bpl-derivatives 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +11 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +60 -0
  8. data/Rakefile +7 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/bpl-derivatives.gemspec +50 -0
  12. data/lib/bpl/derivatives.rb +74 -0
  13. data/lib/bpl/derivatives/audio_encoder.rb +27 -0
  14. data/lib/bpl/derivatives/config.rb +64 -0
  15. data/lib/bpl/derivatives/datastream_decorator.rb +31 -0
  16. data/lib/bpl/derivatives/input_object_decorator.rb +11 -0
  17. data/lib/bpl/derivatives/io_decorator.rb +15 -0
  18. data/lib/bpl/derivatives/logger.rb +25 -0
  19. data/lib/bpl/derivatives/output_object_decorator.rb +12 -0
  20. data/lib/bpl/derivatives/processors.rb +18 -0
  21. data/lib/bpl/derivatives/processors/audio.rb +5 -0
  22. data/lib/bpl/derivatives/processors/document.rb +45 -0
  23. data/lib/bpl/derivatives/processors/ffmpeg.rb +21 -0
  24. data/lib/bpl/derivatives/processors/image.rb +76 -0
  25. data/lib/bpl/derivatives/processors/jpeg2k_image.rb +127 -0
  26. data/lib/bpl/derivatives/processors/processor.rb +43 -0
  27. data/lib/bpl/derivatives/processors/raw_image.rb +37 -0
  28. data/lib/bpl/derivatives/processors/shell_based_processor.rb +103 -0
  29. data/lib/bpl/derivatives/processors/video.rb +10 -0
  30. data/lib/bpl/derivatives/processors/video/config.rb +66 -0
  31. data/lib/bpl/derivatives/processors/video/processor.rb +41 -0
  32. data/lib/bpl/derivatives/runners/audio_derivatives.rb +7 -0
  33. data/lib/bpl/derivatives/runners/document_derivatives.rb +7 -0
  34. data/lib/bpl/derivatives/runners/image_derivatives.rb +15 -0
  35. data/lib/bpl/derivatives/runners/jpeg2k_image_derivatives.rb +15 -0
  36. data/lib/bpl/derivatives/runners/pdf_derivatives.rb +4 -0
  37. data/lib/bpl/derivatives/runners/runner.rb +59 -0
  38. data/lib/bpl/derivatives/runners/video_derivatives.rb +7 -0
  39. data/lib/bpl/derivatives/services/capability_service.rb +17 -0
  40. data/lib/bpl/derivatives/services/mime_type_service.rb +14 -0
  41. data/lib/bpl/derivatives/services/persist_basic_contained_output_file_service.rb +73 -0
  42. data/lib/bpl/derivatives/services/persist_datastream_output_service.rb +30 -0
  43. data/lib/bpl/derivatives/services/persist_file_system_output_service.rb +31 -0
  44. data/lib/bpl/derivatives/services/persist_output_file_service.rb +24 -0
  45. data/lib/bpl/derivatives/services/retrieve_source_file_from_datastream_service.rb +12 -0
  46. data/lib/bpl/derivatives/services/retrieve_source_file_service.rb +13 -0
  47. data/lib/bpl/derivatives/services/tempfile_service.rb +65 -0
  48. data/lib/bpl/derivatives/version.rb +5 -0
  49. data/lib/color_profiles/license.txt +7 -0
  50. data/lib/color_profiles/sRGB_IEC61966-2-1_no_black_scaling.icc +0 -0
  51. metadata +238 -0
@@ -0,0 +1,12 @@
1
+ module BPL::Derivatives
2
+ class RetrieveSourceFileFromDatastreamService
3
+ # Retrieves the source
4
+ # @param [BPL::Derivatives::DatastreamDecorator] object the source file is attached to
5
+ # @param [Hash] options
6
+ # @option options [Symbol] :source a method that can be called on the object to retrieve the source file
7
+ # @yield [Tempfile] a temporary source file that has a lifetime of the block
8
+ def self.call(object, options, &block)
9
+ BPL::Derivatives::TempfileService.create(object, &block)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module BPL::Derivatives
2
+ class RetrieveSourceFileService
3
+ # Retrieves the source
4
+ # @param [ArbitraryObject] object the source file is attached to
5
+ # @param [Hash] options
6
+ # @option options [Symbol] :source a method that can be called on the object to retrieve the source file
7
+ # @yield [Tempfile] a temporary source file that has a lifetime of the block
8
+ def self.call(object, options, &block)
9
+ source_name = options.fetch(:source)
10
+ BPL::Derivatives::TempfileService.create(object.send(source_name), &block)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ require 'mime/types'
2
+
3
+ module BPL::Derivatives
4
+ class TempfileService
5
+ def self.create(object, &block)
6
+ new(object).tempfile(&block)
7
+ end
8
+
9
+ attr_reader :source_object, :source_file
10
+
11
+ def initialize(source_object)
12
+ @source_object = source_object
13
+ @source_file = nil
14
+ end
15
+
16
+ def source_file
17
+ if source_object.respond_to? :source_datastream
18
+ @source_file ||= source_object.source_datastream
19
+ else
20
+ @source_file ||= source_object
21
+ end
22
+ end
23
+
24
+ def tempfile(&block)
25
+ if source_file.respond_to? :to_tempfile
26
+ source_file.send(:to_tempfile, &block)
27
+ elsif source_file.has_content?
28
+ default_tempfile(&block)
29
+ end
30
+ end
31
+
32
+ def default_tempfile(&_block)
33
+ Tempfile.open(filename_for_characterization) do |f|
34
+ f.binmode
35
+ if source_file.content.respond_to? :read
36
+ f.write(source_file.content.read)
37
+ else
38
+ f.write(source_file.content)
39
+ end
40
+ source_file.content.rewind if source_file.content.respond_to? :rewind
41
+ f.rewind
42
+ yield(f)
43
+ end
44
+ end
45
+
46
+ protected
47
+
48
+ def filename_for_characterization
49
+ if source_file.respond_to? :filename_for_characterization
50
+ source_file.filename_for_characterization
51
+ else
52
+ default_filename_for_characterization
53
+ end
54
+ end
55
+
56
+ def default_filename_for_characterization
57
+ registered_mime_type = MIME::Types[source_file.mime_type].first
58
+ BPL::Derivatives.base_logger.warn "Unable to find a registered mime type for #{source_file.mime_type.inspect} on #{source_object.uri}" unless registered_mime_type
59
+ extension = registered_mime_type ? ".#{registered_mime_type.extensions.first}" : ''
60
+ version_id = 1 # TODO: fixme
61
+ m = %r{/([^/]*)$}.match(source_object.uri)
62
+ ["#{m[1]}-#{version_id}", extension.to_s]
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ module BPL
2
+ module Derivatives
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ Terms of use (from http://www.color.org/srgbprofiles.xalter#v2)
2
+
3
+ To anyone who acknowledges that the files "sRGB_IEC61966-2-1_no_black_scaling.icc" and "sRGB_IEC61966-2-1_black scaled.icc"
4
+ are provided "AS IS" WITH NO EXPRESS OR IMPLIED WARRANTY, permission to use, copy and distribute these file for any purpose
5
+ is hereby granted without fee, provided that the files are not changed including the ICC copyright notice tag, and that the
6
+ name of ICC shall not be used in advertising or publicity pertaining to distribution of the software without specific,
7
+ written prior permission. ICC makes no representations about the suitability of this software for any purpose.
metadata ADDED
@@ -0,0 +1,238 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bpl-derivatives
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Barber
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
33
+ - !ruby/object:Gem::Dependency
34
+ name: addressable
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.5'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.5'
47
+ - !ruby/object:Gem::Dependency
48
+ name: mime-types
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '4.0'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">"
62
+ - !ruby/object:Gem::Version
63
+ version: '2.0'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '4.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: mini_magick
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '3.2'
74
+ - - "<"
75
+ - !ruby/object:Gem::Version
76
+ version: '5'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '3.2'
84
+ - - "<"
85
+ - !ruby/object:Gem::Version
86
+ version: '5'
87
+ - !ruby/object:Gem::Dependency
88
+ name: bundler
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '2.0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '2.0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: rake
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '10.0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '10.0'
115
+ - !ruby/object:Gem::Dependency
116
+ name: rspec
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '3.8'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '3.8'
129
+ - !ruby/object:Gem::Dependency
130
+ name: pry
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: awesome_print
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ description: Dervivatives Processor borrowed heavily from Samvera hydra-derivatives
158
+ with the added benefit of being decoupled to ActiveFedora
159
+ email:
160
+ - bbarber@bpl.org
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - ".gitignore"
166
+ - ".rspec"
167
+ - ".travis.yml"
168
+ - Gemfile
169
+ - LICENSE.txt
170
+ - README.md
171
+ - Rakefile
172
+ - bin/console
173
+ - bin/setup
174
+ - bpl-derivatives.gemspec
175
+ - lib/bpl/derivatives.rb
176
+ - lib/bpl/derivatives/audio_encoder.rb
177
+ - lib/bpl/derivatives/config.rb
178
+ - lib/bpl/derivatives/datastream_decorator.rb
179
+ - lib/bpl/derivatives/input_object_decorator.rb
180
+ - lib/bpl/derivatives/io_decorator.rb
181
+ - lib/bpl/derivatives/logger.rb
182
+ - lib/bpl/derivatives/output_object_decorator.rb
183
+ - lib/bpl/derivatives/processors.rb
184
+ - lib/bpl/derivatives/processors/audio.rb
185
+ - lib/bpl/derivatives/processors/document.rb
186
+ - lib/bpl/derivatives/processors/ffmpeg.rb
187
+ - lib/bpl/derivatives/processors/image.rb
188
+ - lib/bpl/derivatives/processors/jpeg2k_image.rb
189
+ - lib/bpl/derivatives/processors/processor.rb
190
+ - lib/bpl/derivatives/processors/raw_image.rb
191
+ - lib/bpl/derivatives/processors/shell_based_processor.rb
192
+ - lib/bpl/derivatives/processors/video.rb
193
+ - lib/bpl/derivatives/processors/video/config.rb
194
+ - lib/bpl/derivatives/processors/video/processor.rb
195
+ - lib/bpl/derivatives/runners/audio_derivatives.rb
196
+ - lib/bpl/derivatives/runners/document_derivatives.rb
197
+ - lib/bpl/derivatives/runners/image_derivatives.rb
198
+ - lib/bpl/derivatives/runners/jpeg2k_image_derivatives.rb
199
+ - lib/bpl/derivatives/runners/pdf_derivatives.rb
200
+ - lib/bpl/derivatives/runners/runner.rb
201
+ - lib/bpl/derivatives/runners/video_derivatives.rb
202
+ - lib/bpl/derivatives/services/capability_service.rb
203
+ - lib/bpl/derivatives/services/mime_type_service.rb
204
+ - lib/bpl/derivatives/services/persist_basic_contained_output_file_service.rb
205
+ - lib/bpl/derivatives/services/persist_datastream_output_service.rb
206
+ - lib/bpl/derivatives/services/persist_file_system_output_service.rb
207
+ - lib/bpl/derivatives/services/persist_output_file_service.rb
208
+ - lib/bpl/derivatives/services/retrieve_source_file_from_datastream_service.rb
209
+ - lib/bpl/derivatives/services/retrieve_source_file_service.rb
210
+ - lib/bpl/derivatives/services/tempfile_service.rb
211
+ - lib/bpl/derivatives/version.rb
212
+ - lib/color_profiles/license.txt
213
+ - lib/color_profiles/sRGB_IEC61966-2-1_no_black_scaling.icc
214
+ homepage: https://github.com/boston-library/bpl-derivatives
215
+ licenses:
216
+ - MIT
217
+ metadata: {}
218
+ post_install_message:
219
+ rdoc_options: []
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ required_rubygems_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ requirements: []
233
+ rubyforge_project:
234
+ rubygems_version: 2.6.14.3
235
+ signing_key:
236
+ specification_version: 4
237
+ summary: Dervivatives Processor borrowed heavily from Samvera hydra-derivatives
238
+ test_files: []