hydra-derivatives 0.1.1 → 1.0.0.beta1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9915bdcf795eeb369e8d6d74c73ea28b6e123d7
4
- data.tar.gz: 8324701965b3eeaafab56b3d7c4c1865c7a63523
3
+ metadata.gz: 80810fa0b2485899158d367b925840c7919c70ae
4
+ data.tar.gz: 0711a06da2a40f7fe71450ec7d7efc94c79a3019
5
5
  SHA512:
6
- metadata.gz: 85e2b44fb759711a73de6a282732f919f5fc2cb6caf8bcb7f312d6e78238588b9321d174e45aca66cfd58cc01f43b4ba65207400f532be822333a5aa43031e9d
7
- data.tar.gz: 7367297fea0431159120dca7805b16e54fd2c6e252368f6ef8b57e8bf7ce89f19931d8485fe50ce774a3500a73e3bb31b95fb591e8ed4dccfb05e0df3e6c83fc
6
+ metadata.gz: 4ded4fc1774ddd3d2088a179c8ca545783a338580533e5051b824497de769ea1ec102956b6232fa635478ca8112401fbe82620dad35ce1b75e8a3becf759fee4
7
+ data.tar.gz: 729a4e5397096b15f4b7f9c4ce28dc00780471ea2ad7b99010fa162d21fbfbec5aa28bacdb40d72ed1795c8453871eb134acb0958a9f71f56bcd63140a68b817
data/.travis.yml CHANGED
@@ -1,7 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
3
+ - 2.1
4
+ - 2.0
5
+ env:
6
+ global:
7
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
5
8
  notifications:
6
9
  email:
7
10
  recipients:
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
- has_file_datastream :content
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.transform_datastream :content, { :thumb => "100x100>" }
17
+ obj.transform_file :content, { :thumb => "100x100>" }
18
18
  when 'audio/wav'
19
- obj.transform_datastream :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
19
+ obj.transform_file :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
20
20
  when 'video/avi'
21
- obj.transform_datastream :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
21
+ obj.transform_file :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
22
22
  when 'image/png', 'image/jpg'
23
- obj.transform_datastream :content, { :medium => "300x300>", :thumb => "100x100>" }
23
+ obj.transform_file :content, { :medium => "300x300>", :thumb => "100x100>" }
24
24
  when 'image/tiff'
25
- obj.transform_datastream :content, { :service => { resize: "3600x3600>" } }, processor: 'jpeg2k_image'
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
- has_file_datastream :content
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
- transform_datastream :content, { :thumb => "100x100>" }
46
+ transform_file :content, { :thumb => "100x100>" }
47
47
  when 'audio/wav'
48
- transform_datastream :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
48
+ transform_file :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
49
49
  when 'video/avi'
50
- transform_datastream :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
50
+ transform_file :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
51
51
  when 'image/png', 'image/jpg'
52
- transform_datastream :content, { :medium => "300x300>", :thumb => {size: "100x100>", datastream: 'thumbnail'} }
52
+ transform_file :content, { :medium => "300x300>", :thumb => {size: "100x100>", datastream: 'thumbnail'} }
53
53
  when 'image/tiff'
54
- transform_datastream :content, { :service => { recipe: :default } }, processor: 'jpeg2k_image'
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 datastreams, 'thumbnail' and 'content_medium', will have been created with downsized images in them.
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
1
+ 1.0.0.beta1
@@ -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=\{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
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 encode_datastream(dest_dsid, file_suffix, mime_type, options = '')
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
- source_datastream.to_tempfile do |f|
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, mimeType: mime_type)
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
- mime_type = MIME::Types[mimeType].first
33
- Logger.warn "Unable to find a registered mime type for #{mimeType.inspect} on #{pid}" unless mime_type
34
- extension = mime_type ? ".#{mime_type.extensions.first}" : ''
35
- ["#{pid}-#{dsVersionID}", "#{extension}"]
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
- output_datastream_name = opts.fetch(:datastream, output_datastream_id(name))
10
- create_resized_image(output_datastream(output_datastream_name), opts[:size], format)
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(output_datastream, size, format, quality=nil)
21
- create_image(output_datastream, format, quality) do |xfrm|
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
- output_datastream.mimeType = new_mime_type(format)
24
+ output_file.mime_type = new_mime_type(format)
25
25
  end
26
26
 
27
- def create_image(output_datastream, format, quality=nil)
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(output_datastream, xfrm)
32
+ write_image(output_file, xfrm)
33
33
  end
34
34
 
35
- def write_image(output_datastream, xfrm)
35
+ def write_image(output_file, xfrm)
36
36
  stream = StringIO.new
37
37
  xfrm.write(stream)
38
38
  stream.rewind
39
- output_datastream.content = stream
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 datastream)
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(source_datastream.content)
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(source_datastream.content)
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
- output_datastream_name = args[:datastream] || output_datastream_id(name)
23
- encode_datastream(output_datastream_name, recipe, file_path: file_path)
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 encode_datastream(dest_dsid, recipe, opts={})
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
- source_datastream.to_tempfile do |f|
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, mimeType: 'image/jp2')
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 = "\{#{tile_size},#{tile_size}\}"
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=#{tiles_arg}
103
- Cblk=\{64,64\}
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
 
@@ -5,7 +5,7 @@ module Hydra::Derivatives
5
5
 
6
6
  def method_missing method_name, *arguments, &block
7
7
  logger.send(method_name, *arguments, &block)
8
- rescue
8
+ rescue
9
9
  super
10
10
  end
11
11
 
@@ -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 output_datastream_id(name)
16
+ def output_file_id(name)
17
17
  [source_name, name].join('_')
18
18
  end
19
19
 
20
- def output_datastream(dsid)
21
- # first, check for a defined datastream
22
- output_datastream = if object.datastreams[dsid]
23
- object.datastreams[dsid]
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
- ds = ActiveFedora::Datastream.new(object.inner_object, dsid)
26
- object.add_datastream(ds)
27
- ds
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 source_datastream
32
- object.datastreams[source_name.to_s]
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
- output_datastream_name = args[:datastream] || output_datastream_id(name)
21
- encode_datastream(output_datastream_name, format, new_mime_type(format), options_for(format))
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 encode_datastream(dest_dsid, file_suffix, mime_type, options = '')
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
- source_datastream.to_tempfile do |f|
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, :dsid=>dest_dsid, :mimeType=>mime_type)
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
 
@@ -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 datastream according to transformation directives
62
- # @param datastream_name
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
- # transform_datastream :content, { :thumb => "100x100>" }
69
+ # transform_file :content, { :thumb => "100x100>" }
68
70
  #
69
- # @example Specify the dsid for the output datastream
70
- # transform_datastream :content, { :thumb => {size: "200x300>", datastream: 'thumbnail'} }
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
- # transform_datastream :content, { :medium => "300x300>", :thumb => "100x100>" }
75
+ # transform_file :content, { :medium => "300x300>", :thumb => "100x100>" }
74
76
  #
75
77
  # @example Specify which processor you want to use (defaults to :image)
76
- # transform_datastream :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
77
- # transform_datastream :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
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 transform_datastream(datastream_name, transform_directives, opts={})
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, datastream_name, transform_directives).process
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.transform_datastream :content, { :thumb => "100x100>" }
100
+ # obj.transform_file :content, { :thumb => "100x100>" }
93
101
  # when 'audio/wav'
94
- # obj.transform_datastream :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
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
- # transform_datastream :content, { :medium => "300x300>", :thumb => "100x100>" }
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, :mimeType, :pid, :dsVersionID
7
+ attr_reader :content, :mime_type, :uri
8
+
8
9
  def initialize(options = {})
9
10
  @content = options.fetch(:content, '')
10
- @mimeType = options.fetch(:mime_type, nil)
11
- @pid = options.fetch(:pid, 'pid-123')
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'
@@ -1,12 +1,12 @@
1
1
  require "spec_helper"
2
2
 
3
- class ExtractThing < ActiveFedora::Datastream
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
@@ -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) {{ :thumb => "100x100>" } }
7
- subject { Hydra::Derivatives::Image.new(object, 'content', directives)}
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(an_instance_of(ActiveFedora::Datastream), "100x100>", 'png') do |ds|
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) {{ :thumb => {size: "200x300>", datastream: 'thumbnail'} }}
18
- subject { Hydra::Derivatives::Image.new(object, 'content', directives)}
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(an_instance_of(ActiveFedora::Datastream), "200x300>", 'png') do |ds|
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::Datastream
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
- has_metadata 'characterization', type: ActiveFedora::SimpleDatastream do |m|
12
- m.field "mime_type", :string
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 :mime_type, datastream: :characterization, multiple: false
16
- has_file_datastream 'content', type: ContentDatastream
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.mime_type
20
+ case obj.mime_type_from_fits
20
21
  when 'application/pdf'
21
- obj.transform_datastream :content, { thumb: '100x100>' }
22
+ obj.transform_file :content, { thumb: '100x100>' }
22
23
  when 'audio/wav'
23
- obj.transform_datastream :content, { mp3: { format: 'mp3' }, ogg: { format: 'ogg'} }, processor: :audio
24
+ obj.transform_file :content, { mp3: { format: 'mp3' }, ogg: { format: 'ogg'} }, processor: :audio
24
25
  when 'video/avi'
25
- obj.transform_datastream :content, { mp4: { format: 'mp4' }, webm: { format: 'webm'}, thumbnail: { format: 'jpg', datastream: 'thumbnail' } }, processor: :video
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.transform_datastream :content, { medium: "300x300>", thumb: "100x100>", access: { format: 'jpg', datastream: 'access'} }
28
+ obj.transform_file :content, { medium: "300x300>", thumb: "100x100>", access: { format: 'jpg', datastream: 'access'} }
28
29
  when 'application/vnd.ms-powerpoint'
29
- obj.transform_datastream :content, { preservation: { format: 'pptx'}, access: { format: 'pdf' }, thumbnail: { format: 'jpg' } }, processor: 'document'
30
+ obj.transform_file :content, { preservation: { format: 'pptx'}, access: { format: 'pdf' }, thumbnail: { format: 'jpg' } }, processor: 'document'
30
31
  when 'text/rtf'
31
- obj.transform_datastream :content, { preservation: { format: 'odf' }, access: { format: 'pdf' }, thumbnail: { format: 'jpg' } }, processor: 'document'
32
+ obj.transform_file :content, { preservation: { format: 'odf' }, access: { format: 'pdf' }, thumbnail: { format: 'jpg' } }, processor: 'document'
32
33
  when 'application/msword'
33
- obj.transform_datastream :content, { access: { format: 'pdf' }, preservation: { format: 'docx' }, thumbnail: { format: 'jpg' } }, processor: 'document'
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.transform_datastream :content, { access: { format: 'pdf' }, preservation: { format: 'xslx' }, thumbnail: { format: 'jpg' } }, processor: 'document'
36
+ obj.transform_file :content, { access: { format: 'pdf' }, preservation: { format: 'xslx' }, thumbnail: { format: 'jpg' } }, processor: 'document'
36
37
  when 'image/tiff'
37
- obj.transform_datastream :content, {
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 label == "special" && mime_type == 'image/png'
51
- transform_datastream :content, { medium: { size: "200x300>", datastream: 'special_ds' } }
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(mime_type: 'image/png').tap do |f|
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.datastreams.key?('content_medium')).to be_falsey
73
+ expect(file.attached_files.key?('content_medium')).to be_falsey
74
74
  file.create_derivatives
75
- expect(file.datastreams['content_medium']).to have_content
76
- expect(file.datastreams['content_medium'].mimeType).to eq('image/png')
77
- expect(file.datastreams['content_thumb']).to have_content
78
- expect(file.datastreams['content_thumb'].mimeType).to eq('image/png')
79
- expect(file.datastreams['access']).to have_content
80
- expect(file.datastreams['access'].mimeType).to eq('image/jpeg')
81
- expect(file.datastreams.key?('content_text')).to be_falsey
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(mime_type: 'application/pdf').tap { |t| t.content.content = attachment; t.save } }
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.datastreams.key?('content_thumb')).to be_falsey
90
+ expect(file.attached_files.key?('content_thumb')).to be_falsey
91
91
  file.create_derivatives
92
- expect(file.datastreams['content_thumb']).to have_content
93
- expect(file.datastreams['content_thumb'].mimeType).to eq('image/png')
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(mime_type: 'audio/wav').tap { |t| t.content.content = attachment; t.save } }
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.datastreams['content_mp3']).to have_content
104
- expect(file.datastreams['content_mp3'].mimeType).to eq('audio/mpeg')
105
- expect(file.datastreams['content_ogg']).to have_content
106
- expect(file.datastreams['content_ogg'].mimeType).to eq('audio/ogg')
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) { GenericFile.new(mime_type: 'audio/wav').tap { |t| t.content.content = attachment; t.content.mimeType = 'audio/vnd.wav'; t.save } }
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.datastreams['content_mp3']).to have_content
117
- expect(file.datastreams['content_mp3'].mimeType).to eq('audio/mpeg')
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(mime_type: 'video/avi').tap { |t| t.content.content = attachment; t.save } }
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.datastreams['content_mp4']).to have_content
128
- expect(file.datastreams['content_mp4'].mimeType).to eq('video/mp4')
129
- expect(file.datastreams['content_webm']).to have_content
130
- expect(file.datastreams['content_webm'].mimeType).to eq('video/webm')
131
- expect(file.datastreams['thumbnail']).to have_content
132
- expect(file.datastreams['thumbnail'].mimeType).to eq('image/jpeg')
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(mime_type: 'image/png', label: "special").tap { |t| t.content.content = attachment; t.save } }
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.datastreams.key?('special_ds')).to be_falsey
148
+ expect(file.attached_files.key?('special_ds')).to be_falsey
142
149
  file.create_derivatives
143
- expect(file.datastreams['special_ds']).to have_content
144
- expect(file.datastreams['special_ds'].mimeType).to eq('image/png')
145
- expect(file.datastreams['special_ds']).to have_content
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(mime_type: 'application/vnd.ms-powerpoint').tap { |t| t.content.content = attachment; t.save } }
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.datastreams['content_thumbnail']).to have_content
156
- expect(file.datastreams['content_thumbnail'].mimeType).to eq('image/jpeg')
157
- expect(file.datastreams['content_access']).to have_content
158
- expect(file.datastreams['content_access'].mimeType).to eq('application/pdf')
159
- expect(file.datastreams['content_preservation']).to have_content
160
- expect(file.datastreams['content_preservation'].mimeType).to eq('application/vnd.openxmlformats-officedocument.presentationml.presentation')
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(mime_type: 'text/rtf').tap { |t| t.content.content = attachment; t.save } }
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.datastreams['content_thumbnail']).to have_content
171
- expect(file.datastreams['content_thumbnail'].mimeType).to eq('image/jpeg')
172
- expect(file.datastreams['content_access']).to have_content
173
- expect(file.datastreams['content_access'].mimeType).to eq('application/pdf')
174
- expect(file.datastreams['content_preservation']).to have_content
175
- expect(file.datastreams['content_preservation'].mimeType).to eq('application/vnd.oasis.opendocument.text')
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(mime_type: 'application/msword').tap { |t| t.content.content = attachment; t.save } }
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.datastreams['content_thumbnail']).to have_content
186
- expect(file.datastreams['content_thumbnail'].mimeType).to eq('image/jpeg')
187
- expect(file.datastreams['content_access']).to have_content
188
- expect(file.datastreams['content_access'].mimeType).to eq('application/pdf')
189
- expect(file.datastreams['content_preservation']).to have_content
190
- expect(file.datastreams['content_preservation'].mimeType).to eq('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
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(mime_type: 'application/vnd.ms-excel').tap { |t| t.content.content = attachment; t.save } }
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.datastreams['content_thumbnail']).to have_content
201
- expect(file.datastreams['content_thumbnail'].mimeType).to eq('image/jpeg')
202
- expect(file.datastreams['content_access']).to have_content
203
- expect(file.datastreams['content_access'].mimeType).to eq('application/pdf')
204
- expect(file.datastreams['content_preservation']).to have_content
205
- expect(file.datastreams['content_preservation'].mimeType).to eq('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
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(mime_type: 'image/tiff').tap { |t| t.content.content = attachment; t.save } }
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.datastreams['content_diy']).to have_content
215
- expect(file.datastreams['content_diy'].mimeType).to eq('image/jp2')
216
- expect(file.datastreams['config_lookup']).to have_content
217
- expect(file.datastreams['config_lookup'].mimeType).to eq('image/jp2')
218
- expect(file.datastreams['resized']).to have_content
219
- expect(file.datastreams['resized'].mimeType).to eq('image/jp2')
220
- expect(file.datastreams['string_recipe']).to have_content
221
- expect(file.datastreams['string_recipe'].mimeType).to eq('image/jp2')
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
@@ -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(:encode_datastream).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=>""})
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(:encode_datastream).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=>""})
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(:encode_datastream).with("thumbnail", "jpg", "image/jpeg", {:output_options=>"-s 320x240 -vcodec mjpeg -vframes 1 -an -f rawvideo", :input_options=>" -itsoffset -2"})
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.1.1
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-07-21 00:00:00.000000000 Z
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: '0'
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: '0'
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: '0'
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: