hydra-derivatives 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +32 -0
- data/VERSION +1 -1
- data/lib/hydra/derivatives.rb +10 -8
- data/lib/hydra/derivatives/ffmpeg.rb +4 -2
- data/spec/units/transcoding_spec.rb +4 -4
- data/spec/units/video_spec.rb +26 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74b15261c78629ff97614bc0090102ceed0c5fa7
|
4
|
+
data.tar.gz: 268d962f2ea5607db494c67455878d8cb8eab25d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c7c0aa06d5fd7059e4bb9886d2f241ff5a7f00508941bb7650907464e0a3d59e1d884fddc61208068930a263c420e952534bb91c5931deadd896695ba8fd607
|
7
|
+
data.tar.gz: 5b5b6f7800798afe8dd7688638bdf88f643c6990d1cb0dad011d2f36c54238f2fc48e97f5fdaef6664d84daca620ed0b9ac9a0d8b2b0c0a51eeab843a7ecd84e
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,3 +2,35 @@ hydra-derivatives
|
|
2
2
|
=================
|
3
3
|
|
4
4
|
Derivative generation for hydra
|
5
|
+
|
6
|
+
If you have an ActiveFedora class like this:
|
7
|
+
```ruby
|
8
|
+
class GenericFile < ActiveFedora::Base
|
9
|
+
include Hydra::Derivatives
|
10
|
+
|
11
|
+
has_file_datastream :content
|
12
|
+
attr_accessor :mime_type
|
13
|
+
|
14
|
+
makes_derivatives_of :content, when: :mime_type, is_one_of: ['image/tiff', 'image/jpeg],
|
15
|
+
derivatives: { :thumbnail => {size: "200x150>", datastream: 'thumbnail'} }
|
16
|
+
makes_derivatives_of :content, when: :mime_type, is: 'application/pdf',
|
17
|
+
derivatives: { :thumbnail => {size: "338x493", datastream: 'thumbnail'} }
|
18
|
+
makes_derivatives_of :content, when: :mime_type, is_one_of: ['video/mpeg', 'video/avi'],
|
19
|
+
derivatives: { :webm => {format: "webm", datastream: 'webm'}, :mp4 => {format: "mp4", datastream: 'mp4'} }, processors: :video
|
20
|
+
makes_derivatives_of :content, when: :mime_type, is_one_of: ['audio/wav', 'audio/mpeg'],
|
21
|
+
derivatives: { :mp3 => {format: 'mp3', datastream: 'mp3'}, :ogg => {format: 'ogg', datastream: 'ogg'} }, processors: :audio
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
And you add some content to it:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
obj = GenericFile.new
|
29
|
+
obj.content.content = File.open(...)
|
30
|
+
obj.mime_type = 'image/tiff'
|
31
|
+
obj.save
|
32
|
+
```
|
33
|
+
|
34
|
+
Then when you call `obj.create_derivatives` a new datastream, called 'thumbnail' will have been created, with a downsized image in it.
|
35
|
+
|
36
|
+
We recommend you run `obj.create_derivatives` in a background worker, because some derivative creation (especially videos) can take a long time.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/hydra/derivatives.rb
CHANGED
@@ -74,13 +74,14 @@ module Hydra
|
|
74
74
|
class TransformationDirective
|
75
75
|
attr_accessor :differentiator, :selector, :derivatives, :processors
|
76
76
|
# @param [Hash] args the options
|
77
|
-
# @option args [Symbol] :
|
78
|
-
# @option args [String, Array] :
|
77
|
+
# @option args [Symbol] :when the method that holds the differentiator column
|
78
|
+
# @option args [String, Array] :is_one_of activates this set of derivatives when the the differentiator column is includes one of these.
|
79
|
+
# @option args [String, Array] :is alias for :is_one_of
|
79
80
|
# @option args [Hash] :derivatives the derivatives to be produced
|
80
81
|
# @option args [Symbol, Array] :processors the processors to run to produce the derivatives
|
81
82
|
def initialize(args)
|
82
|
-
self.differentiator = args[:
|
83
|
-
self.selector = args[:
|
83
|
+
self.differentiator = args[:when]
|
84
|
+
self.selector = args[:is_one_of] || args[:is]
|
84
85
|
self.derivatives = args[:derivatives]
|
85
86
|
self.processors = args[:processors]
|
86
87
|
end
|
@@ -93,15 +94,16 @@ module Hydra
|
|
93
94
|
module ClassMethods
|
94
95
|
# @param [Symbol, String] datastream the datastream to operate on
|
95
96
|
# @param [Hash] args the options
|
96
|
-
# @option args [Symbol] :
|
97
|
-
# @option args [String, Array] :
|
97
|
+
# @option args [Symbol] :when the method that holds the differentiator column
|
98
|
+
# @option args [String, Array] :is_one_of activates this set of derivatives when the the differentiator column is includes one of these.
|
99
|
+
# @option args [String, Array] :is alias for :is_one_of
|
98
100
|
# @option args [Hash] :derivatives the derivatives to be produced
|
99
101
|
# @option args [Symbol, Array] :processors the processors to run to produce the derivatives
|
100
102
|
# @example
|
101
|
-
# makes_derivatives_of :content,
|
103
|
+
# makes_derivatives_of :content, when: :mime_type, is: 'text/pdf',
|
102
104
|
# derivatives: { :text => { :quality => :better }, processors: [:ocr]}
|
103
105
|
#
|
104
|
-
# makes_derivatives_of :content,
|
106
|
+
# makes_derivatives_of :content, when: :mime_type, is_one_of: ['image/png', 'image/jpg'],
|
105
107
|
# derivatives: { :medium => "300x300>", :thumb => "100x100>" }
|
106
108
|
def makes_derivatives_of(datastream, args = {})
|
107
109
|
self.transformation_scheme ||= {}
|
@@ -14,9 +14,11 @@ module Hydra
|
|
14
14
|
|
15
15
|
def process
|
16
16
|
directives.each do |name, args|
|
17
|
-
|
17
|
+
format = args[:format]
|
18
|
+
raise ArgumentError, "You must provide the :format you want to transcode into. You provided #{args}" unless format
|
18
19
|
# TODO if the source is in the correct format, we could just copy it and skip transcoding.
|
19
|
-
|
20
|
+
output_datastream_name = args[:datastream] || output_datastream_id(name)
|
21
|
+
encode_datastream(output_datastream_name, format, new_mime_type(format), options_for(format))
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -14,10 +14,10 @@ describe "Transcoder" do
|
|
14
14
|
delegate :mime_type, :to => :characterization, :unique => true
|
15
15
|
has_file_datastream 'content', type: ContentDatastream
|
16
16
|
|
17
|
-
makes_derivatives_of :content,
|
17
|
+
makes_derivatives_of :content, when: :mime_type, is_one_of: 'application/pdf',
|
18
18
|
derivatives: { :thumb => "100x100>" }
|
19
19
|
|
20
|
-
makes_derivatives_of :content,
|
20
|
+
makes_derivatives_of :content, when: :mime_type, is_one_of: 'audio/wav',
|
21
21
|
derivatives: { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processors: :audio
|
22
22
|
|
23
23
|
# -g 30 enforces keyframe generation every second (30fps)
|
@@ -25,10 +25,10 @@ describe "Transcoder" do
|
|
25
25
|
# -acodec is the audio codec
|
26
26
|
size_attributes = "-s 320x240"
|
27
27
|
audio_attributes = "-ac 2 -ab 96k -ar 44100"
|
28
|
-
makes_derivatives_of :content,
|
28
|
+
makes_derivatives_of :content, when: :mime_type, is: 'video/avi',
|
29
29
|
derivatives: { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processors: :video
|
30
30
|
|
31
|
-
makes_derivatives_of :content,
|
31
|
+
makes_derivatives_of :content, when: :mime_type, is_one_of: ['image/png', 'image/jpg'],
|
32
32
|
derivatives: { :medium => "300x300>", :thumb => "100x100>" }
|
33
33
|
|
34
34
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::Derivatives::Video do
|
4
|
+
describe "when arguments are passed as a hash" do
|
5
|
+
describe "and datastream is provided as an argument" do
|
6
|
+
let(:directives) {{ :thumb => {format: "webm", datastream: 'thumbnail'} }}
|
7
|
+
subject { Hydra::Derivatives::Video.new(double(:obj), 'content', directives)}
|
8
|
+
it "should create a datastream with the specified name" do
|
9
|
+
subject.should_receive(:encode_datastream).with("thumbnail", "webm", 'video/webm', "-s 320x240 -g 30 -b:v 345k -acodec libvorbis -ac 2 -ab 96k -ar 44100")
|
10
|
+
subject.process
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "and datastream is not provided as an argument" do
|
16
|
+
let(:directives) {{ :thumb => {format: "webm"} }}
|
17
|
+
subject { Hydra::Derivatives::Video.new(double(:obj), 'content', directives)}
|
18
|
+
it "should create a datastream and infer the name" do
|
19
|
+
subject.should_receive(:encode_datastream).with("content_thumb", "webm", 'video/webm', "-s 320x240 -g 30 -b:v 345k -acodec libvorbis -ac 2 -ab 96k -ar 44100")
|
20
|
+
subject.process
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
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: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- spec/spec_helper.rb
|
147
147
|
- spec/units/image_spec.rb
|
148
148
|
- spec/units/transcoding_spec.rb
|
149
|
+
- spec/units/video_spec.rb
|
149
150
|
homepage: https://github.com/projecthydra/hydra-derivatives
|
150
151
|
licenses:
|
151
152
|
- APACHE2
|
@@ -178,3 +179,5 @@ test_files:
|
|
178
179
|
- spec/spec_helper.rb
|
179
180
|
- spec/units/image_spec.rb
|
180
181
|
- spec/units/transcoding_spec.rb
|
182
|
+
- spec/units/video_spec.rb
|
183
|
+
has_rdoc:
|