hydra-derivatives 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcf72cd8457040e024d1afc7165e39fcd934b9e6
4
- data.tar.gz: c32e5d6d99fd839685c76d3e7ae5f535ee9a2df5
3
+ metadata.gz: 14f09b6670a1ef6add67ed44818c17c7cf8c36b1
4
+ data.tar.gz: 408048906e8ab82bccb72a05c9849826cc09c742
5
5
  SHA512:
6
- metadata.gz: d0a0f31a6c6be71ed6d88ea9504cc6f16800449dd44d70c8b5c487cbcd232fee19acccb64c4f1b71a7d64a5029307a014b29698253d5433db6e945ff69399d56
7
- data.tar.gz: 33c5c95a19390035f4b4227acae0dd78ccf6053de8b9215f25b0f29559a9b9e3dc03cfe544d92bc15a20708f67f1a76a66aedc400fbae0179ef148381422fdbb
6
+ metadata.gz: 0d97b2c7b9cff0b1e09f0394feef16e136808cb840b50ff48bb40b6ed8e24903862a88e99b5f054f24fb80a4789a0bce5251cb02c3f942010311ab7ba24f32c9
7
+ data.tar.gz: 4afab72548ce8ba1524b9d957cd08574d1a543a6a0741ebc9e2ade3dc6675d731b7f7286d479d6b9920ed157e7a0bfc38d8a68e9a51f7cab6d403c378e679cd4
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # hydra-derivatives [![Version](https://badge.fury.io/rb/hydra-derivatives.png)](http://badge.fury.io/rb/hydra-derivatives) [![Build Status](https://travis-ci.org/projecthydra-labs/hydra-derivatives.png?branch=master)](https://travis-ci.org/projecthydra-labs/hydra-derivatives) [![Dependency Status](https://gemnasium.com/projecthydra-labs/hydra-derivatives.png)](https://gemnasium.com/projecthydra-labs/hydra-derivatives)
1
+ # hydra-derivatives [![Version](https://badge.fury.io/rb/hydra-derivatives.png)](http://badge.fury.io/rb/hydra-derivatives) [![Build Status](https://travis-ci.org/projecthydra/hydra-derivatives.png?branch=master)](https://travis-ci.org/projecthydra/hydra-derivatives) [![Dependency Status](https://gemnasium.com/projecthydra/hydra-derivatives.png)](https://gemnasium.com/projecthydra/hydra-derivatives)
2
2
 
3
3
  Derivative generation for hydra
4
4
 
@@ -70,6 +70,34 @@ Then when you call `obj.create_derivatives` two new files, 'thumbnail' and 'cont
70
70
 
71
71
  We recommend you run `obj.create_derivatives` in a background worker, because some derivative creation (especially videos) can take a long time.
72
72
 
73
+ ## Configuration
74
+
75
+ ### Processing Timeouts
76
+
77
+ hydra-derivatives can be configured to timeout derivatives processes. Each process type has a separate timeout.
78
+ If no timeout is set the system will process until complete (possibly indefinitely).
79
+
80
+ ```
81
+ require 'hydra/derivatives'
82
+
83
+ Hydra::Derivatives::Video::Processor.timeout = 10.minutes
84
+ Hydra::Derivatives::Document.timeout = 5.minutes
85
+ Hydra::Derivatives::Audio.timeout = 10.minutes
86
+ Hydra::Derivatives::Image.timeout = 5.minutes
87
+
88
+ ```
89
+
90
+ ### Video Processing configuration
91
+
92
+ Flags can be set for using different video codes. Default codecs are shown below
93
+
94
+ ```
95
+ Hydra::Derivatives::Video::Processor.config.mpeg4.codec = '-vcodec libx264 -acodec libfdk_aac'
96
+ Hydra::Derivatives::Video::Processor.config.webm.codec = '-vcodec libvpx -acodec libvorbis'
97
+ Hydra::Derivatives::Video::Processor.config.mkv.codec = '-vcodec ffv1'
98
+ Hydra::Derivatives::Video::Processor.config.jpeg.codec = '-vcodec mjpeg'
99
+ ```
100
+
73
101
  # Installation
74
102
 
75
103
  Just add `gem 'hydra-derivatives'` to your Gemfile.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'hydra-file_characterization', '~> 0.3'
27
27
  spec.add_dependency 'mini_magick', '>= 3.2', '< 5'
28
28
  spec.add_dependency 'activesupport', '~> 4.0'
29
- spec.add_dependency 'mime-types', '~> 2.3'
29
+ spec.add_dependency 'mime-types', '~> 1'
30
30
  spec.add_dependency 'deprecation', '~> 0.1'
31
31
  end
32
32
 
@@ -9,7 +9,7 @@ module Hydra
9
9
  execute "#{Hydra::Derivatives.libreoffice_path} --invisible --headless --convert-to #{format} --outdir #{outdir} #{path}"
10
10
  end
11
11
 
12
- def encode_file(dest_path, file_suffix, mime_type, options = '')
12
+ def encode_file(dest_path, file_suffix, mime_type, options = { })
13
13
  new_output = ''
14
14
  source_file.to_tempfile do |f|
15
15
  if mime_type == 'image/jpeg'
@@ -19,10 +19,8 @@ module Hydra
19
19
  module ClassMethods
20
20
 
21
21
  def encode(path, options, output_file)
22
- inopts = options[INPUT_OPTIONS] if options
23
- inopts ||= "-y"
24
- outopts = options[OUTPUT_OPTIONS] if options
25
- outopts ||= options
22
+ inopts = options[INPUT_OPTIONS] ||= "-y"
23
+ outopts = options[OUTPUT_OPTIONS] ||= ""
26
24
  execute "#{Hydra::Derivatives.ffmpeg_path} #{inopts} -i \"#{path}\" #{outopts} #{output_file}"
27
25
  end
28
26
  end
@@ -2,7 +2,21 @@ require 'mini_magick'
2
2
  module Hydra
3
3
  module Derivatives
4
4
  class Image < Processor
5
+ class_attribute :timeout
6
+
5
7
  def process
8
+ timeout ? process_with_timeout : process_without_timeout
9
+ end
10
+
11
+ def process_with_timeout
12
+ status = Timeout::timeout(timeout) do
13
+ process_without_timeout
14
+ end
15
+ rescue Timeout::Error => ex
16
+ raise Hydra::Derivatives::TimeoutError, "Unable to process image derivative\nThe command took longer than #{timeout} seconds to execute"
17
+ end
18
+
19
+ def process_without_timeout
6
20
  directives.each do |name, args|
7
21
  opts = args.kind_of?(Hash) ? args : {size: args}
8
22
  format = opts.fetch(:format, 'png')
@@ -35,4 +35,3 @@ module Hydra
35
35
  end
36
36
  end
37
37
  end
38
-
@@ -24,10 +24,12 @@ module Hydra
24
24
  end
25
25
 
26
26
  # override this method in subclass if you want to provide specific options.
27
+ # returns a hash of options that the specific processors use
27
28
  def options_for(format)
29
+ {}
28
30
  end
29
31
 
30
- def encode_file(dest_path, file_suffix, mime_type, options = '')
32
+ def encode_file(dest_path, file_suffix, mime_type, options)
31
33
  out_file = nil
32
34
  output_file = Dir::Tmpname.create(['sufia', ".#{file_suffix}"], Hydra::Derivatives.temp_file_base){}
33
35
  source_file.to_tempfile do |f|
@@ -6,7 +6,7 @@ describe Hydra::Derivatives::Image do
6
6
 
7
7
  subject { Hydra::Derivatives::Image.new(object, 'content', directives)}
8
8
 
9
- before { expect(subject).to receive(:output_file).with(file_name).and_return(output_file) }
9
+ before { allow(subject).to receive(:output_file).with(file_name).and_return(output_file) }
10
10
 
11
11
  describe "when arguments are passed as a string" do
12
12
  let(:directives) { { thumb: "100x100>" } }
@@ -27,4 +27,32 @@ describe Hydra::Derivatives::Image do
27
27
  subject.process
28
28
  end
29
29
  end
30
+
31
+ describe 'timeout' do
32
+ let(:directives) { { thumb: "100x100>" } }
33
+ let(:file_name) { 'content_thumb' }
34
+
35
+ before do
36
+ allow(subject).to receive(:create_resized_image).with(output_file, "100x100>", 'png')
37
+ end
38
+
39
+ context 'when set' do
40
+ before do
41
+ subject.timeout = 0.1
42
+ allow_any_instance_of(Hydra::Derivatives::Image).to receive(:process_without_timeout) { sleep 0.2 }
43
+ end
44
+ it 'raises a timeout exception' do
45
+ expect { subject.process }.to raise_error Hydra::Derivatives::TimeoutError
46
+ end
47
+ end
48
+
49
+ context 'when not set' do
50
+ before { subject.timeout = nil }
51
+ it 'processes without a timeout' do
52
+ expect(subject).to receive(:process_with_timeout).never
53
+ expect(subject).to receive(:process_without_timeout).once
54
+ subject.process
55
+ end
56
+ end
57
+ end
30
58
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Hydra::Derivatives::ShellBasedProcessor do
5
+ class TestProcessor <
6
+ include Hydra::Derivatives::ShellBasedProcessor
7
+ end
8
+
9
+ let (:processor) {TestProcessor.new}
10
+
11
+ describe "has expected interface" do
12
+
13
+ describe "options_for" do
14
+ it "returns a hash" do
15
+ expect(processor.options_for("a")).to be_a Hash
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+
22
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-derivatives
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-30 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,14 +134,14 @@ dependencies:
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '2.3'
137
+ version: '1'
138
138
  type: :runtime
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '2.3'
144
+ version: '1'
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: deprecation
147
147
  requirement: !ruby/object:Gem::Requirement
@@ -214,6 +214,7 @@ files:
214
214
  - spec/units/image_spec.rb
215
215
  - spec/units/jpeg2k_spec.rb
216
216
  - spec/units/logger_spec.rb
217
+ - spec/units/shell_based_processor_spec.rb
217
218
  - spec/units/transcoding_spec.rb
218
219
  - spec/units/video_spec.rb
219
220
  homepage: https://github.com/projecthydra/hydra-derivatives
@@ -236,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
237
  version: '0'
237
238
  requirements: []
238
239
  rubyforge_project:
239
- rubygems_version: 2.2.2
240
+ rubygems_version: 2.4.6
240
241
  signing_key:
241
242
  specification_version: 4
242
243
  summary: Derivative generation plugin for hydra
@@ -262,6 +263,6 @@ test_files:
262
263
  - spec/units/image_spec.rb
263
264
  - spec/units/jpeg2k_spec.rb
264
265
  - spec/units/logger_spec.rb
266
+ - spec/units/shell_based_processor_spec.rb
265
267
  - spec/units/transcoding_spec.rb
266
268
  - spec/units/video_spec.rb
267
- has_rdoc: