libis-format 1.0.2 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +5 -1
  3. data/.travis.yml +43 -25
  4. data/README.md +2 -2
  5. data/base/Dockerfile +35 -0
  6. data/base/Dockerfile.alpine +20 -0
  7. data/base/Dockerfile.rvm +56 -0
  8. data/base/rework_path +20 -0
  9. data/bin/libis_format +8 -0
  10. data/docker_cfg.yml +1 -0
  11. data/lib/libis/format.rb +12 -2
  12. data/lib/libis/format/cli/convert.rb +310 -0
  13. data/lib/libis/format/cli/format.rb +77 -0
  14. data/lib/libis/format/cli/prompt_helper.rb +87 -0
  15. data/lib/libis/format/cli/sub_command.rb +22 -0
  16. data/lib/libis/format/command_line.rb +25 -0
  17. data/lib/libis/format/config.rb +15 -10
  18. data/lib/libis/format/converter/audio_converter.rb +3 -37
  19. data/lib/libis/format/converter/base.rb +22 -8
  20. data/lib/libis/format/converter/chain.rb +3 -3
  21. data/lib/libis/format/converter/image_assembler.rb +82 -0
  22. data/lib/libis/format/converter/image_converter.rb +32 -127
  23. data/lib/libis/format/converter/image_splitter.rb +84 -0
  24. data/lib/libis/format/converter/image_watermarker.rb +261 -0
  25. data/lib/libis/format/converter/jp2_converter.rb +2 -2
  26. data/lib/libis/format/converter/office_converter.rb +2 -2
  27. data/lib/libis/format/converter/pdf_assembler.rb +66 -0
  28. data/lib/libis/format/converter/pdf_converter.rb +10 -134
  29. data/lib/libis/format/converter/pdf_metadata.rb +82 -0
  30. data/lib/libis/format/converter/pdf_optimizer.rb +67 -0
  31. data/lib/libis/format/converter/pdf_protecter.rb +147 -0
  32. data/lib/libis/format/converter/pdf_selecter.rb +77 -0
  33. data/lib/libis/format/converter/pdf_splitter.rb +70 -0
  34. data/lib/libis/format/converter/pdf_watermarker_header.rb +71 -0
  35. data/lib/libis/format/converter/pdf_watermarker_image.rb +76 -0
  36. data/lib/libis/format/converter/pdf_watermarker_text.rb +93 -0
  37. data/lib/libis/format/converter/spreadsheet_converter.rb +2 -2
  38. data/lib/libis/format/converter/video_converter.rb +1 -1
  39. data/lib/libis/format/identifier.rb +7 -7
  40. data/lib/libis/format/info.rb +27 -0
  41. data/lib/libis/format/library.rb +147 -0
  42. data/lib/libis/format/tool.rb +4 -1
  43. data/lib/libis/format/tool/droid.rb +2 -2
  44. data/lib/libis/format/tool/extension_identification.rb +4 -4
  45. data/lib/libis/format/tool/ffmpeg.rb +1 -1
  46. data/lib/libis/format/tool/fido.rb +1 -1
  47. data/lib/libis/format/tool/fop_pdf.rb +1 -1
  48. data/lib/libis/format/tool/identification_tool.rb +6 -6
  49. data/lib/libis/format/tool/office_to_pdf.rb +1 -1
  50. data/lib/libis/format/tool/pdf_merge.rb +4 -4
  51. data/lib/libis/format/tool/{pdf_copy.rb → pdf_metadata.rb} +6 -6
  52. data/lib/libis/format/tool/pdf_protect.rb +47 -0
  53. data/lib/libis/format/tool/pdf_select.rb +47 -0
  54. data/lib/libis/format/tool/pdf_split.rb +5 -5
  55. data/lib/libis/format/tool/pdf_to_pdfa.rb +1 -2
  56. data/lib/libis/format/tool/pdf_watermark.rb +47 -0
  57. data/lib/libis/format/tool/pdfa_validator.rb +3 -4
  58. data/lib/libis/format/tool/spreadsheet_to_ods.rb +2 -1
  59. data/lib/libis/format/version.rb +1 -1
  60. data/lib/libis/format/yaml_loader.rb +71 -0
  61. data/libis-format.gemspec +5 -5
  62. data/tools/PdfTool.jar +0 -0
  63. data/tools/bcpkix-jdk15on-167.jar +0 -0
  64. data/tools/bcprov-jdk15on-167.jar +0 -0
  65. data/tools/fop/build/fop.jar +0 -0
  66. data/tools/fop/conf/fop.xconf +466 -0
  67. data/tools/fop/fop +258 -0
  68. data/tools/fop/fop.bat +75 -0
  69. data/tools/fop/fop.cmd +31 -0
  70. data/tools/fop/fop.js +341 -0
  71. data/tools/fop/lib/README.txt +243 -0
  72. data/tools/fop/lib/avalon-framework-api-4.3.1.jar +0 -0
  73. data/tools/fop/lib/avalon-framework-impl-4.3.1.jar +0 -0
  74. data/tools/fop/lib/avalon-framework.LICENSE.txt +175 -0
  75. data/tools/fop/lib/avalon-framework.NOTICE.TXT +11 -0
  76. data/tools/fop/lib/batik-all-1.10.jar +0 -0
  77. data/tools/fop/lib/batik.LICENSE.txt +201 -0
  78. data/tools/fop/lib/batik.NOTICE.txt +18 -0
  79. data/tools/fop/lib/commons-io-1.3.1.jar +0 -0
  80. data/tools/fop/lib/commons-io.LICENSE.txt +203 -0
  81. data/tools/fop/lib/commons-io.NOTICE.txt +6 -0
  82. data/tools/fop/lib/commons-logging-1.0.4.jar +0 -0
  83. data/tools/fop/lib/commons-logging.LICENSE.txt +202 -0
  84. data/tools/fop/lib/commons-logging.NOTICE.txt +3 -0
  85. data/tools/fop/lib/fontbox-2.0.7.jar +0 -0
  86. data/tools/fop/lib/serializer-2.7.2.jar +0 -0
  87. data/tools/fop/lib/serializer.LICENSE.txt +201 -0
  88. data/tools/fop/lib/serializer.NOTICE.txt +15 -0
  89. data/tools/fop/lib/xalan-2.7.2.jar +0 -0
  90. data/tools/fop/lib/xalan.BCEL.LICENSE.txt +52 -0
  91. data/tools/fop/lib/xalan.LICENSE.txt +202 -0
  92. data/tools/fop/lib/xalan.NOTICE.txt +44 -0
  93. data/tools/fop/lib/xalan.regexp.LICENSE.txt +52 -0
  94. data/tools/fop/lib/xalan.runtime.LICENSE.txt +20 -0
  95. data/tools/fop/lib/xerces.LICENSE.txt +56 -0
  96. data/tools/fop/lib/xercesImpl-2.9.1.jar +0 -0
  97. data/tools/fop/lib/xercesImpl.LICENSE.txt +201 -0
  98. data/tools/fop/lib/xercesImpl.NOTICE.txt +14 -0
  99. data/tools/fop/lib/xml-apis-1.3.04.jar +0 -0
  100. data/tools/fop/lib/xml-apis-ext-1.3.04.jar +0 -0
  101. data/tools/fop/lib/xml-apis-ext.LICENSE.dom-documentation.txt +73 -0
  102. data/tools/fop/lib/xml-apis-ext.LICENSE.dom-software.txt +61 -0
  103. data/tools/fop/lib/xml-apis-ext.LICENSE.sac.html +75 -0
  104. data/tools/fop/lib/xml-apis-ext.LICENSE.txt +202 -0
  105. data/tools/fop/lib/xml-apis-ext.NOTICE.txt +16 -0
  106. data/tools/fop/lib/xml-apis-ext.README.dom.txt +56 -0
  107. data/tools/fop/lib/xml-apis.LICENSE-SAX.html +17 -0
  108. data/tools/fop/lib/xml-apis.LICENSE.DOM-documentation.html +74 -0
  109. data/tools/fop/lib/xml-apis.LICENSE.DOM-software.html +66 -0
  110. data/tools/fop/lib/xml-apis.LICENSE.txt +201 -0
  111. data/tools/fop/lib/xml-apis.NOTICE.txt +13 -0
  112. data/tools/fop/lib/xmlgraphics-commons-2.3.jar +0 -0
  113. data/tools/fop/lib/xmlgraphics-commons.LICENSE.txt +202 -0
  114. data/tools/fop/lib/xmlgraphics-commons.NOTICE.txt +5 -0
  115. data/tools/pdfbox/pdfbox-app-2.0.13.jar +0 -0
  116. data/tools/pdfbox/{pdfbox-app-1.8.10.jar → preflight-app-2.0.13.jar} +0 -0
  117. metadata +93 -259
  118. data/lib/libis/format/type_database.rb +0 -201
  119. data/spec/converter_audio_spec.rb +0 -66
  120. data/spec/converter_fop_spec.rb +0 -37
  121. data/spec/converter_image_spec.rb +0 -166
  122. data/spec/converter_office_spec.rb +0 -84
  123. data/spec/converter_pdf_spec.rb +0 -30
  124. data/spec/converter_repository_spec.rb +0 -97
  125. data/spec/converter_spreadsheet_spec.rb +0 -39
  126. data/spec/converter_video_spec.rb +0 -97
  127. data/spec/converter_xsl_spec.rb +0 -56
  128. data/spec/data/Cevennes2.bmp +0 -0
  129. data/spec/data/Cevennes2.jp2 +0 -0
  130. data/spec/data/Cevennes2.ppm +0 -22492
  131. data/spec/data/NikonRaw-CameraRaw.TIF +0 -0
  132. data/spec/data/NikonRaw-CaptureOne.tif +0 -0
  133. data/spec/data/audio/carlin_disappointed.aac +0 -0
  134. data/spec/data/audio/carlin_disappointed.ac3 +0 -0
  135. data/spec/data/audio/carlin_disappointed.aiff +0 -0
  136. data/spec/data/audio/carlin_disappointed.au +0 -0
  137. data/spec/data/audio/carlin_disappointed.flac +0 -0
  138. data/spec/data/audio/carlin_disappointed.m4a +0 -0
  139. data/spec/data/audio/carlin_disappointed.mka +0 -0
  140. data/spec/data/audio/carlin_disappointed.mp3 +0 -0
  141. data/spec/data/audio/carlin_disappointed.ogg +0 -0
  142. data/spec/data/audio/carlin_disappointed.ra +0 -0
  143. data/spec/data/audio/carlin_disappointed.voc +0 -0
  144. data/spec/data/audio/carlin_disappointed.wav +0 -0
  145. data/spec/data/audio/carlin_disappointed.wma +0 -0
  146. data/spec/data/audio/greensleeves.aac +0 -0
  147. data/spec/data/audio/greensleeves.ac3 +0 -0
  148. data/spec/data/audio/greensleeves.aiff +0 -0
  149. data/spec/data/audio/greensleeves.au +0 -0
  150. data/spec/data/audio/greensleeves.flac +0 -0
  151. data/spec/data/audio/greensleeves.m4a +0 -0
  152. data/spec/data/audio/greensleeves.mka +0 -0
  153. data/spec/data/audio/greensleeves.mp3 +0 -0
  154. data/spec/data/audio/greensleeves.ogg +0 -0
  155. data/spec/data/audio/greensleeves.ra +0 -0
  156. data/spec/data/audio/greensleeves.voc +0 -0
  157. data/spec/data/audio/greensleeves.wav +0 -0
  158. data/spec/data/audio/greensleeves.wma +0 -0
  159. data/spec/data/audio/king_nonviolence.aac +0 -0
  160. data/spec/data/audio/king_nonviolence.ac3 +0 -0
  161. data/spec/data/audio/king_nonviolence.aiff +0 -0
  162. data/spec/data/audio/king_nonviolence.au +0 -0
  163. data/spec/data/audio/king_nonviolence.flac +0 -0
  164. data/spec/data/audio/king_nonviolence.m4a +0 -0
  165. data/spec/data/audio/king_nonviolence.mka +0 -0
  166. data/spec/data/audio/king_nonviolence.mp3 +0 -0
  167. data/spec/data/audio/king_nonviolence.ogg +0 -0
  168. data/spec/data/audio/king_nonviolence.ra +0 -0
  169. data/spec/data/audio/king_nonviolence.voc +0 -0
  170. data/spec/data/audio/king_nonviolence.wav +0 -0
  171. data/spec/data/audio/king_nonviolence.wma +0 -0
  172. data/spec/data/audio/top_gun_secret.aac +0 -0
  173. data/spec/data/audio/top_gun_secret.ac3 +0 -0
  174. data/spec/data/audio/top_gun_secret.aiff +0 -0
  175. data/spec/data/audio/top_gun_secret.au +0 -0
  176. data/spec/data/audio/top_gun_secret.flac +0 -0
  177. data/spec/data/audio/top_gun_secret.m4a +0 -0
  178. data/spec/data/audio/top_gun_secret.mka +0 -0
  179. data/spec/data/audio/top_gun_secret.mp3 +0 -0
  180. data/spec/data/audio/top_gun_secret.ogg +0 -0
  181. data/spec/data/audio/top_gun_secret.ra +0 -0
  182. data/spec/data/audio/top_gun_secret.voc +0 -0
  183. data/spec/data/audio/top_gun_secret.wav +0 -0
  184. data/spec/data/audio/top_gun_secret.wma +0 -0
  185. data/spec/data/multipage.tif +0 -0
  186. data/spec/data/multipage.tif.jp2 +0 -0
  187. data/spec/data/test-ead.xml +0 -392
  188. data/spec/data/test-jpg.tif +0 -0
  189. data/spec/data/test-lzw.tif +0 -0
  190. data/spec/data/test-options.jpg +0 -0
  191. data/spec/data/test-options.png +0 -0
  192. data/spec/data/test.bmp +0 -0
  193. data/spec/data/test.doc +0 -0
  194. data/spec/data/test.docx +0 -0
  195. data/spec/data/test.gif +0 -0
  196. data/spec/data/test.jpg +0 -0
  197. data/spec/data/test.ods +0 -0
  198. data/spec/data/test.odt +0 -0
  199. data/spec/data/test.pdf +0 -0
  200. data/spec/data/test.pdf.tif +0 -0
  201. data/spec/data/test.png +0 -0
  202. data/spec/data/test.ps +0 -8631
  203. data/spec/data/test.psd +0 -0
  204. data/spec/data/test.rtf +0 -1455
  205. data/spec/data/test.tif +0 -0
  206. data/spec/data/test.txt +0 -12
  207. data/spec/data/test.xcf +0 -0
  208. data/spec/data/test.xls +0 -0
  209. data/spec/data/test.xlsx +0 -0
  210. data/spec/data/test.xml +0 -4
  211. data/spec/data/test_pdfa.pdf +0 -0
  212. data/spec/data/video/SampleVideo_1080x720_2mb.flv +0 -0
  213. data/spec/data/video/SampleVideo_1080x720_2mb.mkv +0 -0
  214. data/spec/data/video/SampleVideo_1080x720_2mb.mp4 +0 -0
  215. data/spec/data/video/SampleVideo_176x144_2mb.3gp +0 -0
  216. data/spec/data/video/SampleVideo_320x240_2mb.3gp +0 -0
  217. data/spec/data/video/SampleVideo_360x240_2mb.flv +0 -0
  218. data/spec/data/video/SampleVideo_360x240_2mb.mkv +0 -0
  219. data/spec/data/video/SampleVideo_360x240_2mb.mp4 +0 -0
  220. data/spec/data/video/copyright.png +0 -0
  221. data/spec/data/xml/134476_ead.XML +0 -1
  222. data/spec/data/xml/134476_ead.pdf +0 -0
  223. data/spec/data/xml/134476_fo.XML +0 -383
  224. data/spec/data/xml/134476_raw.XML +0 -141
  225. data/spec/data/xml/ead2fo_pdf.xsl +0 -1453
  226. data/spec/data/xml/header_nolink_pdf.xsl +0 -120
  227. data/spec/data/xml/lookupLists.xsl +0 -488
  228. data/spec/data/xml/scope_eadToHTML.xsl +0 -2376
  229. data/spec/data/xml/scope_xmlToEAD_dom.xsl +0 -952
  230. data/spec/identifier_spec.rb +0 -161
  231. data/spec/spec_helper.rb +0 -58
  232. data/spec/test_types.yml +0 -12
  233. data/spec/type_database_spec.rb +0 -140
  234. data/tools/bcpkix-jdk15on-1.49.jar +0 -0
  235. data/tools/bcprov-jdk15on-1.49.jar +0 -0
  236. data/tools/pdfbox/preflight-app-1.8.10.jar +0 -0
@@ -0,0 +1,77 @@
1
+ require 'awesome_print'
2
+ require 'libis-format'
3
+ require 'libis-tools'
4
+
5
+ require_relative 'sub_command'
6
+
7
+ module Libis
8
+ module Format
9
+ module Cli
10
+ class Format < SubCommand
11
+
12
+ no_commands do
13
+ def self.description(field)
14
+ "#{STRING_CONFIG[field]}." + (DEFAULT_CONFIG[field].nil? ? '' : " default: #{DEFAULT_CONFIG[field]}")
15
+ end
16
+ end
17
+
18
+ DEFAULT_CONFIG = {
19
+ droid: true,
20
+ fido: true,
21
+ file: true,
22
+ xml_validation: true
23
+ }
24
+
25
+ STRING_CONFIG = {
26
+ droid: 'Use Droid to identify the format',
27
+ fido: 'Use Fido to identify the format',
28
+ file: 'Use File to identify the format',
29
+ xml_validation: 'When XML file found, validate the file against known XML schemas',
30
+ }
31
+
32
+ desc 'identify FILE [options]', 'Identify the FILE using a combination of the tools.'
33
+ long_desc <<-DESC
34
+
35
+ 'identify FILE [options]' will idnetify a file using a combination of tools.
36
+
37
+ The file will be identified by each of the selected tools in turn and the format with best score will be
38
+ selected to give the final result. The score is determined by the identification method and will be lowered if
39
+ a known weak format (e.g. zip file) is detected.
40
+
41
+ The tool will display as much information about the format as possible, including the format candidates that
42
+ were not selected.
43
+
44
+ DESC
45
+
46
+ method_option :droid, default: DEFAULT_CONFIG[:droid], type: :boolean, desc: STRING_CONFIG[:droid]
47
+ method_option :fido, default: DEFAULT_CONFIG[:fido], type: :boolean, desc: STRING_CONFIG[:fido]
48
+ method_option :file, default: DEFAULT_CONFIG[:file], type: :boolean, desc: STRING_CONFIG[:file]
49
+ method_option :xml_validation, default: DEFAULT_CONFIG[:xml_validation], type: :boolean, desc: STRING_CONFIG[:xml_validation]
50
+
51
+ def identify(source_file)
52
+ ::Libis::Tools::Config.logger.level = :WARN
53
+ opts = options.inject({}) { |h, x| h[x.first.to_sym] = x.last; h}
54
+ opts[:keep_output] = true
55
+ result = ::Libis::Format::Identifier.get source_file, opts
56
+ puts '--- messages ---'
57
+ result[:messages].each do |message|
58
+ puts "#{message[0]} : #{message[1]}"
59
+ end
60
+
61
+ puts '--- formats ---'
62
+ result[:formats].each do |file, info|
63
+ puts "#{file}:"
64
+ ap info
65
+ end
66
+
67
+ puts '--- tool results ---'
68
+ result[:output].each do |file, info|
69
+ puts "#{file}:"
70
+ ap info
71
+ end
72
+ end
73
+
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,87 @@
1
+ require 'tty-prompt'
2
+ require 'pastel'
3
+
4
+ module Libis
5
+ module Format
6
+ module Cli
7
+ module PromptHelper
8
+
9
+ attr_reader :prompt, :pastel
10
+
11
+ def initialize(*args)
12
+ @prompt = TTY::Prompt.new
13
+ @pastel = Pastel.new
14
+ super
15
+ end
16
+
17
+ protected
18
+
19
+ private
20
+
21
+ def index_of(list, value)
22
+ i = list.index(value)
23
+ i += 1 if i
24
+ i || 1
25
+ end
26
+
27
+ def ask(question, bool: false, enum: nil, default: nil, mask: false)
28
+ cmd, args, opts = :ask, [question], {}
29
+ if enum
30
+ cmd = :select
31
+ args << enum
32
+ # Change default to its index in the enum
33
+ default = index_of(enum, default)
34
+ end
35
+ cmd = :mask if mask
36
+ opts[:default] = default if default
37
+ cmd = (opts[:default] ? :yes? : :no?) if bool
38
+ prompt.send(cmd, *args, opts)
39
+ end
40
+
41
+ def tree_select(path, question: nil, file: false, page_size: 22, filter: true, cycle: false, create: false,
42
+ default_choices: nil)
43
+ path = Pathname.new(path) unless path.is_a? Pathname
44
+
45
+ return path unless path.exist?
46
+ path = path.realpath
47
+
48
+ dirs = path.children.select(&:directory?).sort
49
+ files = file ? path.children.select(&:file?).sort : []
50
+
51
+ choices = []
52
+ choices << {name: "Folder: #{path}", value: path, disabled: file ? '' : false}
53
+ choices += default_choices if default_choices
54
+ choices << {name: '-- new directory --', value: -> do
55
+ new_name = prompt.ask('new directory name:', modify: :trim, required: true)
56
+ new_path = path + new_name
57
+ FileUtils.mkdir(new_path.to_path)
58
+ new_path
59
+ end
60
+ } if create
61
+
62
+ choices << {name: "-- new file --", value: -> do
63
+ new_name = prompt.ask('new file name:', modify: :trim, required: true)
64
+ path + new_name
65
+ end
66
+ } if file && create
67
+
68
+ choices << {name: '[..]', value: path.parent}
69
+
70
+ dirs.each {|d| choices << {name: "[#{d.basename}]", value: d}}
71
+ files.each {|f| choices << {name: f.basename.to_path, value: f}}
72
+
73
+ question ||= "Select #{'file or ' if files}directory"
74
+ selection = prompt.select question, choices,
75
+ per_page: page_size, filter: filter, cycle: cycle, default: file ? 2 : 1
76
+
77
+ return selection unless selection.is_a? Pathname
78
+ return selection.to_path if selection == path || selection.file?
79
+
80
+ tree_select selection, question: question, file: file, page_size: page_size, filter: filter,
81
+ cycle: cycle, create: create, default_choices: default_choices
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,22 @@
1
+ require 'thor'
2
+ require_relative 'prompt_helper'
3
+
4
+ module Libis
5
+ module Format
6
+ module Cli
7
+ class SubCommand < Thor
8
+
9
+ include PromptHelper
10
+
11
+ def self.banner(command, namespace = nil, subcommand = false)
12
+ "#{basename} #{subcommand_prefix} #{command.usage}"
13
+ end
14
+
15
+ def self.subcommand_prefix
16
+ self.name.gsub(%r{.*::}, '').gsub(%r{^[A-Z]}) { |match| match[0].downcase }.gsub(%r{[A-Z]}) { |match| "-#{match[0].downcase}" }
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'thor'
2
+ require 'tty-prompt'
3
+ require 'tty-config'
4
+
5
+ require 'libis/format/cli/convert'
6
+ require 'libis/format/cli/format'
7
+
8
+ module Libis
9
+ module Format
10
+
11
+ class CommandLine < Thor
12
+
13
+ def self.exit_on_failure?
14
+ true
15
+ end
16
+
17
+ desc 'convert', 'perform format conversion on a given file'
18
+ subcommand 'convert', Cli::Convert
19
+
20
+ desc 'format', 'perform format identification on a given file or directory'
21
+ subcommand 'format', Cli::Format
22
+ end
23
+
24
+ end
25
+ end
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require 'os'
3
+ require 'libis-tools'
3
4
 
4
5
  module Libis
5
6
  module Format
@@ -9,20 +10,23 @@ module Libis
9
10
 
10
11
  Config[:converter_chain_max_level] = 8
11
12
 
12
- Config[:java_path] = 'java'
13
- Config[:j2kdriver] = 'j2kdriver'
14
- Config[:soffice_path] = 'soffice'
15
- Config[:ghostscript_path] = 'gs'
16
- Config[:droid_path] = '/opt/droid/droid.sh'
17
- Config[:fido_path] = '/usr/local/bin/fido'
18
- Config[:fop_jar] = '/opt/fop/current/fop/build/fop.jar'
19
- Config[:ffmpeg_path] = 'ffmpeg'
13
+ Config[:java_cmd] = 'java'
14
+ Config[:j2k_cmd] = 'j2kdriver'
15
+ Config[:soffice_cmd] = 'soffice'
16
+ Config[:ghostscript_cmd] = 'gs'
17
+ Config[:droid_cmd] = '/opt/droid/droid.sh'
18
+ Config[:droid_temp_path] = '/tmp'
19
+ Config[:fido_cmd] = '/usr/local/bin/fido'
20
+ Config[:fop_jar] = File.join(Libis::Format::TOOL_DIR, 'fop', 'build', 'fop.jar')
21
+ Config[:ffmpeg_cmd] = 'ffmpeg'
20
22
  Config[:fido_formats] = [(File.join(Libis::Format::DATA_DIR, 'lias_formats.xml'))]
21
23
  Config[:pdf_tool] = File.join(Libis::Format::TOOL_DIR, 'PdfTool.jar')
24
+ Config[:preflight_jar] = File.join(Libis::Format::TOOL_DIR, 'pdfbox', 'preflight-app-2.0.13.jar')
22
25
  # noinspection RubyStringKeysInHashInspection
23
26
  Config[:xml_validations] = [['archive/ead', File.join(Libis::Format::DATA_DIR, 'ead.xsd')]]
24
- Config[:type_database] = File.join(Libis::Format::DATA_DIR, 'types.yml')
25
- Config[:raw_audio_convert_cmd] = 'sox %s -e signed -b 16 -t wav %s rate %d channels %d'
27
+ Config[:format_library_implementation] = 'Libis::Format::YamlLoader.instance'
28
+ Config[:format_library_database] = File.join(Libis::Format::DATA_DIR, 'types.yml')
29
+ Config[:raw_audio_convert_cmd] = 'sox -V1 %s -e signed -b 16 -t wav %s rate %d channels %d'
26
30
  Config[:watermark_font] = '/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf'
27
31
  Config[:timeouts] = {
28
32
  droid: 20 * 60,
@@ -32,6 +36,7 @@ module Libis
32
36
  fop: 5 * 60,
33
37
  identification_tool: 5 * 60,
34
38
  office_to_pdf: 5 * 60,
39
+ pdf_select: 5 * 60,
35
40
  pdf_copy: 5 * 60,
36
41
  pdf_merge: 5 * 60,
37
42
  pdf_optimizer: 5 * 60,
@@ -15,7 +15,7 @@ module Libis
15
15
  end
16
16
 
17
17
  def self.output_types(format = nil)
18
- return [] unless input_types.include?(format)
18
+ return [] unless format.nil? || input_types.include?(format)
19
19
  [:MP3, :FLAC, :AC3, :AAC, :WMA, :ALAC, :WAV, :AIFF, :AMR, :AU, :M4A]
20
20
  end
21
21
 
@@ -69,50 +69,16 @@ module Libis
69
69
  (@options[:preset] ||= {})[stream] = name
70
70
  end
71
71
 
72
- # def encoder(value)
73
- # @options[:encoder] = value
74
- # end
75
- #
76
- # def encoder_options(value)
77
- # @options[:encoder_options] = value
78
- # end
79
-
80
72
  def convert(source, target, _format, opts = {})
81
73
  super
82
74
 
83
75
  FileUtils.mkpath(File.dirname(target))
84
76
 
85
- if source.is_a? Array
86
-
87
- assemble_and_convert(source, target)
88
-
89
- elsif File.directory?(source)
90
-
91
- sources = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
92
- assemble_and_convert(sources, target)
77
+ convert_file(source, target)
93
78
 
94
- else
95
-
96
- convert_file(source, target)
97
-
98
- end
99
-
100
- target
101
-
102
- end
103
-
104
- def assemble_and_convert(sources, target)
105
- Tempfile.create(%w(list .txt)) do |f|
106
- sources.each {|src| f.puts src}
107
- opts[:global] ||= []
108
- opts[:global] += %w(-f concat)
109
- f.close
110
- target = convert_file(f.to_path, target)
111
- end
112
- target
113
79
  end
114
80
 
115
- def sounds_like(file1, file2, threshold, rate, channels)
81
+ def self.sounds_like(file1, file2, threshold, rate, channels)
116
82
  rate ||= 96000
117
83
  channels ||= 2
118
84
  threshold ||= 0.85
@@ -4,7 +4,8 @@
4
4
  require 'tmpdir'
5
5
  require 'libis/tools/logger'
6
6
  require 'libis/tools/temp_file'
7
- require 'libis/format/type_database'
7
+ require 'libis/tools/extend/string'
8
+ require 'libis/format/library'
8
9
 
9
10
  require_relative 'repository'
10
11
 
@@ -22,10 +23,23 @@ module Libis
22
23
  @flags = {}
23
24
  end
24
25
 
26
+ def self.category
27
+ :converter
28
+ end
29
+
30
+ def check_file_exist(file)
31
+ unless File.exist? file
32
+ error "Cannot find file '#{file}'."
33
+ return false
34
+ end
35
+ true
36
+ end
37
+
25
38
  def convert(source, target, format, opts = {})
26
- unless File.exist? source
27
- error "Cannot find file '#{source}'."
28
- return nil
39
+ if source.is_a?(Array)
40
+ return nil unless source.map { |f| check_file_exist(f) }.reduce(:&)
41
+ else
42
+ return nil unless check_file_exist(source)
29
43
  end
30
44
  @options.merge!(opts[:options]) if opts[:options]
31
45
  @flags.merge!(opts[:flags]) if opts[:flags]
@@ -51,7 +65,7 @@ module Libis
51
65
  target
52
66
  end
53
67
 
54
- def Base.inherited( klass )
68
+ def Base.inherited(klass)
55
69
 
56
70
  Repository.register klass
57
71
 
@@ -73,12 +87,12 @@ module Libis
73
87
  end
74
88
 
75
89
  def input_mimetype?(mimetype)
76
- type_id = TypeDatabase.instance.mime_types(mimetype).first
90
+ type_id = Libis::Format::Library.get_field_by(:mimetype, mimetype, :format)
77
91
  input_type? type_id
78
92
  end
79
93
 
80
94
  def output_mimetype?(mimetype)
81
- type_id = TypeDatabase.instance.mime_types(mimetype).first
95
+ type_id = Libis::Format::Library.get_field_by(:mimetype, mimetype, :format)
82
96
  output_type? type_id
83
97
  end
84
98
 
@@ -91,7 +105,7 @@ module Libis
91
105
  end
92
106
 
93
107
  def extension?(extension)
94
- !TypeDatabase.ext_types(extension).first.nil?
108
+ !Libis::Format::Library.get_field_by(:extension, extension, :format).nil?
95
109
  end
96
110
 
97
111
  end
@@ -5,7 +5,7 @@ require 'deep_dive'
5
5
 
6
6
  require 'libis/tools/logger'
7
7
  require 'libis/tools/extend/hash'
8
- require 'libis/format/type_database'
8
+ require 'libis/format/library'
9
9
 
10
10
  module Libis
11
11
  module Format
@@ -83,8 +83,8 @@ module Libis
83
83
  target = target_file
84
84
 
85
85
  if i < size - 1
86
- target += ".temp.#{TypeDatabase.type_extentions(target_type).first}"
87
- target += ".#{TypeDatabase.type_extentions(target_type).first}" while File.exist? target
86
+ target += ".temp.#{Libis::Format::Library.get_field(target_type, :extensions).first}"
87
+ target += ".#{Libis::Format::Library.get_field(target_type, :extensions).first}" while File.exist? target
88
88
  temp_files << target
89
89
  end
90
90
 
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+ require 'libis/format/identifier'
5
+
6
+ require 'mini_magick'
7
+
8
+ MiniMagick.logger.level = ::Logger::UNKNOWN
9
+
10
+ MiniMagick.configure do |config|
11
+ # config.cli = :graphicsmagick
12
+ config.validate_on_create = false
13
+ config.validate_on_write = false
14
+ config.whiny = false
15
+ end
16
+
17
+ module Libis
18
+ module Format
19
+ module Converter
20
+
21
+ # noinspection RubyTooManyInstanceVariablesInspection,DuplicatedCode
22
+ class ImageAssembler < Libis::Format::Converter::Base
23
+
24
+ def self.input_types
25
+ [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2]
26
+ end
27
+
28
+ def self.output_types(format = nil)
29
+ return [] unless input_types.include?(format) if format
30
+ [:PDF, :TIFF, :GIF, :PBM, :PGM, :PPM]
31
+ end
32
+
33
+ def self.category
34
+ :assembler
35
+ end
36
+
37
+ def image_assemble(_)
38
+ #force usage of this converter
39
+ end
40
+
41
+ def quiet(v)
42
+ @quiet = !!v
43
+ end
44
+
45
+ def convert(source, target, format, opts = {})
46
+ super
47
+
48
+ FileUtils.mkpath(File.dirname(target))
49
+
50
+ if source.is_a? Array
51
+ assemble(source, target, format)
52
+ elsif File.directory?(source)
53
+ source_list = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
54
+ assemble(source_list, target, format)
55
+ else
56
+ image = MiniMagick::Image.open(source) {|b| b.quiet}
57
+ if image.pages.size > 1
58
+ assemble(image.pages.map {|page| page.path}, target, format)
59
+ else
60
+ assemble([source], target, format)
61
+ end
62
+ end
63
+
64
+ target
65
+
66
+ end
67
+
68
+ private
69
+
70
+ def assemble(sources, target, format)
71
+ MiniMagick::Tool::Convert.new do |b|
72
+ sources.each {|source| b << source}
73
+ convert.format(format)
74
+ b << target
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
82
+ end