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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2760dd208eaff0215533b8885e35b115a78f1f4f
4
- data.tar.gz: cdeab3f70511982e5440ad348856c0f51f7bc626
3
+ metadata.gz: 74b15261c78629ff97614bc0090102ceed0c5fa7
4
+ data.tar.gz: 268d962f2ea5607db494c67455878d8cb8eab25d
5
5
  SHA512:
6
- metadata.gz: d8f7ec3e514d6d8b2e9aca347e1b2cff3e669e2d3de44bcdf24afd12790262f886d0b5ffb206c8ecea72b72d6151d850b0e7d65a2e5a092154c05b1eeff522f3
7
- data.tar.gz: 0d15fefd69e56e2afc29806d3201e1787f9e00d41ef973bce43b57ca23965247f379346138caf6570d797573a1521db656f2b1d38ef3c5f358726e0e0d88f5c5
6
+ metadata.gz: 5c7c0aa06d5fd7059e4bb9886d2f241ff5a7f00508941bb7650907464e0a3d59e1d884fddc61208068930a263c420e952534bb91c5931deadd896695ba8fd607
7
+ data.tar.gz: 5b5b6f7800798afe8dd7688638bdf88f643c6990d1cb0dad011d2f36c54238f2fc48e97f5fdaef6664d84daca620ed0b9ac9a0d8b2b0c0a51eeab843a7ecd84e
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  Gemfile.lock
2
2
  tmp/
3
3
  jetty/
4
+ pkg/
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
1
+ 0.0.2
@@ -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] :based_on the method that holds the differentiator column
78
- # @option args [String, Array] :when activates this set of derivatives when the the differentiator column is includes one of these.
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[:based_on]
83
- self.selector = args[:when]
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] :based_on the method that holds the differentiator column
97
- # @option args [String, Array] :when activates this set of derivatives when the the differentiator column is includes one of these.
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, based_on: :mime_type, when: 'text/pdf',
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, based_on: :mime_type, when: ['image/png', 'image/jpg'],
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
- raise ArgumentError, "You must provide the :format you want to transcode into. You provided #{args}" unless args[:format]
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
- encode_datastream(output_datastream_id(name), args[:format], new_mime_type(args[:format]), options_for(args[:format]))
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, based_on: :mime_type, when: 'application/pdf',
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, based_on: :mime_type, when: 'audio/wav',
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, based_on: :mime_type, when: 'video/avi',
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, based_on: :mime_type, when: ['image/png', 'image/jpg'],
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.1
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-23 00:00:00.000000000 Z
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: