hydra-derivatives 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/History.md +43 -0
- data/README.md +23 -38
- data/VERSION +1 -1
- data/hydra-derivatives.gemspec +0 -1
- data/lib/hydra/derivatives.rb +23 -123
- data/lib/hydra/derivatives/io_decorator.rb +7 -1
- data/lib/hydra/derivatives/processors.rb +19 -0
- data/lib/hydra/derivatives/processors/audio.rb +6 -0
- data/lib/hydra/derivatives/processors/document.rb +28 -0
- data/lib/hydra/derivatives/processors/ffmpeg.rb +22 -0
- data/lib/hydra/derivatives/processors/full_text.rb +60 -0
- data/lib/hydra/derivatives/processors/image.rb +58 -0
- data/lib/hydra/derivatives/processors/jpeg2k_image.rb +129 -0
- data/lib/hydra/derivatives/processors/processor.rb +38 -0
- data/lib/hydra/derivatives/processors/raw_image.rb +37 -0
- data/lib/hydra/derivatives/processors/shell_based_processor.rb +108 -0
- data/lib/hydra/derivatives/{video.rb → processors/video.rb} +1 -1
- data/lib/hydra/derivatives/{video → processors/video}/config.rb +1 -1
- data/lib/hydra/derivatives/{video → processors/video}/processor.rb +2 -8
- data/lib/hydra/derivatives/runners/audio_derivatives.rb +7 -0
- data/lib/hydra/derivatives/runners/document_derivatives.rb +7 -0
- data/lib/hydra/derivatives/runners/full_text_extract.rb +16 -0
- data/lib/hydra/derivatives/runners/image_derivatives.rb +16 -0
- data/lib/hydra/derivatives/runners/jpeg2k_image_derivatives.rb +15 -0
- data/lib/hydra/derivatives/runners/pdf_derivatives.rb +6 -0
- data/lib/hydra/derivatives/runners/runner.rb +52 -0
- data/lib/hydra/derivatives/runners/video_derivatives.rb +7 -0
- data/lib/hydra/derivatives/services/mime_type_service.rb +10 -0
- data/lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb +23 -8
- data/lib/hydra/derivatives/services/persist_output_file_service.rb +4 -5
- data/lib/hydra/derivatives/services/retrieve_source_file_service.rb +8 -6
- data/spec/processors/full_text.rb +61 -0
- data/spec/{units → processors}/image_spec.rb +7 -17
- data/spec/{units → processors}/jpeg2k_spec.rb +9 -11
- data/spec/processors/processor_spec.rb +36 -0
- data/spec/processors/shell_based_processor_spec.rb +19 -0
- data/spec/processors/video_spec.rb +40 -0
- data/spec/services/audio_derivatives_spec.rb +76 -0
- data/spec/services/persist_basic_contained_output_file_service_spec.rb +4 -3
- data/spec/services/retrieve_source_file_service_spec.rb +16 -12
- data/spec/units/derivatives_spec.rb +18 -26
- data/spec/units/io_decorator_spec.rb +33 -0
- data/spec/units/transcoding_spec.rb +109 -86
- metadata +42 -44
- data/lib/hydra/derivatives/audio.rb +0 -19
- data/lib/hydra/derivatives/document.rb +0 -56
- data/lib/hydra/derivatives/extract_metadata.rb +0 -27
- data/lib/hydra/derivatives/ffmpeg.rb +0 -31
- data/lib/hydra/derivatives/image.rb +0 -73
- data/lib/hydra/derivatives/jpeg2k_image.rb +0 -136
- data/lib/hydra/derivatives/processor.rb +0 -33
- data/lib/hydra/derivatives/railtie.rb +0 -9
- data/lib/hydra/derivatives/raw_image.rb +0 -45
- data/lib/hydra/derivatives/shell_based_processor.rb +0 -81
- data/spec/lib/hydra/derivatives/extract_metadata_spec.rb +0 -39
- data/spec/units/extract_spec.rb +0 -22
- data/spec/units/processor_spec.rb +0 -61
- data/spec/units/shell_based_processor_spec.rb +0 -22
- data/spec/units/video_spec.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ca2b76caf4ff9ceb741524636c569044af87529
|
4
|
+
data.tar.gz: 8f166356f9cf966d055e0c51341b628afeb236e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5fec89d3e2f7ec198baf9b6db62d39c8fd371abe3b38aeb336b9873b6d964d402f4bd1d8074969adaada0b0cca495b18af8cd88c22cb8dd9597a7f02ecd31de
|
7
|
+
data.tar.gz: fedc87879a089b05f20113cc207be5edfcbc33ecba3b35439a37d134c0cee360450001e6c914fd476d25802875a04526e0ff2ca9d5feecb8804913b88ba13f03
|
data/.travis.yml
CHANGED
data/History.md
CHANGED
@@ -1,3 +1,46 @@
|
|
1
|
+
## 3.0.0 (2015-10-07)
|
2
|
+
2015-10-07: Update to the containerized builds on travis [Justin Coyne]
|
3
|
+
|
4
|
+
2015-10-07: Add full text extraction as a processor [Justin Coyne]
|
5
|
+
|
6
|
+
2015-10-06: make quality be passed when creating an image [lutz]
|
7
|
+
|
8
|
+
2015-10-02: Put the processors into their own namespace [Justin Coyne]
|
9
|
+
|
10
|
+
2015-10-01: Make the IoDecorator initializer 1-3 args [Justin Coyne]
|
11
|
+
|
12
|
+
2015-09-29: Refactor to allow saving at a uri [Justin Coyne]
|
13
|
+
|
14
|
+
2015-09-28: Transcode local files [Justin Coyne]
|
15
|
+
|
16
|
+
2015-09-30: Remove ExtractMetadata. Fixes #76 [Justin Coyne]
|
17
|
+
|
18
|
+
2015-09-28: Rename the :datastream option to :output\_path [Justin Coyne]
|
19
|
+
|
20
|
+
2015-09-25: Remove my PSU address from Travis config [Michael J. Giarlo]
|
21
|
+
|
22
|
+
2015-09-21: Use IO.select so that all buffers get read (and the process can
|
23
|
+
terminate). Ref #81 [Justin Coyne]
|
24
|
+
|
25
|
+
2015-09-16: Log the exit code on failure [Justin Coyne]
|
26
|
+
|
27
|
+
2015-09-09: Update README.md [Justin Coyne]
|
28
|
+
|
29
|
+
2015-09-04: fits version specified [Nikitas Tampakis]
|
30
|
+
|
31
|
+
2015-08-28: Update directions to install openoffice headless [ci skip] [Justin
|
32
|
+
Coyne]
|
33
|
+
|
34
|
+
2015-08-28: List supported version of libreoffice [Justin Coyne]
|
35
|
+
|
36
|
+
2015-08-21: Update documentation to show IoDecorator [Justin Coyne]
|
37
|
+
|
38
|
+
2015-08-21: Add a deprecation horizion to the deprecation message [Justin Coyne]
|
39
|
+
|
40
|
+
2015-08-06: change call to transform\_file, in the deprecated method
|
41
|
+
transform\_datastream, to not pass a default options values, since the method def
|
42
|
+
for transform\_file already sets the default values. [Jose Blanco]
|
43
|
+
|
1
44
|
## 0.1.1 (2014-07-21)
|
2
45
|
- Define a logger
|
3
46
|
|
data/README.md
CHANGED
@@ -11,47 +11,24 @@ If you have an ActiveFedora class like this:
|
|
11
11
|
attr_accessor :mime_type
|
12
12
|
|
13
13
|
# Use a block to declare which derivatives you want to generate
|
14
|
-
makes_derivatives do |obj|
|
15
|
-
case obj.mime_type
|
16
|
-
when 'application/pdf'
|
17
|
-
obj.transform_file :original_file, { :thumb => "100x100>" }
|
18
|
-
when 'audio/wav'
|
19
|
-
obj.transform_file :original_file, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
|
20
|
-
when 'video/avi'
|
21
|
-
obj.transform_file :original_file, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
|
22
|
-
when 'image/png', 'image/jpg'
|
23
|
-
obj.transform_file :original_file, { :medium => "300x300>", :thumb => "100x100>" }
|
24
|
-
when 'image/tiff'
|
25
|
-
obj.transform_file :original_file, { :service => { resize: "3600x3600>" } }, processor: 'jpeg2k_image'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
```
|
30
|
-
|
31
|
-
Or a class like this:
|
32
|
-
|
33
|
-
```ruby
|
34
|
-
class GenericFile < ActiveFedora::Base
|
35
|
-
include Hydra::Derivatives
|
36
|
-
|
37
|
-
contains 'original_file'
|
38
|
-
attr_accessor :mime_type
|
39
|
-
|
40
|
-
# Use a callback method to declare which derivatives you want
|
41
|
-
makes_derivatives :generate_derivatives
|
42
14
|
|
43
|
-
def
|
15
|
+
def create_derivatives(filename)
|
44
16
|
case mime_type
|
45
17
|
when 'application/pdf'
|
46
|
-
|
18
|
+
PdfDerivatives.create(filename, outputs: [{ label: :thumb, size: "100x100>" }]
|
47
19
|
when 'audio/wav'
|
48
|
-
|
20
|
+
AudioDerivatives.create(self, source: :original_file, outputs: [{ label: :mp3, format: 'mp3', url: "#{uri}/mp3" }, { label: :ogg, format: 'ogg', url: "#{uri}/ogg" }])
|
49
21
|
when 'video/avi'
|
50
|
-
|
22
|
+
VideoDerivatives.create(filename, outputs: [{ label: :mp4, format: 'mp4'}, { label: :webm, format: 'webm'}])
|
51
23
|
when 'image/png', 'image/jpg'
|
52
|
-
|
24
|
+
ImageDerivatives.create(self, source: :original_file,
|
25
|
+
outputs: [
|
26
|
+
{ label: :medium, size: "300x300>", url: "#{uri}/medium" },
|
27
|
+
{ label: :thumb, size: "100x100>", url: "#{uri}/thumb" }])
|
28
|
+
when 'application/vnd.ms-powerpoint'
|
29
|
+
DocumentDerivatives.create(filename, outputs[{ label: :preservation, format: 'pptx' }, { label: :access, format: 'pdf' }, { label: :thumnail, format: 'jpg' })
|
53
30
|
when 'image/tiff'
|
54
|
-
|
31
|
+
Jpeg2kDerivatives.create(filename, outputs: [{ label: :service, resize: "3600x3600>" }])
|
55
32
|
end
|
56
33
|
end
|
57
34
|
end
|
@@ -72,6 +49,14 @@ We recommend you run `obj.create_derivatives` in a background worker, because so
|
|
72
49
|
|
73
50
|
## Configuration
|
74
51
|
|
52
|
+
### Retrieving from a basic container in Fedora
|
53
|
+
|
54
|
+
Provide the object and `:source` option instead of a filename
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
PdfDerivatives.create(active_fedora_object, source: :original_file, outputs: [{ label: :thumb, size: "100x100>" }]
|
58
|
+
```
|
59
|
+
|
75
60
|
### Processing Timeouts
|
76
61
|
|
77
62
|
hydra-derivatives can be configured to timeout derivatives processes. Each process type has a separate timeout.
|
@@ -104,11 +89,11 @@ Just add `gem 'hydra-derivatives'` to your Gemfile.
|
|
104
89
|
|
105
90
|
## Dependencies
|
106
91
|
|
107
|
-
* [FITS](http://fitstool.org/)
|
92
|
+
* [FITS](http://fitstool.org/) - version 0.6.2
|
108
93
|
* [FFMpeg](http://www.ffmpeg.org/)
|
109
|
-
* [LibreOffice](https://www.libreoffice.org/)
|
94
|
+
* [LibreOffice](https://www.libreoffice.org/) (openoffice.org-headless on Ubuntu/Debian to avoid "_X11 error: Can't open display:_")
|
110
95
|
* [ImageMagick](http://www.imagemagick.org/)
|
111
|
-
* Kakadu's [kdu_compress](http://www.kakadusoftware.com/)
|
96
|
+
* Kakadu's [kdu_compress](http://www.kakadusoftware.com/) (optional)
|
112
97
|
|
113
98
|
To enable LibreOffice, FFMpeg, ImageMagick, FITS support, and kdu_compress support, make sure they are on your path. Most people will put that in their .bash_profile or somewhere similar.
|
114
99
|
|
@@ -133,7 +118,7 @@ Unlike the other processors, the `Jpeg2kImage` processor does not generally acce
|
|
133
118
|
|
134
119
|
Instead, each directive may contain these arguments:
|
135
120
|
|
136
|
-
* `:
|
121
|
+
* `:output_path` (String) : The name for the new file
|
137
122
|
* `:to_srgb` (Boolean) : If `true` and the image is a color image it will map the source image color profile to sRGB. Default: `true`
|
138
123
|
* `:resize` (String) : Geometry; the same syntax as the `Hydra::Derivatives::Image` processor
|
139
124
|
* `:recipe` :
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.0
|
data/hydra-derivatives.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.1'
|
24
24
|
|
25
25
|
spec.add_dependency 'active-fedora', '~> 9.0'
|
26
|
-
spec.add_dependency 'hydra-file_characterization', '~> 0.3'
|
27
26
|
spec.add_dependency 'mini_magick', '>= 3.2', '< 5'
|
28
27
|
spec.add_dependency 'activesupport', '~> 4.0'
|
29
28
|
spec.add_dependency 'mime-types', '< 3'
|
data/lib/hydra/derivatives.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'active_fedora'
|
2
|
-
require 'hydra/derivatives/railtie' if defined?(Rails)
|
3
2
|
require 'deprecation'
|
4
3
|
|
5
4
|
module Hydra
|
@@ -9,26 +8,32 @@ module Hydra
|
|
9
8
|
extend Deprecation
|
10
9
|
self.deprecation_horizon = "hydra-derivatives 1.0"
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
# Runners take a single input and produce one or more outputs
|
12
|
+
# The runner typically accomplishes this by using one or more processors
|
13
|
+
autoload_under 'runners' do
|
14
|
+
autoload :AudioDerivatives
|
15
|
+
autoload :DocumentDerivatives
|
16
|
+
autoload :FullTextExtract
|
17
|
+
autoload :ImageDerivatives
|
18
|
+
autoload :Jpeg2kImageDerivatives
|
19
|
+
autoload :PdfDerivatives
|
20
|
+
autoload :Runner
|
21
|
+
autoload :VideoDerivatives
|
22
|
+
end
|
23
|
+
|
24
|
+
autoload :Processors
|
17
25
|
autoload :Config
|
18
|
-
autoload :Document
|
19
|
-
autoload :ExtractMetadata
|
20
|
-
autoload :ShellBasedProcessor
|
21
|
-
autoload :Jpeg2kImage
|
22
|
-
autoload :RawImage
|
23
26
|
autoload :Logger
|
24
27
|
autoload :TempfileService
|
25
28
|
autoload :IoDecorator
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
autoload_under 'services' do
|
31
|
+
autoload :RetrieveSourceFileService
|
32
|
+
autoload :PersistOutputFileService
|
33
|
+
autoload :PersistBasicContainedOutputFileService
|
34
|
+
autoload :TempfileService
|
35
|
+
autoload :MimeTypeService
|
36
|
+
end
|
32
37
|
|
33
38
|
# Raised if the timout elapses
|
34
39
|
class TimeoutError < ::Timeout::Error; end
|
@@ -54,113 +59,8 @@ module Hydra
|
|
54
59
|
end
|
55
60
|
|
56
61
|
included do
|
57
|
-
class_attribute :
|
58
|
-
|
59
|
-
|
60
|
-
# Runs all of the transformations immediately.
|
61
|
-
# You may want to run this job in the background as it may take a long time.
|
62
|
-
def create_derivatives
|
63
|
-
if transformation_schemes.present?
|
64
|
-
transformation_schemes.each do |transform_scheme|
|
65
|
-
if transform_scheme.instance_of?(Proc)
|
66
|
-
transform_scheme.call(self)
|
67
|
-
else
|
68
|
-
send(transform_scheme)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
else
|
72
|
-
logger.warn "`create_derivatives' was called on an instance of #{self.class}, but no derivatives have been requested"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Create derivatives from a file according to transformation directives
|
77
|
-
# @param file_name
|
78
|
-
# @param [Hash] transform_directives - each key corresponds to a desired derivative. Associated values vary according to processor being used.
|
79
|
-
# @param [Hash] opts for specifying things like choice of :processor (processor defaults to :image)
|
80
|
-
# @option opts [Symbol] :processor (:image) Processor to use
|
81
|
-
# @option opts [Class] :source_file_service (Hydra::Derivatives::RetrieveSourceFileService) service to use when persisting generated derivatives. The default for this can be set in your config file.
|
82
|
-
# @option opts [Class] :output_file_service (Hydra::Derivatives::PersistIndirectlyContainedOutputFile) service to use when retrieving the source. The default for this can be set in your config file.
|
83
|
-
#
|
84
|
-
# @example This will create content_thumb
|
85
|
-
# transform_file :content, { :thumb => "100x100>" }
|
86
|
-
#
|
87
|
-
# @example Specify the dsid for the output file
|
88
|
-
# transform_file :content, { :thumb => {size: "200x300>", datastream: 'thumbnail'} }
|
89
|
-
#
|
90
|
-
# @example Create multiple derivatives with one set of directives. This will create content_thumb and content_medium
|
91
|
-
# transform_file :content, { :medium => "300x300>", :thumb => "100x100>" }
|
92
|
-
#
|
93
|
-
# @example Specify which processor you want to use (defaults to :image)
|
94
|
-
# transform_file :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
|
95
|
-
# transform_file :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
|
96
|
-
#
|
97
|
-
# @example Specify an output file service to use when persisting generated derivatives
|
98
|
-
# obj.transform_file :content, { mp4: { format: 'mp4' } }, processor: :video, output_file_service: My::System::PersistOutputFileToTapeStorage
|
99
|
-
#
|
100
|
-
# @example Specify a source file service to use when retrieving the source
|
101
|
-
# obj.transform_file :content, { mp4: { format: 'mp4' } }, processor: :video, source_file_service: My::System::PersistOutputFileToTapeStorage
|
102
|
-
|
103
|
-
def transform_file(file_name, transform_directives, opts={})
|
104
|
-
initialize_processor(file_name, transform_directives, opts).process
|
105
|
-
end
|
106
|
-
|
107
|
-
def processor_class(processor)
|
108
|
-
case processor
|
109
|
-
when :video
|
110
|
-
Hydra::Derivatives::Video::Processor
|
111
|
-
else
|
112
|
-
constantize_processor(processor.to_s)
|
113
|
-
end
|
62
|
+
class_attribute :source_file_service
|
63
|
+
self.source_file_service = Hydra::Derivatives.source_file_service
|
114
64
|
end
|
115
|
-
|
116
|
-
def constantize_processor(processor)
|
117
|
-
"Hydra::Derivatives::#{processor.classify}".constantize
|
118
|
-
rescue NameError
|
119
|
-
processor.classify.constantize
|
120
|
-
end
|
121
|
-
|
122
|
-
def transform_datastream(file_name, transform_directives, opts={})
|
123
|
-
transform_file(file_name, transform_directives, opts={})
|
124
|
-
end
|
125
|
-
deprecation_deprecate :transform_datastream
|
126
|
-
|
127
|
-
|
128
|
-
module ClassMethods
|
129
|
-
# Register transformation schemes for generating derivatives.
|
130
|
-
# You can do this using a block or by defining a callback method.
|
131
|
-
#
|
132
|
-
# @example Define transformation scheme using a block
|
133
|
-
# makes_derivatives do |obj|
|
134
|
-
# case obj.mime_type
|
135
|
-
# when 'application/pdf'
|
136
|
-
# obj.transform_file :content, { :thumb => "100x100>" }
|
137
|
-
# when 'audio/wav'
|
138
|
-
# obj.transform_file :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
|
139
|
-
#
|
140
|
-
# @example Define transformation scheme using a callback method
|
141
|
-
# makes_derivatives :generate_image_derivatives
|
142
|
-
#
|
143
|
-
# def generate_image_derivatives
|
144
|
-
# case mime_type
|
145
|
-
# when 'image/png', 'image/jpg'
|
146
|
-
# transform_file :content, { :medium => "300x300>", :thumb => "100x100>" }
|
147
|
-
# end
|
148
|
-
# end
|
149
|
-
def makes_derivatives(*callback_method_names, &block)
|
150
|
-
self.transformation_schemes ||= []
|
151
|
-
if block_given?
|
152
|
-
self.transformation_schemes << block
|
153
|
-
end
|
154
|
-
callback_method_names.each do |callback_name|
|
155
|
-
self.transformation_schemes << callback_name
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
private
|
161
|
-
def initialize_processor(file_name, transform_directives, opts={})
|
162
|
-
processor_class(opts[:processor] || :image).new(self, file_name, transform_directives, opts)
|
163
|
-
end
|
164
|
-
|
165
65
|
end
|
166
66
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Nieve implementation of IO wrapper class that adds mime_type and original_name attributes.
|
2
|
-
# This is done so the attributes do not have to be passed as additional arguments,
|
2
|
+
# This is done so the attributes do not have to be passed as additional arguments,
|
3
3
|
# and are attached properly to the object they describe.
|
4
4
|
#
|
5
5
|
#
|
@@ -10,6 +10,12 @@ module Hydra
|
|
10
10
|
module Derivatives
|
11
11
|
class IoDecorator < SimpleDelegator
|
12
12
|
attr_accessor :mime_type, :original_name
|
13
|
+
|
14
|
+
def initialize(file, mime_type = nil, original_name = nil)
|
15
|
+
super(file)
|
16
|
+
self.mime_type = mime_type
|
17
|
+
self.original_name = original_name
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Hydra::Derivatives
|
2
|
+
module Processors
|
3
|
+
extend ActiveSupport::Autoload
|
4
|
+
|
5
|
+
eager_autoload do
|
6
|
+
autoload :Processor
|
7
|
+
end
|
8
|
+
|
9
|
+
autoload :Audio
|
10
|
+
autoload :Document
|
11
|
+
autoload :Ffmpeg
|
12
|
+
autoload :FullText
|
13
|
+
autoload :Image
|
14
|
+
autoload :Jpeg2kImage
|
15
|
+
autoload :RawImage
|
16
|
+
autoload :ShellBasedProcessor
|
17
|
+
autoload :Video
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Hydra::Derivatives::Processors
|
2
|
+
class Document < Processor
|
3
|
+
include ShellBasedProcessor
|
4
|
+
|
5
|
+
def self.encode(path, options, output_file)
|
6
|
+
format = File.extname(output_file).sub('.', '')
|
7
|
+
outdir = File.dirname(output_file)
|
8
|
+
execute "#{Hydra::Derivatives.libreoffice_path} --invisible --headless --convert-to #{format} --outdir #{outdir} #{path}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def encode_file(file_suffix, options = { })
|
12
|
+
new_output = ''
|
13
|
+
if file_suffix == 'jpg'
|
14
|
+
temp_file = File.join(Hydra::Derivatives.temp_file_base, [directives.fetch(:label).to_s, 'pdf'].join('.'))
|
15
|
+
new_output = File.join(Hydra::Derivatives.temp_file_base, [File.basename(temp_file).sub(File.extname(temp_file), ''), file_suffix].join('.'))
|
16
|
+
self.class.encode(source_path, options, temp_file)
|
17
|
+
self.class.encode(temp_file, options, output_file(file_suffix))
|
18
|
+
File.unlink(temp_file)
|
19
|
+
else
|
20
|
+
self.class.encode(source_path, options, output_file(file_suffix))
|
21
|
+
new_output = File.join(Hydra::Derivatives.temp_file_base, [directives.fetch(:label).to_s, file_suffix].join('.'))
|
22
|
+
end
|
23
|
+
out_file = File.open(new_output, "rb")
|
24
|
+
output_file_service.call(out_file, directives)
|
25
|
+
File.unlink(out_file)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# An abstract class for asyncronous jobs that transcode files using FFMpeg
|
2
|
+
module Hydra::Derivatives::Processors
|
3
|
+
module Ffmpeg
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
INPUT_OPTIONS=:input_options
|
7
|
+
OUTPUT_OPTIONS=:output_options
|
8
|
+
|
9
|
+
included do
|
10
|
+
include ShellBasedProcessor
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def encode(path, options, output_file)
|
16
|
+
inopts = options[INPUT_OPTIONS] ||= "-y"
|
17
|
+
outopts = options[OUTPUT_OPTIONS] ||= ""
|
18
|
+
execute "#{Hydra::Derivatives.ffmpeg_path} #{inopts} -i \"#{path}\" #{outopts} #{output_file}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|