libis-format 1.0.4 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) 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/docker_cfg.yml +1 -0
  10. data/lib/libis/format.rb +12 -3
  11. data/lib/libis/format/cli/convert.rb +4 -4
  12. data/lib/libis/format/config.rb +15 -10
  13. data/lib/libis/format/converter/audio_converter.rb +3 -37
  14. data/lib/libis/format/converter/base.rb +22 -8
  15. data/lib/libis/format/converter/chain.rb +3 -3
  16. data/lib/libis/format/converter/image_assembler.rb +82 -0
  17. data/lib/libis/format/converter/image_converter.rb +20 -138
  18. data/lib/libis/format/converter/image_splitter.rb +84 -0
  19. data/lib/libis/format/converter/image_watermarker.rb +261 -0
  20. data/lib/libis/format/converter/jp2_converter.rb +2 -2
  21. data/lib/libis/format/converter/office_converter.rb +2 -2
  22. data/lib/libis/format/converter/pdf_assembler.rb +66 -0
  23. data/lib/libis/format/converter/pdf_converter.rb +10 -134
  24. data/lib/libis/format/converter/pdf_metadata.rb +82 -0
  25. data/lib/libis/format/converter/pdf_optimizer.rb +67 -0
  26. data/lib/libis/format/converter/pdf_protecter.rb +147 -0
  27. data/lib/libis/format/converter/pdf_selecter.rb +83 -0
  28. data/lib/libis/format/converter/pdf_splitter.rb +70 -0
  29. data/lib/libis/format/converter/pdf_watermarker_header.rb +71 -0
  30. data/lib/libis/format/converter/pdf_watermarker_image.rb +76 -0
  31. data/lib/libis/format/converter/pdf_watermarker_text.rb +93 -0
  32. data/lib/libis/format/converter/spreadsheet_converter.rb +2 -2
  33. data/lib/libis/format/converter/video_converter.rb +1 -1
  34. data/lib/libis/format/identifier.rb +3 -3
  35. data/lib/libis/format/info.rb +27 -0
  36. data/lib/libis/format/library.rb +147 -0
  37. data/lib/libis/format/tool.rb +4 -1
  38. data/lib/libis/format/tool/droid.rb +2 -2
  39. data/lib/libis/format/tool/extension_identification.rb +4 -4
  40. data/lib/libis/format/tool/ffmpeg.rb +1 -1
  41. data/lib/libis/format/tool/fido.rb +1 -1
  42. data/lib/libis/format/tool/fop_pdf.rb +1 -1
  43. data/lib/libis/format/tool/identification_tool.rb +6 -6
  44. data/lib/libis/format/tool/office_to_pdf.rb +1 -1
  45. data/lib/libis/format/tool/pdf_merge.rb +4 -4
  46. data/lib/libis/format/tool/{pdf_copy.rb → pdf_metadata.rb} +6 -6
  47. data/lib/libis/format/tool/pdf_protect.rb +47 -0
  48. data/lib/libis/format/tool/pdf_select.rb +47 -0
  49. data/lib/libis/format/tool/pdf_split.rb +5 -5
  50. data/lib/libis/format/tool/pdf_to_pdfa.rb +1 -2
  51. data/lib/libis/format/tool/pdf_watermark.rb +47 -0
  52. data/lib/libis/format/tool/pdfa_validator.rb +3 -4
  53. data/lib/libis/format/tool/spreadsheet_to_ods.rb +2 -1
  54. data/lib/libis/format/version.rb +1 -1
  55. data/lib/libis/format/yaml_loader.rb +71 -0
  56. data/libis-format.gemspec +5 -4
  57. data/tools/PdfTool.jar +0 -0
  58. data/tools/bcpkix-jdk15on-167.jar +0 -0
  59. data/tools/bcprov-jdk15on-167.jar +0 -0
  60. data/tools/fop/build/fop.jar +0 -0
  61. data/tools/fop/conf/fop.xconf +466 -0
  62. data/tools/fop/fop +258 -0
  63. data/tools/fop/fop.bat +75 -0
  64. data/tools/fop/fop.cmd +31 -0
  65. data/tools/fop/fop.js +341 -0
  66. data/tools/fop/lib/README.txt +243 -0
  67. data/tools/fop/lib/avalon-framework-api-4.3.1.jar +0 -0
  68. data/tools/fop/lib/avalon-framework-impl-4.3.1.jar +0 -0
  69. data/tools/fop/lib/avalon-framework.LICENSE.txt +175 -0
  70. data/tools/fop/lib/avalon-framework.NOTICE.TXT +11 -0
  71. data/tools/fop/lib/batik-all-1.10.jar +0 -0
  72. data/tools/fop/lib/batik.LICENSE.txt +201 -0
  73. data/tools/fop/lib/batik.NOTICE.txt +18 -0
  74. data/tools/fop/lib/commons-io-1.3.1.jar +0 -0
  75. data/tools/fop/lib/commons-io.LICENSE.txt +203 -0
  76. data/tools/fop/lib/commons-io.NOTICE.txt +6 -0
  77. data/tools/fop/lib/commons-logging-1.0.4.jar +0 -0
  78. data/tools/fop/lib/commons-logging.LICENSE.txt +202 -0
  79. data/tools/fop/lib/commons-logging.NOTICE.txt +3 -0
  80. data/tools/fop/lib/fontbox-2.0.7.jar +0 -0
  81. data/tools/fop/lib/serializer-2.7.2.jar +0 -0
  82. data/tools/fop/lib/serializer.LICENSE.txt +201 -0
  83. data/tools/fop/lib/serializer.NOTICE.txt +15 -0
  84. data/tools/fop/lib/xalan-2.7.2.jar +0 -0
  85. data/tools/fop/lib/xalan.BCEL.LICENSE.txt +52 -0
  86. data/tools/fop/lib/xalan.LICENSE.txt +202 -0
  87. data/tools/fop/lib/xalan.NOTICE.txt +44 -0
  88. data/tools/fop/lib/xalan.regexp.LICENSE.txt +52 -0
  89. data/tools/fop/lib/xalan.runtime.LICENSE.txt +20 -0
  90. data/tools/fop/lib/xerces.LICENSE.txt +56 -0
  91. data/tools/fop/lib/xercesImpl-2.9.1.jar +0 -0
  92. data/tools/fop/lib/xercesImpl.LICENSE.txt +201 -0
  93. data/tools/fop/lib/xercesImpl.NOTICE.txt +14 -0
  94. data/tools/fop/lib/xml-apis-1.3.04.jar +0 -0
  95. data/tools/fop/lib/xml-apis-ext-1.3.04.jar +0 -0
  96. data/tools/fop/lib/xml-apis-ext.LICENSE.dom-documentation.txt +73 -0
  97. data/tools/fop/lib/xml-apis-ext.LICENSE.dom-software.txt +61 -0
  98. data/tools/fop/lib/xml-apis-ext.LICENSE.sac.html +75 -0
  99. data/tools/fop/lib/xml-apis-ext.LICENSE.txt +202 -0
  100. data/tools/fop/lib/xml-apis-ext.NOTICE.txt +16 -0
  101. data/tools/fop/lib/xml-apis-ext.README.dom.txt +56 -0
  102. data/tools/fop/lib/xml-apis.LICENSE-SAX.html +17 -0
  103. data/tools/fop/lib/xml-apis.LICENSE.DOM-documentation.html +74 -0
  104. data/tools/fop/lib/xml-apis.LICENSE.DOM-software.html +66 -0
  105. data/tools/fop/lib/xml-apis.LICENSE.txt +201 -0
  106. data/tools/fop/lib/xml-apis.NOTICE.txt +13 -0
  107. data/tools/fop/lib/xmlgraphics-commons-2.3.jar +0 -0
  108. data/tools/fop/lib/xmlgraphics-commons.LICENSE.txt +202 -0
  109. data/tools/fop/lib/xmlgraphics-commons.NOTICE.txt +5 -0
  110. data/tools/pdfbox/pdfbox-app-2.0.13.jar +0 -0
  111. data/tools/pdfbox/{pdfbox-app-1.8.10.jar → preflight-app-2.0.13.jar} +0 -0
  112. metadata +86 -246
  113. data/lib/libis/format/type_database.rb +0 -134
  114. data/lib/libis/format/type_database_impl.rb +0 -120
  115. data/spec/converter_audio_spec.rb +0 -66
  116. data/spec/converter_fop_spec.rb +0 -37
  117. data/spec/converter_image_spec.rb +0 -166
  118. data/spec/converter_office_spec.rb +0 -84
  119. data/spec/converter_pdf_spec.rb +0 -30
  120. data/spec/converter_repository_spec.rb +0 -97
  121. data/spec/converter_spreadsheet_spec.rb +0 -39
  122. data/spec/converter_video_spec.rb +0 -97
  123. data/spec/converter_xsl_spec.rb +0 -56
  124. data/spec/data/Cevennes2.bmp +0 -0
  125. data/spec/data/Cevennes2.jp2 +0 -0
  126. data/spec/data/Cevennes2.ppm +0 -22492
  127. data/spec/data/NikonRaw-CameraRaw.TIF +0 -0
  128. data/spec/data/NikonRaw-CaptureOne.tif +0 -0
  129. data/spec/data/audio/carlin_disappointed.aac +0 -0
  130. data/spec/data/audio/carlin_disappointed.ac3 +0 -0
  131. data/spec/data/audio/carlin_disappointed.aiff +0 -0
  132. data/spec/data/audio/carlin_disappointed.au +0 -0
  133. data/spec/data/audio/carlin_disappointed.flac +0 -0
  134. data/spec/data/audio/carlin_disappointed.m4a +0 -0
  135. data/spec/data/audio/carlin_disappointed.mka +0 -0
  136. data/spec/data/audio/carlin_disappointed.mp3 +0 -0
  137. data/spec/data/audio/carlin_disappointed.ogg +0 -0
  138. data/spec/data/audio/carlin_disappointed.ra +0 -0
  139. data/spec/data/audio/carlin_disappointed.voc +0 -0
  140. data/spec/data/audio/carlin_disappointed.wav +0 -0
  141. data/spec/data/audio/carlin_disappointed.wma +0 -0
  142. data/spec/data/audio/greensleeves.aac +0 -0
  143. data/spec/data/audio/greensleeves.ac3 +0 -0
  144. data/spec/data/audio/greensleeves.aiff +0 -0
  145. data/spec/data/audio/greensleeves.au +0 -0
  146. data/spec/data/audio/greensleeves.flac +0 -0
  147. data/spec/data/audio/greensleeves.m4a +0 -0
  148. data/spec/data/audio/greensleeves.mka +0 -0
  149. data/spec/data/audio/greensleeves.mp3 +0 -0
  150. data/spec/data/audio/greensleeves.ogg +0 -0
  151. data/spec/data/audio/greensleeves.ra +0 -0
  152. data/spec/data/audio/greensleeves.voc +0 -0
  153. data/spec/data/audio/greensleeves.wav +0 -0
  154. data/spec/data/audio/greensleeves.wma +0 -0
  155. data/spec/data/audio/king_nonviolence.aac +0 -0
  156. data/spec/data/audio/king_nonviolence.ac3 +0 -0
  157. data/spec/data/audio/king_nonviolence.aiff +0 -0
  158. data/spec/data/audio/king_nonviolence.au +0 -0
  159. data/spec/data/audio/king_nonviolence.flac +0 -0
  160. data/spec/data/audio/king_nonviolence.m4a +0 -0
  161. data/spec/data/audio/king_nonviolence.mka +0 -0
  162. data/spec/data/audio/king_nonviolence.mp3 +0 -0
  163. data/spec/data/audio/king_nonviolence.ogg +0 -0
  164. data/spec/data/audio/king_nonviolence.ra +0 -0
  165. data/spec/data/audio/king_nonviolence.voc +0 -0
  166. data/spec/data/audio/king_nonviolence.wav +0 -0
  167. data/spec/data/audio/king_nonviolence.wma +0 -0
  168. data/spec/data/audio/top_gun_secret.aac +0 -0
  169. data/spec/data/audio/top_gun_secret.ac3 +0 -0
  170. data/spec/data/audio/top_gun_secret.aiff +0 -0
  171. data/spec/data/audio/top_gun_secret.au +0 -0
  172. data/spec/data/audio/top_gun_secret.flac +0 -0
  173. data/spec/data/audio/top_gun_secret.m4a +0 -0
  174. data/spec/data/audio/top_gun_secret.mka +0 -0
  175. data/spec/data/audio/top_gun_secret.mp3 +0 -0
  176. data/spec/data/audio/top_gun_secret.ogg +0 -0
  177. data/spec/data/audio/top_gun_secret.ra +0 -0
  178. data/spec/data/audio/top_gun_secret.voc +0 -0
  179. data/spec/data/audio/top_gun_secret.wav +0 -0
  180. data/spec/data/audio/top_gun_secret.wma +0 -0
  181. data/spec/data/multipage.tif +0 -0
  182. data/spec/data/multipage.tif.jp2 +0 -0
  183. data/spec/data/test-ead.xml +0 -392
  184. data/spec/data/test-jpg.tif +0 -0
  185. data/spec/data/test-lzw.tif +0 -0
  186. data/spec/data/test-options.jpg +0 -0
  187. data/spec/data/test-options.png +0 -0
  188. data/spec/data/test.bmp +0 -0
  189. data/spec/data/test.doc +0 -0
  190. data/spec/data/test.docx +0 -0
  191. data/spec/data/test.gif +0 -0
  192. data/spec/data/test.jpg +0 -0
  193. data/spec/data/test.ods +0 -0
  194. data/spec/data/test.odt +0 -0
  195. data/spec/data/test.pdf +0 -0
  196. data/spec/data/test.pdf.tif +0 -0
  197. data/spec/data/test.png +0 -0
  198. data/spec/data/test.ps +0 -8631
  199. data/spec/data/test.psd +0 -0
  200. data/spec/data/test.rtf +0 -1455
  201. data/spec/data/test.tif +0 -0
  202. data/spec/data/test.txt +0 -12
  203. data/spec/data/test.xcf +0 -0
  204. data/spec/data/test.xls +0 -0
  205. data/spec/data/test.xlsx +0 -0
  206. data/spec/data/test.xml +0 -4
  207. data/spec/data/test_pdfa.pdf +0 -0
  208. data/spec/data/video/SampleVideo_1080x720_2mb.flv +0 -0
  209. data/spec/data/video/SampleVideo_1080x720_2mb.mkv +0 -0
  210. data/spec/data/video/SampleVideo_1080x720_2mb.mp4 +0 -0
  211. data/spec/data/video/SampleVideo_176x144_2mb.3gp +0 -0
  212. data/spec/data/video/SampleVideo_320x240_2mb.3gp +0 -0
  213. data/spec/data/video/SampleVideo_360x240_2mb.flv +0 -0
  214. data/spec/data/video/SampleVideo_360x240_2mb.mkv +0 -0
  215. data/spec/data/video/SampleVideo_360x240_2mb.mp4 +0 -0
  216. data/spec/data/video/copyright.png +0 -0
  217. data/spec/data/xml/134476_ead.XML +0 -1
  218. data/spec/data/xml/134476_ead.pdf +0 -0
  219. data/spec/data/xml/134476_fo.XML +0 -383
  220. data/spec/data/xml/134476_raw.XML +0 -141
  221. data/spec/data/xml/ead2fo_pdf.xsl +0 -1453
  222. data/spec/data/xml/header_nolink_pdf.xsl +0 -120
  223. data/spec/data/xml/lookupLists.xsl +0 -488
  224. data/spec/data/xml/scope_eadToHTML.xsl +0 -2376
  225. data/spec/data/xml/scope_xmlToEAD_dom.xsl +0 -952
  226. data/spec/identifier_spec.rb +0 -161
  227. data/spec/spec_helper.rb +0 -58
  228. data/spec/test_types.yml +0 -12
  229. data/spec/type_database_spec.rb +0 -140
  230. data/tools/bcpkix-jdk15on-1.49.jar +0 -0
  231. data/tools/bcprov-jdk15on-1.49.jar +0 -0
  232. data/tools/pdfbox/preflight-app-1.8.10.jar +0 -0
@@ -0,0 +1,27 @@
1
+ module Libis
2
+ module Format
3
+ class Info
4
+ attr_reader :name, :category, :description, :puids, :mimetypes, :extensions
5
+
6
+ def initialize(name:, category:, description: '', puids: [], mimetypes: [], extensions: [])
7
+ @name = name
8
+ @category = category
9
+ @description = description
10
+ @puids = puids
11
+ @mimetypes = mimetypes
12
+ @extensions = extensions
13
+ end
14
+
15
+ def to_hash
16
+ {
17
+ name: name,
18
+ description: description.dup,
19
+ category: category,
20
+ puids: puids.dup,
21
+ mimetypes: mimetypes.dup,
22
+ extensions: extensions.dup
23
+ }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,147 @@
1
+ # froze_string_litteral: true
2
+ # coding: utf-8
3
+ require 'singleton'
4
+
5
+ module Libis
6
+ module Format
7
+
8
+ class Library
9
+ include Singleton
10
+
11
+ class << self
12
+ def implementation=(impl)
13
+ instance.implementation = impl
14
+ end
15
+
16
+ def get_info(format)
17
+ instance.get_info(format)
18
+ end
19
+
20
+ def get_info_by(key, value)
21
+ instance.get_info_by(key, value)
22
+ end
23
+
24
+ def get_infos_by(key, value)
25
+ instance.get_infos_by(key, value)
26
+ end
27
+
28
+ def get_field(format, field)
29
+ instance.get_field(format, field)
30
+ end
31
+
32
+ def get_field_by(key, value, field)
33
+ instance.get_field_by(key, value, field)
34
+ end
35
+
36
+ def get_fields_by(key, value, field)
37
+ instance.get_fields_by(key, value, field)
38
+ end
39
+
40
+ def known?(key, value)
41
+ instance.known?(key, value)
42
+ end
43
+
44
+ def enrich(info, map_keys = {})
45
+ instance.enrich(info, map_keys)
46
+ end
47
+
48
+ def normalize(info, map_keys = {})
49
+ instance.normalize(info, map_keys)
50
+ end
51
+ end
52
+
53
+ def implementation=(impl)
54
+ @implementation = impl
55
+ end
56
+
57
+ def get_field(format, field)
58
+ get_field_by(:name, format, field)
59
+ end
60
+
61
+ def get_field_by(key, value, field)
62
+ info = get_info_by(key, value)
63
+ return nil unless info
64
+ case field
65
+ when :mimetype
66
+ info[:mimetypes]&.first
67
+ when :puid
68
+ info[:puids]&.first
69
+ when :extension
70
+ info[:extensions]&.first
71
+ else
72
+ info[field]
73
+ end
74
+ end
75
+
76
+ def get_fields_by(key, value, field)
77
+ get_infos_by(key, value)&.map { |info| info[field] }.compact
78
+ end
79
+
80
+ def get_info(format)
81
+ get_info_by(:name, format)
82
+ end
83
+
84
+ def get_info_by(key, value)
85
+ get_infos_by(key, value)&.first
86
+ end
87
+
88
+ def get_infos_by(key, value)
89
+ result = @implementation.query(key, value)
90
+ result.map(&:to_hash)
91
+ end
92
+
93
+ def known?(key, value)
94
+ !get_info_by(key, value).nil?
95
+ end
96
+
97
+ def enrich(info, map_keys = {})
98
+ info = normalize(info, map_keys)
99
+ mapper = Hash.new { |hash, key| hash[key] = key }.merge(map_keys)
100
+ unless (format = info[mapper[:name]]).nil?
101
+ lib_info = get_info(format)
102
+ mapper.keys.each do |key|
103
+ case key
104
+ when :mimetype
105
+ info[mapper[key]] = lib_info[:mimetypes].first if lib_info[:mimetypes].first
106
+ when :puid
107
+ info[mapper[key]] = lib_info[:puids].first if lib_info[:puids].first
108
+ when :extension
109
+ info[mapper[key]] = lib_info[:extensions].first if lib_info[:extensions].first
110
+ else
111
+ info[mapper[key]] = lib_info[key] if lib_info[key]
112
+ end
113
+ end
114
+ end
115
+ info
116
+ end
117
+
118
+ # Derive name from the available info
119
+ def normalize(info, map_keys = {})
120
+ return {} unless info.is_a? Hash
121
+ mapper = Hash.new { |hash, key| hash[key] = key }.merge(map_keys)
122
+ # fill format from looking up by puid
123
+ unless (puid = info[mapper[:puid]]).blank?
124
+ info[mapper[:name]] ||= get_field_by(:puid, puid, :name)
125
+ end
126
+ # fill format from looking up by mimetype
127
+ unless (mime = info[mapper[:mimetype]]).blank?
128
+ info[mapper[:name]] ||= get_field_by(:mimetype, mime, :name)
129
+ end
130
+ # finally complete the information from looking up by format name
131
+ unless (format = info[mapper[:name]]).nil?
132
+ info[mapper[:mimetype]] = get_field(format, :mimetype)
133
+ info[mapper[:category]] = get_field(format, :category)
134
+ end
135
+ info
136
+ end
137
+
138
+ private
139
+
140
+ def initialize
141
+ @implementation = eval(Libis::Format::Config[:format_library_implementation])
142
+ end
143
+
144
+ end
145
+
146
+ end
147
+ end
@@ -12,10 +12,13 @@ module Libis
12
12
  autoload :OfficeToPdf, 'libis/format/tool/office_to_pdf'
13
13
  autoload :FFMpeg, 'libis/format/tool/ffmpeg'
14
14
  autoload :FopPdf, 'libis/format/tool/fop_pdf'
15
- autoload :PdfCopy, 'libis/format/tool/pdf_copy'
16
15
  autoload :PdfMerge, 'libis/format/tool/pdf_merge'
16
+ autoload :PdfMetadata, 'libis/format/tool/pdf_metadata'
17
17
  autoload :PdfOptimizer, 'libis/format/tool/pdf_optimizer'
18
+ autoload :PdfProtect, 'libis/format/tool/pdf_protect'
19
+ autoload :PdfSelect, 'libis/format/tool/pdf_select'
18
20
  autoload :PdfSplit, 'libis/format/tool/pdf_split'
21
+ autoload :PdfWatermark, 'libis/format/tool/pdf_watermark'
19
22
  autoload :PdfToPdfa, 'libis/format/tool/pdf_to_pdfa'
20
23
  autoload :PdfaValidator, 'libis/format/tool/pdfa_validator'
21
24
 
@@ -76,7 +76,7 @@ module Libis
76
76
  ]
77
77
  timeout = Libis::Format::Config[:timeouts][:droid]
78
78
  result = Libis::Tools::Command.run(
79
- Libis::Format::Config[:droid_path], *args,
79
+ Libis::Format::Config[:droid_cmd], *args,
80
80
  timeout: timeout,
81
81
  kill_after: timeout * 2
82
82
  )
@@ -96,7 +96,7 @@ module Libis
96
96
  args << '-R' if recursive
97
97
  timeout = Libis::Format::Config[:timeouts][:droid]
98
98
  result = Libis::Tools::Command.run(
99
- Libis::Format::Config[:droid_path], *args,
99
+ Libis::Format::Config[:droid_cmd], *args,
100
100
  timeout: timeout,
101
101
  kill_after: timeout * 2
102
102
  )
@@ -37,14 +37,14 @@ module Libis
37
37
  def runner(*args)
38
38
 
39
39
  args.map do |file|
40
- info = ::Libis::Format::TypeDatabase.ext_infos(File.extname(file)).first
40
+ info = ::Libis::Format::Library.get_info_by(:extension, File.extname(file))
41
41
  if info
42
42
  {
43
43
  filepath: file,
44
- mimetype: (info[:MIME].first rescue nil),
45
- puid: (info[:PUID].first rescue nil),
44
+ mimetype: (info[:mimetypes].first rescue nil),
45
+ puid: (info[:puids].first rescue nil),
46
46
  matchtype: 'extension',
47
- tool: :type_database
47
+ tool: :format_library
48
48
  }
49
49
  end
50
50
  end.cleanup
@@ -28,7 +28,7 @@ module Libis
28
28
 
29
29
  timeout = Libis::Format::Config[:timeouts][:ffmpeg]
30
30
  result = Libis::Tools::Command.run(
31
- Libis::Format::Config[:ffmpeg_path], *opts,
31
+ Libis::Format::Config[:ffmpeg_cmd], *opts,
32
32
  timeout: timeout,
33
33
  kill_after: timeout * 2
34
34
  )
@@ -76,7 +76,7 @@ module Libis
76
76
  # Run command and capture results
77
77
  timeout = Libis::Format::Config[:timeouts][:fido]
78
78
  result = ::Libis::Tools::Command.run(
79
- Libis::Format::Config[:fido_path], *args,
79
+ Libis::Format::Config[:fido_cmd], *args,
80
80
  timeout: timeout,
81
81
  kill_after: timeout * 2
82
82
  )
@@ -25,7 +25,7 @@ module Libis
25
25
 
26
26
  timeout = Libis::Format::Config[:timeouts][:fop]
27
27
  result = Libis::Tools::Command.run(
28
- Libis::Format::Config[:java_path],
28
+ Libis::Format::Config[:java_cmd],
29
29
  "-Dfop.home=#{File.dirname(Libis::Format::Config[:fop_jar])}",
30
30
  '-jar', Libis::Format::Config[:fop_jar],
31
31
  '-fo', xml,
@@ -7,7 +7,7 @@ require 'libis/tools/logger'
7
7
  require 'libis/tools/command'
8
8
 
9
9
  require 'libis/format/config'
10
- require 'libis/format/type_database'
10
+ require 'libis/format/library'
11
11
 
12
12
  module Libis
13
13
  module Format
@@ -99,7 +99,7 @@ module Libis
99
99
  end
100
100
 
101
101
  # Normalize the mimetype
102
- Libis::Format::TypeDatabase.normalize(result, PUID: :puid, MIME: :mimetype)
102
+ Libis::Format::Library.normalize(result)
103
103
 
104
104
  # Default score is 5
105
105
  result[:score] = 5
@@ -117,14 +117,14 @@ module Libis
117
117
  # Signature match increases score with 2
118
118
  when 'signature'
119
119
  result[:score] += 2
120
- # typeinfo = ::Libis::Format::TypeDatabase.puid_typeinfo(result[:puid])
120
+ # typeinfo = ::Libis::Format::Library.get_info_by(:puid, result[:puid])
121
121
  # ext = File.extname(result[:filename])
122
122
  # result[:score] += 1 if typeinfo and typeinfo[:EXTENSIONS].include?(ext)
123
123
 
124
124
  # Container match increases score with 4
125
125
  when 'container'
126
126
  result[:score] += 4
127
- # typeinfo = ::Libis::Format::TypeDatabase.puid_typeinfo(result[:puid])
127
+ # typeinfo = ::Libis::Format::Library.get_info_by(:puid, result[:puid])
128
128
  # ext = File.extname(result[:filename])
129
129
  # result[:score] += 1 if typeinfo and typeinfo[:EXTENSIONS].include?(ext)
130
130
 
@@ -152,11 +152,11 @@ module Libis
152
152
  end
153
153
 
154
154
  def get_mimetype(puid)
155
- ::Libis::Format::TypeDatabase.puid_typeinfo(puid)[:MIME].first rescue nil
155
+ ::Libis::Format::Library.get_field_by(:puid, puid, :mimetype) rescue nil
156
156
  end
157
157
 
158
158
  def get_puid(mimetype)
159
- ::Libis::Format::TypeDatabase.mime_infos(mimetype).first[:PUID].first rescue nil
159
+ ::Libis::Format::Library.get_field_by(:mimetype, mimetype, :puid) rescue nil
160
160
  end
161
161
 
162
162
  attr_accessor :bad_mimetypes, :bad_puids
@@ -33,7 +33,7 @@ module Libis
33
33
 
34
34
  timeout = Libis::Format::Config[:timeouts][:office_to_pdf]
35
35
  result = Libis::Tools::Command.run(
36
- Libis::Format::Config[:soffice_path], '--headless',
36
+ Libis::Format::Config[:soffice_cmd], '--headless',
37
37
  "-env:UserInstallation=file://#{workdir}",
38
38
  '--convert-to', export_filter,
39
39
  '--outdir', workdir, src_file,
@@ -26,10 +26,10 @@ module Libis
26
26
 
27
27
  timeout = Libis::Format::Config[:timeouts][:pdf_merge]
28
28
  result = Libis::Tools::Command.run(
29
- Libis::Format::Config[:java_path],
30
- '-cp', Libis::Format::Config[:pdf_tool],
31
- 'MergePdf',
32
- '--file_output', target,
29
+ Libis::Format::Config[:java_cmd],
30
+ '-jar', Libis::Format::Config[:pdf_tool],
31
+ 'merge',
32
+ '-o', target,
33
33
  *options,
34
34
  *source,
35
35
  timeout: timeout,
@@ -10,7 +10,7 @@ module Libis
10
10
  module Format
11
11
  module Tool
12
12
 
13
- class PdfCopy
13
+ class PdfMetadata
14
14
  include ::Libis::Tools::Logger
15
15
 
16
16
  def self.run(source, target, options = [])
@@ -25,11 +25,11 @@ module Libis
25
25
 
26
26
  timeout = Libis::Format::Config[:timeouts][:pdf_copy]
27
27
  result = Libis::Tools::Command.run(
28
- Libis::Format::Config[:java_path],
29
- '-cp', Libis::Format::Config[:pdf_tool],
30
- 'CopyPdf',
31
- '--file_input', source,
32
- '--file_output', target,
28
+ Libis::Format::Config[:java_cmd],
29
+ '-jar', Libis::Format::Config[:pdf_tool],
30
+ 'metadata',
31
+ '-i', source,
32
+ '-o', target,
33
33
  *options,
34
34
  timeout: timeout,
35
35
  kill_after: timeout * 2
@@ -0,0 +1,47 @@
1
+ require 'os'
2
+
3
+ require 'libis/tools/extend/string'
4
+ require 'libis/tools/logger'
5
+ require 'libis/tools/command'
6
+
7
+ require 'libis/format/config'
8
+
9
+ module Libis
10
+ module Format
11
+ module Tool
12
+
13
+ class PdfProtect
14
+ include ::Libis::Tools::Logger
15
+
16
+ def self.run(source, target, options = [])
17
+ self.new.run source, target, options
18
+ end
19
+
20
+ def run(source, target, options = [])
21
+
22
+ if OS.java?
23
+ # TODO: import library and execute in current VM. For now do exactly as in MRI.
24
+ end
25
+
26
+ timeout = Libis::Format::Config[:timeouts][:pdf_copy]
27
+ result = Libis::Tools::Command.run(
28
+ Libis::Format::Config[:java_cmd],
29
+ '-jar', Libis::Format::Config[:pdf_tool],
30
+ 'protect',
31
+ '-i', source,
32
+ '-o', target,
33
+ *options,
34
+ timeout: timeout,
35
+ kill_after: timeout * 2
36
+ )
37
+
38
+ raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
39
+ raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
40
+
41
+ result
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ require 'os'
2
+
3
+ require 'libis/tools/extend/string'
4
+ require 'libis/tools/logger'
5
+ require 'libis/tools/command'
6
+
7
+ require 'libis/format/config'
8
+
9
+ module Libis
10
+ module Format
11
+ module Tool
12
+
13
+ class PdfSelect
14
+ include ::Libis::Tools::Logger
15
+
16
+ def self.run(source, target, options = [])
17
+ self.new.run source, target, options
18
+ end
19
+
20
+ def run(source, target, options = [])
21
+
22
+ if OS.java?
23
+ # TODO: import library and execute in current VM. For now do exactly as in MRI.
24
+ end
25
+
26
+ timeout = Libis::Format::Config[:timeouts][:pdf_select]
27
+ result = Libis::Tools::Command.run(
28
+ Libis::Format::Config[:java_cmd],
29
+ '-jar', Libis::Format::Config[:pdf_tool],
30
+ 'select',
31
+ '-i', source,
32
+ '-o', target,
33
+ *options,
34
+ timeout: timeout,
35
+ kill_after: timeout * 2
36
+ )
37
+
38
+ raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
39
+ raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
40
+
41
+ result
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end