hydra-derivatives 0.1.1 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/README.md +13 -13
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/hydra-derivatives.gemspec +3 -1
- data/lib/hydra/derivatives/config.rb +29 -29
- data/lib/hydra/derivatives/document.rb +9 -6
- data/lib/hydra/derivatives/extract_metadata.rb +8 -4
- data/lib/hydra/derivatives/image.rb +13 -13
- data/lib/hydra/derivatives/jpeg2k_image.rb +21 -21
- data/lib/hydra/derivatives/logger.rb +1 -1
- data/lib/hydra/derivatives/processor.rb +10 -10
- data/lib/hydra/derivatives/shell_based_processor.rb +5 -5
- data/lib/hydra/derivatives.rb +22 -14
- data/spec/lib/hydra/derivatives/extract_metadata_spec.rb +8 -6
- data/spec/spec_helper.rb +5 -0
- data/spec/units/extract_spec.rb +2 -2
- data/spec/units/image_spec.rb +14 -11
- data/spec/units/transcoding_spec.rb +96 -89
- data/spec/units/video_spec.rb +3 -3
- metadata +37 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80810fa0b2485899158d367b925840c7919c70ae
|
4
|
+
data.tar.gz: 0711a06da2a40f7fe71450ec7d7efc94c79a3019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ded4fc1774ddd3d2088a179c8ca545783a338580533e5051b824497de769ea1ec102956b6232fa635478ca8112401fbe82620dad35ce1b75e8a3becf759fee4
|
7
|
+
data.tar.gz: 729a4e5397096b15f4b7f9c4ce28dc00780471ea2ad7b99010fa162d21fbfbec5aa28bacdb40d72ed1795c8453871eb134acb0958a9f71f56bcd63140a68b817
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -7,22 +7,22 @@ If you have an ActiveFedora class like this:
|
|
7
7
|
class GenericFile < ActiveFedora::Base
|
8
8
|
include Hydra::Derivatives
|
9
9
|
|
10
|
-
|
10
|
+
contains 'content'
|
11
11
|
attr_accessor :mime_type
|
12
12
|
|
13
13
|
# Use a block to declare which derivatives you want to generate
|
14
14
|
makes_derivatives do |obj|
|
15
15
|
case obj.mime_type
|
16
16
|
when 'application/pdf'
|
17
|
-
obj.
|
17
|
+
obj.transform_file :content, { :thumb => "100x100>" }
|
18
18
|
when 'audio/wav'
|
19
|
-
obj.
|
19
|
+
obj.transform_file :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
|
20
20
|
when 'video/avi'
|
21
|
-
obj.
|
21
|
+
obj.transform_file :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
|
22
22
|
when 'image/png', 'image/jpg'
|
23
|
-
obj.
|
23
|
+
obj.transform_file :content, { :medium => "300x300>", :thumb => "100x100>" }
|
24
24
|
when 'image/tiff'
|
25
|
-
obj.
|
25
|
+
obj.transform_file :content, { :service => { resize: "3600x3600>" } }, processor: 'jpeg2k_image'
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -34,7 +34,7 @@ Or a class like this:
|
|
34
34
|
class GenericFile < ActiveFedora::Base
|
35
35
|
include Hydra::Derivatives
|
36
36
|
|
37
|
-
|
37
|
+
contains 'content'
|
38
38
|
attr_accessor :mime_type
|
39
39
|
|
40
40
|
# Use a callback method to declare which derivatives you want
|
@@ -43,15 +43,15 @@ Or a class like this:
|
|
43
43
|
def generate_derivatives
|
44
44
|
case mime_type
|
45
45
|
when 'application/pdf'
|
46
|
-
|
46
|
+
transform_file :content, { :thumb => "100x100>" }
|
47
47
|
when 'audio/wav'
|
48
|
-
|
48
|
+
transform_file :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
|
49
49
|
when 'video/avi'
|
50
|
-
|
50
|
+
transform_file :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
|
51
51
|
when 'image/png', 'image/jpg'
|
52
|
-
|
52
|
+
transform_file :content, { :medium => "300x300>", :thumb => {size: "100x100>", datastream: 'thumbnail'} }
|
53
53
|
when 'image/tiff'
|
54
|
-
|
54
|
+
transform_file :content, { :service => { recipe: :default } }, processor: 'jpeg2k_image'
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -66,7 +66,7 @@ And you add some content to it:
|
|
66
66
|
obj.save
|
67
67
|
```
|
68
68
|
|
69
|
-
Then when you call `obj.create_derivatives` two new
|
69
|
+
Then when you call `obj.create_derivatives` two new files, 'thumbnail' and 'content_medium', will have been created with downsized images in them.
|
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
|
|
data/Rakefile
CHANGED
@@ -4,6 +4,9 @@ require "bundler/gem_tasks"
|
|
4
4
|
|
5
5
|
APP_ROOT="." # for jettywrapper
|
6
6
|
require 'jettywrapper'
|
7
|
+
JETTY_ZIP_BASENAME = 'fedora-4/master'
|
8
|
+
Jettywrapper.url = "https://github.com/projecthydra/hydra-jetty/archive/#{JETTY_ZIP_BASENAME}.zip"
|
9
|
+
|
7
10
|
# Dir.glob('tasks/*.rake').each { |r| import r }
|
8
11
|
|
9
12
|
require 'rspec/core/rake_task'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0.beta1
|
data/hydra-derivatives.gemspec
CHANGED
@@ -22,9 +22,11 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "jettywrapper"
|
23
23
|
spec.add_development_dependency "rspec"
|
24
24
|
|
25
|
-
spec.add_dependency 'active-fedora'
|
25
|
+
spec.add_dependency 'active-fedora', '~> 9.0.0.beta3'
|
26
26
|
spec.add_dependency 'hydra-file_characterization'
|
27
27
|
spec.add_dependency 'mini_magick'
|
28
28
|
spec.add_dependency 'activesupport', '>= 3.2.13', '< 5.0'
|
29
|
+
spec.add_dependency 'mime-types'
|
30
|
+
spec.add_dependency 'deprecation'
|
29
31
|
end
|
30
32
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Hydra
|
2
2
|
module Derivatives
|
3
3
|
class Config
|
4
|
-
attr_writer :ffmpeg_path, :libreoffice_path, :temp_file_base, :fits_path,
|
4
|
+
attr_writer :ffmpeg_path, :libreoffice_path, :temp_file_base, :fits_path,
|
5
5
|
:enable_ffmpeg, :kdu_compress_path, :kdu_compress_recipes
|
6
6
|
def ffmpeg_path
|
7
7
|
@ffmpeg_path ||= 'ffmpeg'
|
@@ -29,34 +29,34 @@ module Hydra
|
|
29
29
|
|
30
30
|
def kdu_compress_recipes
|
31
31
|
@kdu_compress_recipes ||= {
|
32
|
-
default_color: %Q{-rate 2.4,1.48331273,.91673033,.56657224,.35016049,.21641118,.13374944,.08266171
|
33
|
-
-jp2_space sRGB
|
34
|
-
-double_buffering 10
|
35
|
-
-num_threads 4
|
36
|
-
-no_weights
|
37
|
-
Clevels=6
|
38
|
-
Clayers=8
|
39
|
-
Cblk
|
40
|
-
Cuse_sop=yes
|
41
|
-
Cuse_eph=yes
|
42
|
-
Corder=RPCL
|
43
|
-
ORGgen_plt=yes
|
44
|
-
ORGtparts=R
|
45
|
-
Stiles
|
46
|
-
default_grey: %Q{-rate 2.4,1.48331273,.91673033,.56657224,.35016049,.21641118,.13374944,.08266171
|
47
|
-
-jp2_space sLUM
|
48
|
-
-double_buffering 10
|
49
|
-
-num_threads 4
|
50
|
-
-no_weights
|
51
|
-
Clevels=6
|
52
|
-
Clayers=8
|
53
|
-
Cblk
|
54
|
-
Cuse_sop=yes
|
55
|
-
Cuse_eph=yes
|
56
|
-
Corder=RPCL
|
57
|
-
ORGgen_plt=yes
|
58
|
-
ORGtparts=R
|
59
|
-
Stiles
|
32
|
+
default_color: %Q{-rate 2.4,1.48331273,.91673033,.56657224,.35016049,.21641118,.13374944,.08266171
|
33
|
+
-jp2_space sRGB
|
34
|
+
-double_buffering 10
|
35
|
+
-num_threads 4
|
36
|
+
-no_weights
|
37
|
+
Clevels=6
|
38
|
+
Clayers=8
|
39
|
+
"Cblk={64,64}"
|
40
|
+
Cuse_sop=yes
|
41
|
+
Cuse_eph=yes
|
42
|
+
Corder=RPCL
|
43
|
+
ORGgen_plt=yes
|
44
|
+
ORGtparts=R
|
45
|
+
"Stiles={1024,1024}" }.gsub(/\s+/, " ").strip,
|
46
|
+
default_grey: %Q{-rate 2.4,1.48331273,.91673033,.56657224,.35016049,.21641118,.13374944,.08266171
|
47
|
+
-jp2_space sLUM
|
48
|
+
-double_buffering 10
|
49
|
+
-num_threads 4
|
50
|
+
-no_weights
|
51
|
+
Clevels=6
|
52
|
+
Clayers=8
|
53
|
+
"Cblk={64,64}"
|
54
|
+
Cuse_sop=yes
|
55
|
+
Cuse_eph=yes
|
56
|
+
Corder=RPCL
|
57
|
+
ORGgen_plt=yes
|
58
|
+
ORGtparts=R
|
59
|
+
"Stiles={1024,1024}" }.gsub(/\s+/, " ").strip
|
60
60
|
}
|
61
61
|
end
|
62
62
|
|
@@ -9,26 +9,29 @@ module Hydra
|
|
9
9
|
execute "#{Hydra::Derivatives.libreoffice_path} --invisible --headless --convert-to #{format} --outdir #{outdir} #{path}"
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
output_file = Dir::Tmpname.create(["#{object.id}-content.", ".#{file_suffix}"], Hydra::Derivatives.temp_file_base){}
|
12
|
+
def encode_file(dest_dsid, file_suffix, mime_type, options = '')
|
14
13
|
new_output = ''
|
15
|
-
|
14
|
+
source_file.to_tempfile do |f|
|
16
15
|
if mime_type == 'image/jpeg'
|
17
16
|
temp_file = File.join(Hydra::Derivatives.temp_file_base, [File.basename(f.path).sub(File.extname(f.path), ''), 'pdf'].join('.'))
|
18
17
|
new_output = File.join(Hydra::Derivatives.temp_file_base, [File.basename(temp_file).sub(File.extname(temp_file), ''), file_suffix].join('.'))
|
19
18
|
self.class.encode(f.path, options, temp_file)
|
20
|
-
self.class.encode(temp_file, options, output_file)
|
19
|
+
self.class.encode(temp_file, options, output_file(file_suffix))
|
21
20
|
File.unlink(temp_file)
|
22
21
|
else
|
23
|
-
self.class.encode(f.path, options, output_file)
|
22
|
+
self.class.encode(f.path, options, output_file(file_suffix))
|
24
23
|
new_output = File.join(Hydra::Derivatives.temp_file_base, [File.basename(f.path).sub(File.extname(f.path), ''), file_suffix].join('.'))
|
25
24
|
end
|
26
25
|
end
|
27
26
|
out_file = File.open(new_output, "rb")
|
28
|
-
object.add_file_datastream(out_file.read, dsid: dest_dsid,
|
27
|
+
object.add_file_datastream(out_file.read, dsid: dest_dsid, mime_type: mime_type)
|
29
28
|
File.unlink(out_file)
|
30
29
|
end
|
31
30
|
|
31
|
+
def output_file(file_suffix)
|
32
|
+
Dir::Tmpname.create(["#{object.id.gsub('/', '_')}-content.", ".#{file_suffix}"], Hydra::Derivatives.temp_file_base){}
|
33
|
+
end
|
34
|
+
|
32
35
|
def new_mime_type(format)
|
33
36
|
case format
|
34
37
|
when 'pdf'
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'hydra-file_characterization'
|
2
|
+
require 'mime/types'
|
3
|
+
|
2
4
|
module Hydra
|
3
5
|
module Derivatives
|
4
6
|
module ExtractMetadata
|
@@ -29,10 +31,12 @@ module Hydra
|
|
29
31
|
protected
|
30
32
|
|
31
33
|
def filename_for_characterization
|
32
|
-
|
33
|
-
Logger.warn "Unable to find a registered mime type for #{
|
34
|
-
extension =
|
35
|
-
|
34
|
+
registered_mime_type = MIME::Types[mime_type].first
|
35
|
+
Logger.warn "Unable to find a registered mime type for #{mime_type.inspect} on #{uri}" unless registered_mime_type
|
36
|
+
extension = registered_mime_type ? ".#{registered_mime_type.extensions.first}" : ''
|
37
|
+
version_id = 1 # TODO fixme
|
38
|
+
m = /\/([^\/]*)$/.match(uri)
|
39
|
+
["#{m[1]}-#{version_id}", "#{extension}"]
|
36
40
|
end
|
37
41
|
|
38
42
|
end
|
@@ -3,11 +3,11 @@ module Hydra
|
|
3
3
|
module Derivatives
|
4
4
|
class Image < Processor
|
5
5
|
def process
|
6
|
-
directives.each do |name, args|
|
6
|
+
directives.each do |name, args|
|
7
7
|
opts = args.kind_of?(Hash) ? args : {size: args}
|
8
8
|
format = opts.fetch(:format, 'png')
|
9
|
-
|
10
|
-
create_resized_image(
|
9
|
+
output_file_name = opts.fetch(:datastream, output_file_id(name))
|
10
|
+
create_resized_image(output_file(output_file_name), opts[:size], format)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -17,32 +17,32 @@ module Hydra
|
|
17
17
|
MIME::Types.type_for(format).first.to_s
|
18
18
|
end
|
19
19
|
|
20
|
-
def create_resized_image(
|
21
|
-
create_image(
|
20
|
+
def create_resized_image(output_file, size, format, quality=nil)
|
21
|
+
create_image(output_file, format, quality) do |xfrm|
|
22
22
|
xfrm.resize(size) if size.present?
|
23
23
|
end
|
24
|
-
|
24
|
+
output_file.mime_type = new_mime_type(format)
|
25
25
|
end
|
26
26
|
|
27
|
-
def create_image(
|
27
|
+
def create_image(output_file, format, quality=nil)
|
28
28
|
xfrm = load_image_transformer
|
29
29
|
yield(xfrm) if block_given?
|
30
30
|
xfrm.format(format)
|
31
31
|
xfrm.quality(quality.to_s) if quality
|
32
|
-
write_image(
|
32
|
+
write_image(output_file, xfrm)
|
33
33
|
end
|
34
34
|
|
35
|
-
def write_image(
|
35
|
+
def write_image(output_file, xfrm)
|
36
36
|
stream = StringIO.new
|
37
37
|
xfrm.write(stream)
|
38
38
|
stream.rewind
|
39
|
-
|
39
|
+
output_file.content = stream
|
40
40
|
end
|
41
41
|
|
42
|
-
# Override this method if you want a different transformer, or need to load the
|
43
|
-
# raw image from a different source (e.g. external
|
42
|
+
# Override this method if you want a different transformer, or need to load the
|
43
|
+
# raw image from a different source (e.g. external file)
|
44
44
|
def load_image_transformer
|
45
|
-
MiniMagick::Image.read(
|
45
|
+
MiniMagick::Image.read(source_file.content)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -4,11 +4,11 @@ require 'nokogiri'
|
|
4
4
|
|
5
5
|
module Hydra
|
6
6
|
module Derivatives
|
7
|
-
class Jpeg2kImage < Processor
|
7
|
+
class Jpeg2kImage < Processor
|
8
8
|
include ShellBasedProcessor
|
9
9
|
|
10
10
|
def process
|
11
|
-
image = MiniMagick::Image.read(
|
11
|
+
image = MiniMagick::Image.read(source_file.content)
|
12
12
|
quality = image['%[channels]'] == 'gray' ? 'gray' : 'color'
|
13
13
|
directives.each do |name, args|
|
14
14
|
long_dim = self.class.long_dim(image)
|
@@ -19,26 +19,26 @@ module Hydra
|
|
19
19
|
end
|
20
20
|
image.write file_path
|
21
21
|
recipe = self.class.kdu_compress_recipe(args, quality, long_dim)
|
22
|
-
|
23
|
-
|
22
|
+
output_file_name = args[:datastream] || output_file_id(name)
|
23
|
+
encode_file(output_file_name, recipe, file_path: file_path)
|
24
24
|
File.unlink(file_path) unless file_path.nil?
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def encode_file(dest_dsid, recipe, opts={})
|
29
29
|
output_file = self.class.tmp_file('.jp2')
|
30
30
|
if opts[:file_path]
|
31
31
|
self.class.encode(opts[:file_path], recipe, output_file)
|
32
32
|
else
|
33
|
-
|
33
|
+
source_file.to_tempfile do |f|
|
34
34
|
self.class.encode(f.path, recipe, output_file)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
out_file = File.open(output_file, "rb")
|
38
|
-
object.add_file_datastream(out_file.read, dsid: dest_dsid,
|
38
|
+
object.add_file_datastream(out_file.read, dsid: dest_dsid, mime_type: 'image/jp2')
|
39
39
|
File.unlink(output_file)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
protected
|
43
43
|
def preprocess(image, opts={})
|
44
44
|
# resize: <geometry>, to_srgb: <bool>, src_quality: 'color'|'gray'
|
@@ -57,7 +57,7 @@ module Hydra
|
|
57
57
|
def self.srgb_profile_path
|
58
58
|
File.join [
|
59
59
|
File.expand_path('../../../', __FILE__),
|
60
|
-
'color_profiles',
|
60
|
+
'color_profiles',
|
61
61
|
'sRGB_IEC61966-2-1_no_black_scaling.icc'
|
62
62
|
]
|
63
63
|
end
|
@@ -90,21 +90,21 @@ module Hydra
|
|
90
90
|
levels_arg = args.fetch(:levels, Hydra::Derivatives::Jpeg2kImage.level_count_for_size(long_dim))
|
91
91
|
rates_arg = Hydra::Derivatives::Jpeg2kImage.layer_rates(args.fetch(:layers, 8), args.fetch(:compression, 10))
|
92
92
|
tile_size = args.fetch(:tile_size, 1024)
|
93
|
-
tiles_arg = "
|
93
|
+
tiles_arg = "#{tile_size},#{tile_size}"
|
94
94
|
jp2_space_arg = quality == 'gray' ? 'sLUM' : 'sRGB'
|
95
95
|
|
96
|
-
%Q{-rate #{rates_arg}
|
96
|
+
%Q{-rate #{rates_arg}
|
97
97
|
-jp2_space #{jp2_space_arg}
|
98
|
-
-double_buffering 10
|
99
|
-
-num_threads 4
|
100
|
-
-no_weights
|
101
|
-
Clevels=#{levels_arg}
|
102
|
-
Stiles
|
103
|
-
Cblk
|
104
|
-
Cuse_sop=yes
|
105
|
-
Cuse_eph=yes
|
106
|
-
Corder=RPCL
|
107
|
-
ORGgen_plt=yes
|
98
|
+
-double_buffering 10
|
99
|
+
-num_threads 4
|
100
|
+
-no_weights
|
101
|
+
Clevels=#{levels_arg}
|
102
|
+
"Stiles={#{tiles_arg}}"
|
103
|
+
"Cblk={64,64}"
|
104
|
+
Cuse_sop=yes
|
105
|
+
Cuse_eph=yes
|
106
|
+
Corder=RPCL
|
107
|
+
ORGgen_plt=yes
|
108
108
|
ORGtparts=R }.gsub(/\s+/, " ").strip
|
109
109
|
end
|
110
110
|
|
@@ -13,23 +13,23 @@ module Hydra
|
|
13
13
|
raise "Processor is an abstract class. Implement `process' on #{self.class.name}"
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def output_file_id(name)
|
17
17
|
[source_name, name].join('_')
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
# first, check for a defined
|
22
|
-
|
23
|
-
object.
|
20
|
+
def output_file(path)
|
21
|
+
# first, check for a defined file
|
22
|
+
output_file = if object.attached_files[path]
|
23
|
+
object.attached_files[path]
|
24
24
|
else
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
ActiveFedora::File.new("#{object.uri}/#{path}").tap do |file|
|
26
|
+
object.attach_file(file, path)
|
27
|
+
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
object.
|
31
|
+
def source_file
|
32
|
+
object.attached_files[source_name.to_s]
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -17,8 +17,8 @@ module Hydra
|
|
17
17
|
format = args[:format]
|
18
18
|
raise ArgumentError, "You must provide the :format you want to transcode into. You provided #{args}" unless format
|
19
19
|
# TODO if the source is in the correct format, we could just copy it and skip transcoding.
|
20
|
-
|
21
|
-
|
20
|
+
output_file_name = args[:datastream] || output_file_id(name)
|
21
|
+
encode_file(output_file_name, format, new_mime_type(format), options_for(format))
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -26,14 +26,14 @@ module Hydra
|
|
26
26
|
def options_for(format)
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def encode_file(dest_dsid, file_suffix, mime_type, options = '')
|
30
30
|
out_file = nil
|
31
31
|
output_file = Dir::Tmpname.create(['sufia', ".#{file_suffix}"], Hydra::Derivatives.temp_file_base){}
|
32
|
-
|
32
|
+
source_file.to_tempfile do |f|
|
33
33
|
self.class.encode(f.path, options, output_file)
|
34
34
|
end
|
35
35
|
out_file = File.open(output_file, "rb")
|
36
|
-
object.add_file_datastream(out_file.read, :
|
36
|
+
object.add_file_datastream(out_file.read, dsid: dest_dsid, mime_type: mime_type)
|
37
37
|
File.unlink(output_file)
|
38
38
|
end
|
39
39
|
|
data/lib/hydra/derivatives.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'active_fedora'
|
2
2
|
require 'hydra/derivatives/railtie' if defined?(Rails)
|
3
|
-
|
3
|
+
require 'deprecation'
|
4
4
|
module Hydra
|
5
5
|
module Derivatives
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
extend ActiveSupport::Autoload
|
8
|
+
extend Deprecation
|
9
|
+
self.deprecation_horizon = "hydra-derivatives 1.0"
|
8
10
|
|
9
11
|
autoload :Processor
|
10
12
|
autoload :Image
|
@@ -58,28 +60,34 @@ module Hydra
|
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
61
|
-
# Create derivatives from a
|
62
|
-
# @param
|
63
|
+
# Create derivatives from a file according to transformation directives
|
64
|
+
# @param file_name
|
63
65
|
# @param [Hash] transform_directives - each key corresponds to a desired derivative. Associated values vary according to processor being used.
|
64
66
|
# @param [Hash] opts for specifying things like choice of :processor (processor defaults to :image)
|
65
67
|
#
|
66
68
|
# @example This will create content_thumb
|
67
|
-
#
|
69
|
+
# transform_file :content, { :thumb => "100x100>" }
|
68
70
|
#
|
69
|
-
# @example Specify the dsid for the output
|
70
|
-
#
|
71
|
+
# @example Specify the dsid for the output file
|
72
|
+
# transform_file :content, { :thumb => {size: "200x300>", datastream: 'thumbnail'} }
|
71
73
|
#
|
72
74
|
# @example Create multiple derivatives with one set of directives. This will create content_thumb and content_medium
|
73
|
-
#
|
75
|
+
# transform_file :content, { :medium => "300x300>", :thumb => "100x100>" }
|
74
76
|
#
|
75
77
|
# @example Specify which processor you want to use (defaults to :image)
|
76
|
-
#
|
77
|
-
#
|
78
|
+
# transform_file :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
|
79
|
+
# transform_file :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
|
78
80
|
#
|
79
|
-
def
|
81
|
+
def transform_file(file_name, transform_directives, opts={})
|
80
82
|
processor = opts[:processor] ? opts[:processor] : :image
|
81
|
-
"Hydra::Derivatives::#{processor.to_s.classify}".constantize.new(self,
|
83
|
+
"Hydra::Derivatives::#{processor.to_s.classify}".constantize.new(self, file_name, transform_directives).process
|
84
|
+
end
|
85
|
+
|
86
|
+
def transform_datastream(file_name, transform_directives, opts={})
|
87
|
+
transform_file(file_name, transform_directives, opts={})
|
82
88
|
end
|
89
|
+
deprecation_deprecate :transform_datastream
|
90
|
+
|
83
91
|
|
84
92
|
module ClassMethods
|
85
93
|
# Register transformation schemes for generating derivatives.
|
@@ -89,9 +97,9 @@ module Hydra
|
|
89
97
|
# makes_derivatives do |obj|
|
90
98
|
# case obj.mime_type
|
91
99
|
# when 'application/pdf'
|
92
|
-
# obj.
|
100
|
+
# obj.transform_file :content, { :thumb => "100x100>" }
|
93
101
|
# when 'audio/wav'
|
94
|
-
# obj.
|
102
|
+
# obj.transform_file :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
|
95
103
|
#
|
96
104
|
# @example Define transformation scheme using a callback method
|
97
105
|
# makes_derivatives :generate_image_derivatives
|
@@ -99,7 +107,7 @@ module Hydra
|
|
99
107
|
# def generate_image_derivatives
|
100
108
|
# case mime_type
|
101
109
|
# when 'image/png', 'image/jpg'
|
102
|
-
#
|
110
|
+
# transform_file :content, { :medium => "300x300>", :thumb => "100x100>" }
|
103
111
|
# end
|
104
112
|
# end
|
105
113
|
def makes_derivatives(*callback_method_names, &block)
|
@@ -2,19 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Hydra::Derivatives
|
4
4
|
describe ExtractMetadata do
|
5
|
-
let(:class_with_metadata_extraction)
|
5
|
+
let(:class_with_metadata_extraction) do
|
6
6
|
Class.new do
|
7
|
-
attr_reader :content, :
|
7
|
+
attr_reader :content, :mime_type, :uri
|
8
|
+
|
8
9
|
def initialize(options = {})
|
9
10
|
@content = options.fetch(:content, '')
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@dsVersionID = options.fetch(:dsVersionID, 'version-id-1')
|
11
|
+
@mime_uype = options.fetch(:mime_type, nil)
|
12
|
+
@uri = 'http://example.com/pid/123'
|
13
13
|
end
|
14
|
+
|
14
15
|
include Hydra::Derivatives::ExtractMetadata
|
15
16
|
def has_content?; content.present?; end
|
16
17
|
end
|
17
|
-
|
18
|
+
end
|
19
|
+
|
18
20
|
let(:initialization_options) { {content: 'abc', mime_type: 'text/plain'} }
|
19
21
|
subject { class_with_metadata_extraction.new(initialization_options) }
|
20
22
|
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,12 @@ require 'hydra/derivatives'
|
|
4
4
|
#Resque.inline = Rails.env.test?
|
5
5
|
require 'byebug' unless ENV['TRAVIS']
|
6
6
|
|
7
|
+
require 'active_fedora/cleaner'
|
8
|
+
ActiveFedora::Base.logger = Logger.new(STDOUT)
|
7
9
|
RSpec.configure do |config|
|
10
|
+
config.before(:each) do
|
11
|
+
ActiveFedora::Cleaner.clean!
|
12
|
+
end
|
8
13
|
end
|
9
14
|
|
10
15
|
$in_travis = !ENV['TRAVIS'].nil? && ENV['TRAVIS'] == 'true'
|
data/spec/units/extract_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
class ExtractThing < ActiveFedora::
|
3
|
+
class ExtractThing < ActiveFedora::File
|
4
4
|
include Hydra::Derivatives::ExtractMetadata
|
5
5
|
attr_accessor :pid
|
6
6
|
end
|
7
7
|
|
8
8
|
describe Hydra::Derivatives::ExtractMetadata, :unless => $in_travis do
|
9
|
-
let(:subject) { ExtractThing.new }
|
9
|
+
let(:subject) { ExtractThing.new('http://example.com/foo') }
|
10
10
|
let(:attachment) { File.open(File.expand_path('../../fixtures/world.png', __FILE__))}
|
11
11
|
|
12
12
|
describe "Image Content" do
|
data/spec/units/image_spec.rb
CHANGED
@@ -2,26 +2,29 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Hydra::Derivatives::Image do
|
4
4
|
let(:object) { ActiveFedora::Base.new }
|
5
|
+
let(:output_file) { double }
|
6
|
+
|
7
|
+
subject { Hydra::Derivatives::Image.new(object, 'content', directives)}
|
8
|
+
|
9
|
+
before { expect(subject).to receive(:output_file).with(file_name).and_return(output_file) }
|
10
|
+
|
5
11
|
describe "when arguments are passed as a string" do
|
6
|
-
let(:directives) {{ :
|
7
|
-
|
12
|
+
let(:directives) { { thumb: "100x100>" } }
|
13
|
+
let(:file_name) { 'content_thumb' }
|
8
14
|
|
9
15
|
it "should use the string as the size and the name is autogenerated" do
|
10
|
-
expect(subject).to receive(:create_resized_image).with(
|
11
|
-
expect(ds.dsid).to eq('content_thumb')
|
12
|
-
end
|
16
|
+
expect(subject).to receive(:create_resized_image).with(output_file, "100x100>", 'png')
|
13
17
|
subject.process
|
14
18
|
end
|
15
19
|
end
|
20
|
+
|
16
21
|
describe "when arguments are passed as a hash" do
|
17
|
-
let(:directives) {{ :
|
18
|
-
|
22
|
+
let(:directives) { { thumb: { size: "200x300>", datastream: file_name } } }
|
23
|
+
let(:file_name) { 'thumbnail' }
|
24
|
+
|
19
25
|
it "should use the specified size and name" do
|
20
|
-
expect(subject).to receive(:create_resized_image).with(
|
21
|
-
expect(ds.dsid).to eq('thumbnail')
|
22
|
-
end
|
26
|
+
expect(subject).to receive(:create_resized_image).with(output_file, "200x300>", 'png')
|
23
27
|
subject.process
|
24
|
-
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
@@ -2,39 +2,40 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Transcoder" do
|
4
4
|
before(:all) do
|
5
|
-
class ContentDatastream < ActiveFedora::
|
5
|
+
class ContentDatastream < ActiveFedora::File
|
6
6
|
include Hydra::Derivatives::ExtractMetadata
|
7
7
|
end
|
8
8
|
|
9
9
|
class GenericFile < ActiveFedora::Base
|
10
10
|
include Hydra::Derivatives
|
11
|
-
|
12
|
-
m.field "
|
11
|
+
contains 'characterization', class_name: 'ActiveFedora::SimpleDatastream' do |m|
|
12
|
+
m.field "mime_type_from_fits", :string
|
13
|
+
m.field "flag_as", :string
|
13
14
|
end
|
14
15
|
|
15
|
-
has_attributes :
|
16
|
-
|
16
|
+
has_attributes :mime_type_from_fits, :flag_as, datastream: :characterization, multiple: false
|
17
|
+
contains 'content', class_name: 'ContentDatastream'
|
17
18
|
|
18
19
|
makes_derivatives do |obj|
|
19
|
-
case obj.
|
20
|
+
case obj.mime_type_from_fits
|
20
21
|
when 'application/pdf'
|
21
|
-
obj.
|
22
|
+
obj.transform_file :content, { thumb: '100x100>' }
|
22
23
|
when 'audio/wav'
|
23
|
-
obj.
|
24
|
+
obj.transform_file :content, { mp3: { format: 'mp3' }, ogg: { format: 'ogg'} }, processor: :audio
|
24
25
|
when 'video/avi'
|
25
|
-
obj.
|
26
|
+
obj.transform_file :content, { mp4: { format: 'mp4' }, webm: { format: 'webm'}, thumbnail: { format: 'jpg', datastream: 'thumbnail' } }, processor: :video
|
26
27
|
when 'image/png', 'image/jpg'
|
27
|
-
obj.
|
28
|
+
obj.transform_file :content, { medium: "300x300>", thumb: "100x100>", access: { format: 'jpg', datastream: 'access'} }
|
28
29
|
when 'application/vnd.ms-powerpoint'
|
29
|
-
obj.
|
30
|
+
obj.transform_file :content, { preservation: { format: 'pptx'}, access: { format: 'pdf' }, thumbnail: { format: 'jpg' } }, processor: 'document'
|
30
31
|
when 'text/rtf'
|
31
|
-
obj.
|
32
|
+
obj.transform_file :content, { preservation: { format: 'odf' }, access: { format: 'pdf' }, thumbnail: { format: 'jpg' } }, processor: 'document'
|
32
33
|
when 'application/msword'
|
33
|
-
obj.
|
34
|
+
obj.transform_file :content, { access: { format: 'pdf' }, preservation: { format: 'docx' }, thumbnail: { format: 'jpg' } }, processor: 'document'
|
34
35
|
when 'application/vnd.ms-excel'
|
35
|
-
obj.
|
36
|
+
obj.transform_file :content, { access: { format: 'pdf' }, preservation: { format: 'xslx' }, thumbnail: { format: 'jpg' } }, processor: 'document'
|
36
37
|
when 'image/tiff'
|
37
|
-
obj.
|
38
|
+
obj.transform_file :content, {
|
38
39
|
resized: { recipe: :default, resize: "600x600>", datastream: 'resized' },
|
39
40
|
config_lookup: { recipe: :default, datastream: 'config_lookup' },
|
40
41
|
string_recipe: { recipe: '-quiet', datastream: 'string_recipe' },
|
@@ -47,15 +48,14 @@ describe "Transcoder" do
|
|
47
48
|
makes_derivatives :generate_special_derivatives
|
48
49
|
|
49
50
|
def generate_special_derivatives
|
50
|
-
if
|
51
|
-
|
51
|
+
if flag_as == "special" && mime_type_from_fits == 'image/png'
|
52
|
+
transform_file :content, { medium: { size: "200x300>", datastream: 'special_ds' } }
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
58
|
after(:all) do
|
58
|
-
GenericFile.destroy_all
|
59
59
|
Object.send(:remove_const, :GenericFile);
|
60
60
|
Object.send(:remove_const, :ContentDatastream);
|
61
61
|
end
|
@@ -63,162 +63,169 @@ describe "Transcoder" do
|
|
63
63
|
describe "with an attached image" do
|
64
64
|
let(:attachment) { File.open(File.expand_path('../../fixtures/world.png', __FILE__))}
|
65
65
|
let(:file) do
|
66
|
-
GenericFile.new(
|
66
|
+
GenericFile.new(mime_type_from_fits: 'image/png').tap do |f|
|
67
67
|
f.content.content = attachment
|
68
|
-
f.save
|
68
|
+
f.save!
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should transcode" do
|
73
|
-
expect(file.
|
73
|
+
expect(file.attached_files.key?('content_medium')).to be_falsey
|
74
74
|
file.create_derivatives
|
75
|
-
expect(file.
|
76
|
-
expect(file.
|
77
|
-
expect(file.
|
78
|
-
expect(file.
|
79
|
-
expect(file.
|
80
|
-
expect(file.
|
81
|
-
expect(file.
|
75
|
+
expect(file.attached_files['content_medium']).to have_content
|
76
|
+
expect(file.attached_files['content_medium'].mime_type).to eq('image/png')
|
77
|
+
expect(file.attached_files['content_thumb']).to have_content
|
78
|
+
expect(file.attached_files['content_thumb'].mime_type).to eq('image/png')
|
79
|
+
expect(file.attached_files['access']).to have_content
|
80
|
+
expect(file.attached_files['access'].mime_type).to eq('image/jpeg')
|
81
|
+
expect(file.attached_files.key?('content_text')).to be_falsey
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
describe "with an attached pdf" do
|
86
86
|
let(:attachment) { File.open(File.expand_path('../../fixtures/test.pdf', __FILE__))}
|
87
|
-
let(:file) { GenericFile.new(
|
87
|
+
let(:file) { GenericFile.new(mime_type_from_fits: 'application/pdf').tap { |t| t.content.content = attachment; t.save } }
|
88
88
|
|
89
89
|
it "should transcode" do
|
90
|
-
expect(file.
|
90
|
+
expect(file.attached_files.key?('content_thumb')).to be_falsey
|
91
91
|
file.create_derivatives
|
92
|
-
expect(file.
|
93
|
-
expect(file.
|
92
|
+
expect(file.attached_files['content_thumb']).to have_content
|
93
|
+
expect(file.attached_files['content_thumb'].mime_type).to eq('image/png')
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
describe "with an attached audio", unless: ENV['TRAVIS'] == 'true' do
|
98
98
|
let(:attachment) { File.open(File.expand_path('../../fixtures/piano_note.wav', __FILE__))}
|
99
|
-
let(:file) { GenericFile.new(
|
99
|
+
let(:file) { GenericFile.new(mime_type_from_fits: 'audio/wav').tap { |t| t.content.content = attachment; t.save } }
|
100
100
|
|
101
101
|
it "should transcode" do
|
102
102
|
file.create_derivatives
|
103
|
-
expect(file.
|
104
|
-
expect(file.
|
105
|
-
expect(file.
|
106
|
-
expect(file.
|
103
|
+
expect(file.attached_files['content_mp3']).to have_content
|
104
|
+
expect(file.attached_files['content_mp3'].mime_type).to eq('audio/mpeg')
|
105
|
+
expect(file.attached_files['content_ogg']).to have_content
|
106
|
+
expect(file.attached_files['content_ogg'].mime_type).to eq('audio/ogg')
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
describe "when the source datastrem has an unknown mime_type", unless: ENV['TRAVIS'] == 'true' do
|
111
111
|
let(:attachment) { File.open(File.expand_path('../../fixtures/piano_note.wav', __FILE__))}
|
112
|
-
let(:file)
|
112
|
+
let(:file) do
|
113
|
+
GenericFile.new(mime_type_from_fits: 'audio/wav').tap do |t|
|
114
|
+
t.content.content = attachment;
|
115
|
+
t.content.mime_type = 'audio/vnd.wav';
|
116
|
+
t.save
|
117
|
+
end
|
118
|
+
end
|
113
119
|
|
114
120
|
it "should transcode" do
|
121
|
+
allow_any_instance_of(::Logger).to receive(:warn)
|
115
122
|
file.create_derivatives
|
116
|
-
expect(file.
|
117
|
-
expect(file.
|
123
|
+
expect(file.attached_files['content_mp3']).to have_content
|
124
|
+
expect(file.attached_files['content_mp3'].mime_type).to eq('audio/mpeg')
|
118
125
|
end
|
119
126
|
end
|
120
127
|
|
121
128
|
describe "with an attached video", unless: ENV['TRAVIS'] == 'true' do
|
122
129
|
let(:attachment) { File.open(File.expand_path('../../fixtures/countdown.avi', __FILE__))}
|
123
|
-
let(:file) { GenericFile.new(
|
130
|
+
let(:file) { GenericFile.new(mime_type_from_fits: 'video/avi').tap { |t| t.content.content = attachment; t.save } }
|
124
131
|
|
125
132
|
it "should transcode" do
|
126
133
|
file.create_derivatives
|
127
|
-
expect(file.
|
128
|
-
expect(file.
|
129
|
-
expect(file.
|
130
|
-
expect(file.
|
131
|
-
expect(file.
|
132
|
-
expect(file.
|
134
|
+
expect(file.attached_files['content_mp4']).to have_content
|
135
|
+
expect(file.attached_files['content_mp4'].mime_type).to eq('video/mp4')
|
136
|
+
expect(file.attached_files['content_webm']).to have_content
|
137
|
+
expect(file.attached_files['content_webm'].mime_type).to eq('video/webm')
|
138
|
+
expect(file.attached_files['thumbnail']).to have_content
|
139
|
+
expect(file.attached_files['thumbnail'].mime_type).to eq('image/jpeg')
|
133
140
|
end
|
134
141
|
end
|
135
142
|
|
136
143
|
describe "using callback methods" do
|
137
144
|
let(:attachment) { File.open(File.expand_path('../../fixtures/world.png', __FILE__))}
|
138
|
-
let(:file) { GenericFile.new(
|
145
|
+
let(:file) { GenericFile.new(mime_type_from_fits: 'image/png', flag_as: "special").tap { |t| t.content.content = attachment; t.save } }
|
139
146
|
|
140
147
|
it "should transcode" do
|
141
|
-
expect(file.
|
148
|
+
expect(file.attached_files.key?('special_ds')).to be_falsey
|
142
149
|
file.create_derivatives
|
143
|
-
expect(file.
|
144
|
-
expect(file.
|
145
|
-
expect(file.
|
150
|
+
expect(file.attached_files['special_ds']).to have_content
|
151
|
+
expect(file.attached_files['special_ds'].mime_type).to eq('image/png')
|
152
|
+
expect(file.attached_files['special_ds']).to have_content
|
146
153
|
end
|
147
154
|
end
|
148
155
|
|
149
156
|
describe "with an attached Powerpoint", unless: ENV['TRAVIS'] == 'true' do
|
150
157
|
let(:attachment) { File.open(File.expand_path('../../fixtures/FlashPix.ppt', __FILE__))}
|
151
|
-
let(:file) { GenericFile.new(
|
158
|
+
let(:file) { GenericFile.new(mime_type_from_fits: 'application/vnd.ms-powerpoint').tap { |t| t.content.content = attachment; t.save } }
|
152
159
|
|
153
160
|
it "should transcode" do
|
154
161
|
file.create_derivatives
|
155
|
-
expect(file.
|
156
|
-
expect(file.
|
157
|
-
expect(file.
|
158
|
-
expect(file.
|
159
|
-
expect(file.
|
160
|
-
expect(file.
|
162
|
+
expect(file.attached_files['content_thumbnail']).to have_content
|
163
|
+
expect(file.attached_files['content_thumbnail'].mime_type).to eq('image/jpeg')
|
164
|
+
expect(file.attached_files['content_access']).to have_content
|
165
|
+
expect(file.attached_files['content_access'].mime_type).to eq('application/pdf')
|
166
|
+
expect(file.attached_files['content_preservation']).to have_content
|
167
|
+
expect(file.attached_files['content_preservation'].mime_type).to eq('application/vnd.openxmlformats-officedocument.presentationml.presentation')
|
161
168
|
end
|
162
169
|
end
|
163
170
|
|
164
171
|
describe "with an attached rich text format", unless: ENV['TRAVIS'] == 'true' do
|
165
172
|
let(:attachment) { File.open(File.expand_path('../../fixtures/sample.rtf', __FILE__))}
|
166
|
-
let(:file) { GenericFile.new(
|
173
|
+
let(:file) { GenericFile.new(mime_type_from_fits: 'text/rtf').tap { |t| t.content.content = attachment; t.save } }
|
167
174
|
|
168
175
|
it "should transcode" do
|
169
176
|
file.create_derivatives
|
170
|
-
expect(file.
|
171
|
-
expect(file.
|
172
|
-
expect(file.
|
173
|
-
expect(file.
|
174
|
-
expect(file.
|
175
|
-
expect(file.
|
177
|
+
expect(file.attached_files['content_thumbnail']).to have_content
|
178
|
+
expect(file.attached_files['content_thumbnail'].mime_type).to eq('image/jpeg')
|
179
|
+
expect(file.attached_files['content_access']).to have_content
|
180
|
+
expect(file.attached_files['content_access'].mime_type).to eq('application/pdf')
|
181
|
+
expect(file.attached_files['content_preservation']).to have_content
|
182
|
+
expect(file.attached_files['content_preservation'].mime_type).to eq('application/vnd.oasis.opendocument.text')
|
176
183
|
end
|
177
184
|
end
|
178
185
|
|
179
186
|
describe "with an attached word doc format", unless: ENV['TRAVIS'] == 'true' do
|
180
187
|
let(:attachment) { File.open(File.expand_path('../../fixtures/test.doc', __FILE__))}
|
181
|
-
let(:file) { GenericFile.new(
|
188
|
+
let(:file) { GenericFile.new(mime_type_from_fits: 'application/msword').tap { |t| t.content.content = attachment; t.save } }
|
182
189
|
|
183
190
|
it "should transcode" do
|
184
191
|
file.create_derivatives
|
185
|
-
expect(file.
|
186
|
-
expect(file.
|
187
|
-
expect(file.
|
188
|
-
expect(file.
|
189
|
-
expect(file.
|
190
|
-
expect(file.
|
192
|
+
expect(file.attached_files['content_thumbnail']).to have_content
|
193
|
+
expect(file.attached_files['content_thumbnail'].mime_type).to eq('image/jpeg')
|
194
|
+
expect(file.attached_files['content_access']).to have_content
|
195
|
+
expect(file.attached_files['content_access'].mime_type).to eq('application/pdf')
|
196
|
+
expect(file.attached_files['content_preservation']).to have_content
|
197
|
+
expect(file.attached_files['content_preservation'].mime_type).to eq('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
|
191
198
|
end
|
192
199
|
end
|
193
200
|
|
194
201
|
describe "with an attached excel format", unless: ENV['TRAVIS'] == 'true' do
|
195
202
|
let(:attachment) { File.open(File.expand_path('../../fixtures/test.xls', __FILE__))}
|
196
|
-
let(:file) { GenericFile.new(
|
203
|
+
let(:file) { GenericFile.new(mime_type_from_fits: 'application/vnd.ms-excel').tap { |t| t.content.content = attachment; t.save } }
|
197
204
|
|
198
205
|
it "should transcode" do
|
199
206
|
file.create_derivatives
|
200
|
-
expect(file.
|
201
|
-
expect(file.
|
202
|
-
expect(file.
|
203
|
-
expect(file.
|
204
|
-
expect(file.
|
205
|
-
expect(file.
|
207
|
+
expect(file.attached_files['content_thumbnail']).to have_content
|
208
|
+
expect(file.attached_files['content_thumbnail'].mime_type).to eq('image/jpeg')
|
209
|
+
expect(file.attached_files['content_access']).to have_content
|
210
|
+
expect(file.attached_files['content_access'].mime_type).to eq('application/pdf')
|
211
|
+
expect(file.attached_files['content_preservation']).to have_content
|
212
|
+
expect(file.attached_files['content_preservation'].mime_type).to eq('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
206
213
|
end
|
207
214
|
end
|
208
215
|
|
209
216
|
describe "with an attached tiff", unless: ENV['TRAVIS'] == 'true' do
|
210
217
|
let(:attachment) { File.open(File.expand_path('../../fixtures/test.tif', __FILE__))}
|
211
|
-
let(:file) { GenericFile.new(
|
218
|
+
let(:file) { GenericFile.new(mime_type_from_fits: 'image/tiff').tap { |t| t.content.content = attachment; t.save } }
|
212
219
|
it "should transcode" do
|
213
220
|
file.create_derivatives
|
214
|
-
expect(file.
|
215
|
-
expect(file.
|
216
|
-
expect(file.
|
217
|
-
expect(file.
|
218
|
-
expect(file.
|
219
|
-
expect(file.
|
220
|
-
expect(file.
|
221
|
-
expect(file.
|
221
|
+
expect(file.attached_files['content_diy']).to have_content
|
222
|
+
expect(file.attached_files['content_diy'].mime_type).to eq('image/jp2')
|
223
|
+
expect(file.attached_files['config_lookup']).to have_content
|
224
|
+
expect(file.attached_files['config_lookup'].mime_type).to eq('image/jp2')
|
225
|
+
expect(file.attached_files['resized']).to have_content
|
226
|
+
expect(file.attached_files['resized'].mime_type).to eq('image/jp2')
|
227
|
+
expect(file.attached_files['string_recipe']).to have_content
|
228
|
+
expect(file.attached_files['string_recipe'].mime_type).to eq('image/jp2')
|
222
229
|
end
|
223
230
|
end
|
224
231
|
end
|
data/spec/units/video_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Hydra::Derivatives::Video do
|
|
6
6
|
let(:directives) {{ :thumb => {format: "webm", datastream: 'thumbnail'} }}
|
7
7
|
subject { Hydra::Derivatives::Video.new(double(:obj), 'content', directives)}
|
8
8
|
it "should create a datastream with the specified name" do
|
9
|
-
expect(subject).to receive(:
|
9
|
+
expect(subject).to receive(:encode_file).with("thumbnail", "webm", 'video/webm', {Hydra::Derivatives::Ffmpeg::OUTPUT_OPTIONS =>"-s 320x240 -vcodec libvpx -acodec libvorbis -g 30 -b:v 345k -ac 2 -ab 96k -ar 44100", Hydra::Derivatives::Ffmpeg::INPUT_OPTIONS=>""})
|
10
10
|
subject.process
|
11
11
|
|
12
12
|
end
|
@@ -16,7 +16,7 @@ describe Hydra::Derivatives::Video do
|
|
16
16
|
let(:directives) {{ :thumb => {format: "webm"} }}
|
17
17
|
subject { Hydra::Derivatives::Video.new(double(:obj), 'content', directives)}
|
18
18
|
it "should create a datastream and infer the name" do
|
19
|
-
expect(subject).to receive(:
|
19
|
+
expect(subject).to receive(:encode_file).with("content_thumb", "webm", 'video/webm', {Hydra::Derivatives::Ffmpeg::OUTPUT_OPTIONS =>"-s 320x240 -vcodec libvpx -acodec libvorbis -g 30 -b:v 345k -ac 2 -ab 96k -ar 44100", Hydra::Derivatives::Ffmpeg::INPUT_OPTIONS=>""})
|
20
20
|
subject.process
|
21
21
|
|
22
22
|
end
|
@@ -26,7 +26,7 @@ describe Hydra::Derivatives::Video do
|
|
26
26
|
let(:directives) {{ :thumb => {:format => 'jpg' , datastream: 'thumbnail'} }}
|
27
27
|
subject { Hydra::Derivatives::Video.new(double(:obj), 'content', directives)}
|
28
28
|
it "should create a datastream and infer the name" do
|
29
|
-
expect(subject).to receive(:
|
29
|
+
expect(subject).to receive(:encode_file).with("thumbnail", "jpg", "image/jpeg", {:output_options=>"-s 320x240 -vcodec mjpeg -vframes 1 -an -f rawvideo", :input_options=>" -itsoffset -2"})
|
30
30
|
subject.process
|
31
31
|
|
32
32
|
end
|
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.
|
4
|
+
version: 1.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: active-fedora
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 9.0.0.beta3
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 9.0.0.beta3
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: hydra-file_characterization
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,6 +128,34 @@ dependencies:
|
|
128
128
|
- - "<"
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '5.0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: mime-types
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :runtime
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: deprecation
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :runtime
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
131
159
|
description: Derivative generation plugin for hydra
|
132
160
|
email:
|
133
161
|
- justin@curationexperts.com
|
@@ -201,9 +229,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
201
229
|
version: '0'
|
202
230
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
231
|
requirements:
|
204
|
-
- - "
|
232
|
+
- - ">"
|
205
233
|
- !ruby/object:Gem::Version
|
206
|
-
version:
|
234
|
+
version: 1.3.1
|
207
235
|
requirements: []
|
208
236
|
rubyforge_project:
|
209
237
|
rubygems_version: 2.2.2
|
@@ -234,3 +262,4 @@ test_files:
|
|
234
262
|
- spec/units/logger_spec.rb
|
235
263
|
- spec/units/transcoding_spec.rb
|
236
264
|
- spec/units/video_spec.rb
|
265
|
+
has_rdoc:
|