hydra-derivatives 3.2.1 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c4f7de97aeaa9148272e2cc1e4d16bba7d33f4f
4
- data.tar.gz: 867caa37665a6e477ab511435b501124b63f852a
3
+ metadata.gz: 505c538dd6ded3a65f826eb0d93040bc4edf2a1e
4
+ data.tar.gz: 0323253a69f02a91b84e07f546e42debd822ea7f
5
5
  SHA512:
6
- metadata.gz: fcc289306fd1d503078e74e149f3dc252f0b55c60e735fe9f650cd636e88d9be78d929f71ea3df138e30ae54bc1a166e22b447282bb2e644c44db64b9e70f07d
7
- data.tar.gz: 2a0396315ec846b9a1457561810cf6c0decf3bed5b45a4f409854e8ab6df78de6a4600acab934494e78f2f3395bbd95f66f1f85f8ded36178025e8bddff9807b
6
+ metadata.gz: c27070a785686b16bb37c60d0a30cf175da384e2818942efb3d7994ff0eacf2a61b84aa0f1189216d4242ed235bda6bda1a43001b3dcb7ad09efcb5a9a085254
7
+ data.tar.gz: 453cec1e1d0b1f5940ad251f6271771e0f062f37e53342f80e31f783005b1a87615868d615e569389dcef1635e2332ef59e7a7f92048c93018e0a6e4f0876349
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ pkg/
7
7
  .ruby-gemset
8
8
  fcrepo4-data/
9
9
  fcrepo4-test-data/
10
+ coverage/
data/.travis.yml CHANGED
@@ -1,8 +1,13 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  sudo: false
4
+ before_install:
5
+ - gem update --system
6
+ - gem install bundler
4
7
  rvm:
5
8
  - 2.2.5
9
+ - 2.3.1
10
+ - 2.4.0
6
11
  env:
7
12
  global:
8
13
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
data/CONTRIBUTING.md CHANGED
@@ -3,6 +3,13 @@
3
3
  We want your help to make Project Hydra great.
4
4
  There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
5
5
 
6
+ ## Code of Conduct
7
+
8
+ The Hydra community is dedicated to providing a welcoming and positive experience for all its
9
+ members, whether they are at a formal gathering, in a social setting, or taking part in activities
10
+ online. Please see our [Code of Conduct](https://wiki.duraspace.org/display/hydra/Code+of+Conduct)
11
+ for more information.
12
+
6
13
  ## Hydra Project Intellectual Property Licensing and Ownership
7
14
 
8
15
  All code contributors must have an Individual Contributor License Agreement (iCLA) on file with the Hydra Project Steering Group.
@@ -16,8 +23,10 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
16
23
 
17
24
  * Reporting Issues
18
25
  * Making Changes
26
+ * Documenting Code
27
+ * Committing Changes
19
28
  * Submitting Changes
20
- * Merging Changes
29
+ * Reviewing and Merging Changes
21
30
 
22
31
  ### Reporting Issues
23
32
 
@@ -38,8 +47,28 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
38
47
  * Then checkout the new branch with `git checkout fix/master/my_contribution`.
39
48
  * Please avoid working directly on the `master` branch.
40
49
  * You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
50
+ * Make sure you have added sufficient tests and documentation for your changes.
51
+ * Test functionality with RSpec; est features / UI with Capybara.
52
+ * Run _all_ the tests to assure nothing else was accidentally broken.
53
+
54
+ ### Documenting Code
55
+
56
+ * All new public methods, modules, and classes should include inline documentation in [YARD](http://yardoc.org/).
57
+ * Documentation should seek to answer the question "why does this code exist?"
58
+ * Document private / protected methods as desired.
59
+ * If you are working in a file with no prior documentation, do try to document as you gain understanding of the code.
60
+ * If you don't know exactly what a bit of code does, it is extra likely that it needs to be documented. Take a stab at it and ask for feedback in your pull request. You can use the 'blame' button on GitHub to identify the original developer of the code and @mention them in your comment.
61
+ * This work greatly increases the usability of the code base and supports the on-ramping of new committers.
62
+ * We will all be understanding of one another's time constraints in this area.
63
+ * YARD examples:
64
+ * [Hydra::Works::RemoveGenericFile](https://github.com/projecthydra-labs/hydra-works/blob/master/lib/hydra/works/services/generic_work/remove_generic_file.rb)
65
+ * [ActiveTriples::LocalName::Minter](https://github.com/ActiveTriples/active_triples-local_name/blob/master/lib/active_triples/local_name/minter.rb)
66
+ * [Getting started with YARD](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
67
+
68
+ ### Committing changes
69
+
41
70
  * Make commits of logical units.
42
- * Your commit should include a high level description of your work in HISTORY.textile
71
+ * Your commit should include a high level description of your work in HISTORY.textile
43
72
  * Check for unnecessary whitespace with `git diff --check` before committing.
44
73
  * Make sure your commit messages are [well formed](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
45
74
  * If you created an issue, you can close it by including "Closes #issue" in your commit message. See [Github's blog post for more details](https://github.com/blog/1386-closing-issues-via-commit-messages)
@@ -60,7 +89,9 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
60
89
 
61
90
  class PostsController
62
91
  def index
63
- respond_with Post.limit(10)
92
+ respond_to do |wants|
93
+ wants.html { render 'index' }
94
+ end
64
95
  end
65
96
  end
66
97
 
@@ -72,38 +103,53 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
72
103
  long to fit in 72 characters
73
104
  ```
74
105
 
75
- * Make sure you have added the necessary tests for your changes.
76
- * Run _all_ the tests to assure nothing else was accidentally broken.
77
- * When you are ready to submit a pull request
78
-
79
106
  ### Submitting Changes
80
107
 
81
- [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
82
-
83
108
  * Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
84
109
  * Make sure your branch is up to date with its parent branch (i.e. master)
85
110
  * `git checkout master`
86
111
  * `git pull --rebase`
87
112
  * `git checkout <your-branch>`
88
113
  * `git rebase master`
89
- * It is likely a good idea to run your tests again.
90
- * Squash the commits for your branch into one commit
91
- * `git rebase --interactive HEAD~<number-of-commits>` ([See Github help](https://help.github.com/articles/interactive-rebase))
92
- * To determine the number of commits on your branch: `git log master..<your-branch> --oneline | wc -l`
114
+ * It is a good idea to run your tests again.
115
+ * If you've made more than one commit take a moment to consider whether squashing commits together would help improve their logical grouping.
116
+ * [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
117
+ * `git rebase --interactive master` ([See Github help](https://help.github.com/articles/interactive-rebase))
93
118
  * Squashing your branch's changes into one commit is "good form" and helps the person merging your request to see everything that is going on.
94
119
  * Push your changes to a topic branch in your fork of the repository.
95
120
  * Submit a pull request from your fork to the project.
96
121
 
97
- ### Merging Changes
122
+ ### Reviewing and Merging Changes
123
+
124
+ We adopted [Github's Pull Request Review](https://help.github.com/articles/about-pull-request-reviews/) for our repositories.
125
+ Common checks that may occur in our repositories:
126
+
127
+ 1. Travis CI - where our automated tests are running
128
+ 2. Hound CI - where we check for style violations
129
+ 3. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
130
+ 4. CodeClimate - is our code remaining healthy (at least according to static code analysis)
131
+
132
+ If one or more of the required checks failed (or are incomplete), the code should not be merged (and the UI will not allow it). If all of the checks have passed, then anyone on the project (including the pull request submitter) may merge the code.
133
+
134
+ *Example: Carolyn submits a pull request, Justin reviews the pull request and approves. However, Justin is still waiting on other checks (Travis CI is usually the culprit), so he does not merge the pull request. Eventually, all of the checks pass. At this point, Carolyn or anyone else may merge the pull request.*
135
+
136
+ #### Things to Consider When Reviewing
137
+
138
+ First, the person contributing the code is putting themselves out there. Be mindful of what you say in a review.
139
+
140
+ * Ask clarifying questions
141
+ * State your understanding and expectations
142
+ * Provide example code or alternate solutions, and explain why
143
+
144
+ This is your chance for a mentoring moment of another developer. Take time to give an honest and thorough review of what has changed. Things to consider:
98
145
 
99
- * It is considered "poor from" to merge your own request.
100
- * Please take the time to review the changes and get a sense of what is being changed. Things to consider:
101
146
  * Does the commit message explain what is going on?
102
- * Does the code changes have tests? _Not all changes need new tests, some changes are refactorings_
147
+ * Does the code changes have tests? _Not all changes need new tests, some changes are refactors_
148
+ * Do new or changed methods, modules, and classes have documentation?
103
149
  * Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
104
- * Did the Travis tests complete successfully?
105
- * If you are uncertain, bring other contributors into the conversation by creating a comment that includes their @username.
106
- * If you like the pull request, but want others to chime in, create a +1 comment and tag a user.
150
+ * Does the description of the new/changed specs match your understanding of what the spec is doing?
151
+
152
+ If you are uncertain, bring other contributors into the conversation by assigning them as a reviewer.
107
153
 
108
154
  # Additional Resources
109
155
 
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development, :test do
7
+ gem 'simplecov'
8
+ gem 'coveralls'
7
9
  gem 'byebug' unless ENV['TRAVIS']
8
10
  gem 'rubocop', '~> 0.37.2', require: false
9
11
  gem 'rubocop-rspec', require: false
data/History.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 3.2.2 (2017-04-07)
2
+ * 2017-04-05: Raise an exception when encoding fails [Valerie Maher] * 2017-04-03: Add in service check to determine which libraries ffmpeg has [Jame Little]
3
+ * 2017-04-01: Fix broken rspec tests [Chris Colvard]
4
+
1
5
  ## 3.2.1 (2016-11-21)
2
6
  2016-11-17: Default to first page for pdf images [Adam Wead]
3
7
 
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
- # hydra-derivatives [![Version](https://badge.fury.io/rb/hydra-derivatives.png)](http://badge.fury.io/rb/hydra-derivatives) [![Build Status](https://travis-ci.org/projecthydra/hydra-derivatives.png?branch=master)](https://travis-ci.org/projecthydra/hydra-derivatives) [![Dependency Status](https://gemnasium.com/projecthydra/hydra-derivatives.png)](https://gemnasium.com/projecthydra/hydra-derivatives)
1
+ # hydra-derivatives
2
+
3
+ [![Version](https://badge.fury.io/rb/hydra-derivatives.png)](http://badge.fury.io/rb/hydra-derivatives)
4
+ [![Build Status](https://travis-ci.org/projecthydra/hydra-derivatives.png?branch=master)](https://travis-ci.org/projecthydra/hydra-derivatives)
5
+ [![Dependency Status](https://gemnasium.com/projecthydra/hydra-derivatives.png)](https://gemnasium.com/projecthydra/hydra-derivatives)
6
+ [![Coverage Status](https://coveralls.io/repos/github/projecthydra/hydra-derivatives/badge.svg?branch=master)](https://coveralls.io/github/projecthydra/hydra-derivatives?branch=master)
2
7
 
3
8
  Derivative generation for hydra
4
9
 
@@ -65,10 +70,10 @@ If no timeout is set the system will process until complete (possibly indefinite
65
70
  ```
66
71
  require 'hydra/derivatives'
67
72
 
68
- Hydra::Derivatives::Video::Processor.timeout = 10.minutes
69
- Hydra::Derivatives::Document.timeout = 5.minutes
70
- Hydra::Derivatives::Audio.timeout = 10.minutes
71
- Hydra::Derivatives::Image.timeout = 5.minutes
73
+ Hydra::Derivatives::Processors::Video::Processor.timeout = 10.minutes
74
+ Hydra::Derivatives::Processors::Document.timeout = 5.minutes
75
+ Hydra::Derivatives::Processors::Audio.timeout = 10.minutes
76
+ Hydra::Derivatives::Processors::Image.timeout = 5.minutes
72
77
 
73
78
  ```
74
79
 
@@ -77,10 +82,10 @@ Hydra::Derivatives::Image.timeout = 5.minutes
77
82
  Flags can be set for using different video codes. Default codecs are shown below
78
83
 
79
84
  ```
80
- Hydra::Derivatives::Video::Processor.config.mpeg4.codec = '-vcodec libx264 -acodec libfdk_aac'
81
- Hydra::Derivatives::Video::Processor.config.webm.codec = '-vcodec libvpx -acodec libvorbis'
82
- Hydra::Derivatives::Video::Processor.config.mkv.codec = '-vcodec ffv1'
83
- Hydra::Derivatives::Video::Processor.config.jpeg.codec = '-vcodec mjpeg'
85
+ Hydra::Derivatives::Processors::Video::Processor.config.mpeg4.codec = '-vcodec libx264 -acodec libfdk_aac'
86
+ Hydra::Derivatives::Processors::Video::Processor.config.webm.codec = '-vcodec libvpx -acodec libvorbis'
87
+ Hydra::Derivatives::Processors::Video::Processor.config.mkv.codec = '-vcodec ffv1'
88
+ Hydra::Derivatives::Processors::Video::Processor.config.jpeg.codec = '-vcodec mjpeg'
84
89
  ```
85
90
 
86
91
  ### Additional Directives
@@ -103,11 +108,13 @@ Just add `gem 'hydra-derivatives'` to your Gemfile.
103
108
 
104
109
  ## Dependencies
105
110
 
106
- * [FITS](http://fitstool.org/) - 0.8.x (0.8.5 is known to be good)
111
+ * [FITS](http://fitstool.org/) - 1.0.x (1.0.5 is known to be good)
107
112
  * [FFMpeg](http://www.ffmpeg.org/)
108
113
  * [LibreOffice](https://www.libreoffice.org/) (openoffice.org-headless on Ubuntu/Debian to avoid "_X11 error: Can't open display:_")
114
+ * [GhostScript](https://www.ghostscript.com/)
109
115
  * [ImageMagick](http://www.imagemagick.org/)
110
116
  * Kakadu's [kdu_compress](http://www.kakadusoftware.com/) (optional)
117
+ * [ufraw](http://ufraw.sourceforge.net/)
111
118
 
112
119
  To enable LibreOffice, FFMpeg, ImageMagick, FITS support, and kdu_compress support, make sure they are on your path. Most people will put that in their .bash_profile or somewhere similar.
113
120
 
@@ -115,7 +122,7 @@ For example:
115
122
 
116
123
  ```bash
117
124
  # in .bash_profile
118
- export PATH=${PATH}:/Users/justin/workspace/fits-0.8.5:/Applications/LibreOffice.app/Contents/MacOS
125
+ export PATH=${PATH}:/Users/justin/workspace/fits-1.0.5:/Applications/LibreOffice.app/Contents/MacOS
119
126
  ```
120
127
 
121
128
  Alternatively, you can configure their paths:
@@ -125,6 +132,17 @@ Hydra::Derivatives.fits_path = '/opt/local/fits/bin/fits.sh'
125
132
  Hydra::Derivatives.libreoffice_path = '/opt/local/libreoffice_path/bin/soffice'
126
133
  Hydra::Derivatives.kdu_compress_path = '/usr/local/bin/kdu_compress'
127
134
  ```
135
+ ## Configuration
136
+
137
+ ImageMagick by default stores temp files in system /tmp. If you'd like to override this, adjust these environment variables:
138
+
139
+ ```
140
+ MAGICK_TEMPORARY_PATH
141
+ MAGICK_TMPDIR
142
+ MAGICK_TEMPDIR
143
+
144
+ ```
145
+ YMMV as to where setting them will take effect in your app; the application's web server's vhost directives are a location known to work with an Apache web server set up.
128
146
 
129
147
  ## JPEG2k Directives
130
148
 
data/Rakefile CHANGED
@@ -19,7 +19,9 @@ namespace :derivatives do
19
19
  task.fail_on_error = true
20
20
  end
21
21
 
22
- RSpec::Core::RakeTask.new(:rspec)
22
+ RSpec::Core::RakeTask.new(:rspec) do |task|
23
+ task.rspec_opts = "--tag ~requires_imagemagick --tag ~requires_ffmpeg --tag ~requires_libreoffice --tag ~requires_kdu_compress" if ENV['TRAVIS']
24
+ end
23
25
 
24
26
  desc 'Start up Solr & Fedora and run tests'
25
27
  task :spec do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 3.2.2
@@ -26,6 +26,7 @@ module Hydra
26
26
  autoload :Logger
27
27
  autoload :TempfileService
28
28
  autoload :IoDecorator
29
+ autoload :AudioEncoder
29
30
 
30
31
  autoload_under 'services' do
31
32
  autoload :RetrieveSourceFileService
@@ -46,8 +47,9 @@ module Hydra
46
47
  @config = Config.new
47
48
  end
48
49
 
49
- [:ffmpeg_path, :libreoffice_path, :temp_file_base, :fits_path, :kdu_compress_path,
50
- :kdu_compress_recipes, :enable_ffmpeg, :source_file_service, :output_file_service].each do |method|
50
+ CONFIG_METHODS = [:ffmpeg_path, :libreoffice_path, :temp_file_base, :fits_path, :kdu_compress_path,
51
+ :kdu_compress_recipes, :enable_ffmpeg, :source_file_service, :output_file_service].freeze
52
+ CONFIG_METHODS.each do |method|
51
53
  module_eval <<-RUBY
52
54
  def self.#{method}
53
55
  config.#{method}
@@ -0,0 +1,27 @@
1
+ require 'open3'
2
+
3
+ module Hydra::Derivatives
4
+ class AudioEncoder
5
+ def initialize
6
+ @ffmpeg_output = Open3.capture3('ffmpeg -codecs').to_s
7
+ rescue
8
+ Logger.warn('Unable to find ffmpeg')
9
+ @ffmpeg_output = ""
10
+ end
11
+
12
+ def audio_encoder
13
+ audio_encoder = if fdk_aac?
14
+ 'libfdk_aac'
15
+ else
16
+ 'aac'
17
+ end
18
+ audio_encoder
19
+ end
20
+
21
+ private
22
+
23
+ def fdk_aac?
24
+ @ffmpeg_output.include?('--enable-libfdk-aac') || @ffmpeg_output.include?('--with-fdk-aac')
25
+ end
26
+ end
27
+ end
@@ -32,7 +32,8 @@ module Hydra
32
32
  end
33
33
 
34
34
  def enable_ffmpeg
35
- @enable_ffmpeg ||= true
35
+ return @enable_ffmpeg unless @enable_ffmpeg.nil?
36
+ @enable_ffmpeg = true
36
37
  end
37
38
 
38
39
  def kdu_compress_path
@@ -73,20 +73,18 @@ module Hydra::Derivatives::Processors
73
73
  rates.map(&:to_s).join(',')
74
74
  end
75
75
 
76
- protected
77
-
78
- def encode(path, recipe, output_file)
79
- kdu_compress = Hydra::Derivatives.kdu_compress_path
80
- execute "#{kdu_compress} -quiet -i #{path} -o #{output_file} #{recipe}"
81
- end
76
+ def encode(path, recipe, output_file)
77
+ kdu_compress = Hydra::Derivatives.kdu_compress_path
78
+ execute "#{kdu_compress} -quiet -i #{path} -o #{output_file} #{recipe}"
79
+ end
82
80
 
83
- def tmp_file(ext)
84
- Dir::Tmpname.create(['sufia', ext], Hydra::Derivatives.temp_file_base) {}
85
- end
81
+ def tmp_file(ext)
82
+ Dir::Tmpname.create(['sufia', ext], Hydra::Derivatives.temp_file_base) {}
83
+ end
86
84
 
87
- def long_dim(image)
88
- [image[:width], image[:height]].max
89
- end
85
+ def long_dim(image)
86
+ [image[:width], image[:height]].max
87
+ end
90
88
  end
91
89
 
92
90
  def process
@@ -19,7 +19,8 @@ module Hydra::Derivatives::Processors::Video
19
19
  end
20
20
 
21
21
  def mpeg4
22
- @mpeg4 ||= CodecConfig.new('-vcodec libx264 -acodec libfdk_aac')
22
+ audio_encoder = Hydra::Derivatives::AudioEncoder.new
23
+ @mpeg4 ||= CodecConfig.new("-vcodec libx264 -acodec #{audio_encoder.audio_encoder}")
23
24
  end
24
25
 
25
26
  def webm
@@ -0,0 +1,17 @@
1
+ require 'open3'
2
+
3
+ module Hydra::Derivatives
4
+ class CapabilityService
5
+ attr_accessor :ffmpeg_output
6
+ def capture_output
7
+ @ffmpeg_output = Open3.capture3('ffmpeg -codecs').to_s
8
+ rescue
9
+ Logger.warn('Unable to find ffmpeg')
10
+ @ffmpeg_output = ""
11
+ end
12
+
13
+ def fdk_aac?
14
+ @ffmpeg_output.include?('--enable-libfdk-aac') || @ffmpeg_output.include?('--with-fdk-aac')
15
+ end
16
+ end
17
+ end
@@ -111,7 +111,7 @@ describe Hydra::Derivatives::Processors::Image do
111
111
  end
112
112
  end
113
113
 
114
- context "when running the complete command", unless: in_travis? do
114
+ context "when running the complete command", requires_imagemagick: true do
115
115
  let(:file_name) { File.join(fixture_path, "test.tif") }
116
116
  it "converts the image" do
117
117
  expect(Hydra::Derivatives::PersistBasicContainedOutputFileService).to receive(:call).with(kind_of(StringIO), directives)
@@ -3,6 +3,8 @@ require 'yaml'
3
3
 
4
4
  describe Hydra::Derivatives::Processors::Jpeg2kImage do
5
5
  let(:object) { ActiveFedora::Base.new }
6
+ let(:filename) { File.expand_path('../../fixtures/test.tif', __FILE__) }
7
+ let(:image) { MiniMagick::Image.open(filename) }
6
8
 
7
9
  describe "#calculate_recipe" do
8
10
  it "calculates the number of levels from a size" do
@@ -29,6 +31,9 @@ describe Hydra::Derivatives::Processors::Jpeg2kImage do
29
31
  @sample_cfg = YAML.load_file(File.expand_path('../../fixtures/jpeg2k_config.yml', __FILE__))['test']
30
32
  Hydra::Derivatives.kdu_compress_recipes = @sample_cfg['jp2_recipes']
31
33
  end
34
+ after(:all) do
35
+ Hydra::Derivatives.reset_config!
36
+ end
32
37
 
33
38
  it "can get the recipe from a config file" do
34
39
  args = { recipe: :myrecipe }
@@ -54,4 +59,24 @@ describe Hydra::Derivatives::Processors::Jpeg2kImage do
54
59
  expect(r).to eq(described_class.calculate_recipe(args, 'grey', 7200))
55
60
  end
56
61
  end
62
+
63
+ describe "#encode" do
64
+ it "executes the external utility" do
65
+ expect(described_class).to receive(:execute) { 0 }
66
+ described_class.encode('infile', 'recipe', 'outfile')
67
+ end
68
+ end
69
+
70
+ describe "#tmp_file" do
71
+ it "returns a temp file with the correct extension" do
72
+ f = described_class.tmp_file('.test')
73
+ expect(f).to end_with('.test')
74
+ end
75
+ end
76
+
77
+ describe "long_dim" do
78
+ it "returns the image's largest dimension" do
79
+ expect(described_class.long_dim(image)).to eq(386)
80
+ end
81
+ end
57
82
  end
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  describe Hydra::Derivatives::AudioDerivatives do
4
4
  describe ".create" do
5
5
  let(:filename) { 'spec/fixtures/piano_note.wav' }
6
- context "with a filename", unless: in_travis? do
6
+ let(:af_path) { ActiveFedora.fedora.host + ActiveFedora.fedora.base_path }
7
+
8
+ context "with a filename", requires_ffmpeg: true do
7
9
  before do
8
10
  class LocalFileService
9
11
  def self.call(file_name, _options, &_block)
@@ -21,8 +23,8 @@ describe Hydra::Derivatives::AudioDerivatives do
21
23
 
22
24
  it "creates derivatives" do
23
25
  described_class.create(filename,
24
- outputs: [{ label: 'mp3', format: 'mp3', url: 'http://localhost:8983/fedora/rest/dev/1234/mp3' },
25
- { label: 'ogg', format: 'ogg', url: 'http://localhost:8983/fedora/rest/dev/1234/ogg' }])
26
+ outputs: [{ label: 'mp3', format: 'mp3', url: "#{af_path}/1234/mp3" },
27
+ { label: 'ogg', format: 'ogg', url: "#{af_path}/1234/ogg" }])
26
28
  end
27
29
  end
28
30
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,13 @@
1
1
  ENV['environment'] ||= 'test'
2
+
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
6
+ SimpleCov.start do
7
+ add_filter '/spec'
8
+ end
9
+ Coveralls.wear!
10
+
2
11
  # - RSpec adds ./lib to the $LOAD_PATH
3
12
  require 'hydra/derivatives'
4
13
  # Resque.inline = Rails.env.test?
@@ -22,7 +31,3 @@ MIME::Types.add(dng_format)
22
31
  def fixture_path
23
32
  File.expand_path("../fixtures", __FILE__)
24
33
  end
25
-
26
- def in_travis?
27
- !ENV['TRAVIS'].nil? && ENV['TRAVIS'] == 'true'
28
- end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Derivatives::AudioEncoder do
4
+ before do
5
+ @audio_encoder = described_class.new
6
+ end
7
+
8
+ describe 'fdk_aac?' do
9
+ it 'outpus libfdk_aac if your ffmpeg was compiled with the library' do
10
+ enable_libfdk_flags = '--enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --with-fdk-aac'
11
+ @audio_encoder.instance_variable_set(:@ffmpeg_output, enable_libfdk_flags)
12
+ audio_encoder = @audio_encoder.audio_encoder
13
+ expect(audio_encoder).to eq('libfdk_aac')
14
+ end
15
+
16
+ it 'outputs aac if your ffmpeg was compiled with the library' do
17
+ enable_libfdk_flags = '--enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample'
18
+ @audio_encoder.instance_variable_set(:@ffmpeg_output, enable_libfdk_flags)
19
+ audio_encoder = @audio_encoder.audio_encoder
20
+ expect(audio_encoder).to eq('aac')
21
+ end
22
+ end
23
+ end
@@ -1,7 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "the configuration" do
4
- subject { Hydra::Derivatives }
4
+ subject { Hydra::Derivatives::Config.new }
5
+
6
+ before do
7
+ # It's not always /tmp; it depends on OS and ENV vars
8
+ allow(Dir).to receive(:tmpdir).and_return('/tmp')
9
+ end
5
10
 
6
11
  it "has some configuration defaults" do
7
12
  expect(subject.ffmpeg_path).to eq('ffmpeg')
@@ -20,6 +25,9 @@ describe "the configuration" do
20
25
 
21
26
  subject.kdu_compress_path = '/opt/local/bin/kdu_compress'
22
27
  expect(subject.kdu_compress_path).to eq('/opt/local/bin/kdu_compress')
28
+
29
+ subject.enable_ffmpeg = false
30
+ expect(subject.enable_ffmpeg).to be false
23
31
  end
24
32
 
25
33
  it "lets you set a custom output file service" do
@@ -33,14 +41,4 @@ describe "the configuration" do
33
41
  subject.source_file_service = source_file_service
34
42
  expect(subject.source_file_service).to eq(source_file_service)
35
43
  end
36
-
37
- it "lets you reset the configuration" do
38
- subject.ffmpeg_path = '/usr/local/ffmpeg-1.0/bin/ffmpeg'
39
- subject.reset_config!
40
- expect(subject.ffmpeg_path).to eq('ffmpeg')
41
-
42
- subject.kdu_compress_path = '/usr/local/bin/kdu_compress'
43
- subject.reset_config!
44
- expect(subject.kdu_compress_path).to eq('kdu_compress')
45
- end
46
44
  end
@@ -30,4 +30,29 @@ describe Hydra::Derivatives do
30
30
  end
31
31
  end
32
32
  end
33
+
34
+ Hydra::Derivatives::CONFIG_METHODS.each do |method|
35
+ describe method.to_s do
36
+ it 'returns the config value' do
37
+ expect(subject.send(method)).to eq subject.config.send(method)
38
+ end
39
+ end
40
+ describe "#{method}=" do
41
+ it 'stores config changes' do
42
+ expect { subject.send("#{method}=", "new_value") }.to change { subject.config.send(method) }.from(subject.config.send(method)).to("new_value")
43
+ end
44
+ end
45
+ end
46
+
47
+ describe 'reset_config!' do
48
+ it "resets the configuration" do
49
+ subject.ffmpeg_path = '/usr/local/ffmpeg-1.0/bin/ffmpeg'
50
+ subject.reset_config!
51
+ expect(subject.ffmpeg_path).to eq('ffmpeg')
52
+
53
+ subject.kdu_compress_path = '/usr/local/bin/kdu_compress'
54
+ subject.reset_config!
55
+ expect(subject.kdu_compress_path).to eq('kdu_compress')
56
+ end
57
+ end
33
58
  end
@@ -13,12 +13,12 @@ describe "Transcoding" do
13
13
  PdfDerivatives.create(self, source: :original_file,
14
14
  outputs: [{ label: :thumb, size: "100x100>", url: "#{uri}/original_file_thumb" }])
15
15
  FullTextExtract.create(self, source: :original_file, outputs: [{ url: "#{uri}/fulltext" }])
16
- when 'audio/wav'
16
+ when 'audio/x-wav'
17
17
  AudioDerivatives.create(self, source: :original_file,
18
18
  outputs: [
19
- { label: :mp3, format: 'mp3', url: "#{uri}/mp3" },
20
- { label: :ogg, format: 'ogg', url: "#{uri}/ogg" }])
21
- when 'video/avi'
19
+ { label: :mp3, format: 'mp3', url: "#{uri}/original_file_mp3" },
20
+ { label: :ogg, format: 'ogg', url: "#{uri}/original_file_ogg" }])
21
+ when 'video/x-msvideo'
22
22
  VideoDerivatives.create(self, source: :original_file,
23
23
  outputs: [
24
24
  { label: :mp4, format: 'mp4', url: "#{uri}/original_file_mp4" },
@@ -40,7 +40,7 @@ describe "Transcoding" do
40
40
  when 'text/rtf'
41
41
  DocumentDerivatives.create(self, source: :original_file,
42
42
  outputs: [
43
- { label: :preservation, format: 'odf', url: "#{uri}/original_file_preservation" },
43
+ { label: :preservation, format: 'odt', url: "#{uri}/original_file_preservation" },
44
44
  { label: :access, format: 'pdf', url: "#{uri}/original_file_access" },
45
45
  { label: :thumnail, format: 'jpg', url: "#{uri}/original_file_thumbnail" }])
46
46
  when 'application/msword'
@@ -52,21 +52,21 @@ describe "Transcoding" do
52
52
  when 'application/vnd.ms-excel'
53
53
  DocumentDerivatives.create(self, source: :original_file,
54
54
  outputs: [
55
- { label: :preservation, format: 'xslx', url: "#{uri}/original_file_preservation" },
55
+ { label: :preservation, format: 'xlsx', url: "#{uri}/original_file_preservation" },
56
56
  { label: :access, format: 'pdf', url: "#{uri}/original_file_access" },
57
57
  { label: :thumnail, format: 'jpg', url: "#{uri}/original_file_thumbnail" }])
58
58
  when 'image/tiff'
59
59
  Jpeg2kImageDerivatives.create(self, source: :original_file,
60
60
  outputs: [
61
- { label: :resized, recipe: :default, processor: 'jpeg2k_image', resize: "600x600>", url: "#{uri}/resized" },
62
- { label: :config_lookup, recipe: :default, processor: 'jpeg2k_image', url: "#{uri}/config_lookup" },
63
- { label: :string_recipe, recipe: '-quiet', processor: 'jpeg2k_image', url: "#{uri}/string_recipe" },
64
- { label: :diy, processor: 'jpeg2k_image', url: "#{uri}/original_file_diy" }])
61
+ { label: :resized, format: 'jp2', recipe: :default, processor: 'jpeg2k_image', resize: "600x600>", url: "#{uri}/resized" },
62
+ { label: :config_lookup, format: 'jp2', recipe: :default, processor: 'jpeg2k_image', url: "#{uri}/config_lookup" },
63
+ { label: :string_recipe, format: 'jp2', recipe: '-jp2_space sRGB', processor: 'jpeg2k_image', url: "#{uri}/string_recipe" },
64
+ { label: :diy, format: 'jp2', processor: 'jpeg2k_image', url: "#{uri}/original_file_diy" }])
65
65
  when 'image/x-adobe-dng'
66
66
  ImageDerivatives.create(self, source: :original_file,
67
67
  outputs: [
68
- { label: :access, size: "300x300>", format: 'jpg', processor: :raw_image },
69
- { label: :thumb, size: "100x100>", format: 'jpg', processor: :raw_image }])
68
+ { label: :access, size: "300x300>", format: 'jpg', processor: :raw_image, url: "#{uri}/original_file_access" },
69
+ { label: :thumb, size: "100x100>", format: 'jpg', processor: :raw_image, url: "#{uri}/original_file_thumb" }])
70
70
  end
71
71
  end
72
72
  end
@@ -82,6 +82,7 @@ describe "Transcoding" do
82
82
  let(:file) do
83
83
  GenericFile.new(mime_type_from_fits: 'image/png') do |f|
84
84
  f.original_file.content = attachment
85
+ f.original_file.mime_type = f.mime_type_from_fits
85
86
  f.save!
86
87
  end
87
88
  end
@@ -100,36 +101,37 @@ describe "Transcoding" do
100
101
  end
101
102
  end
102
103
 
103
- describe "with an attached RAW image", unless: in_travis? do
104
+ describe "with an attached RAW image", requires_imagemagick: true do
104
105
  let(:filename) { File.expand_path('../../fixtures/test.dng', __FILE__) }
105
106
  let(:attachment) { File.open(filename) }
106
107
  let(:file) do
107
108
  GenericFile.new(mime_type_from_fits: 'image/x-adobe-dng') do |f|
108
109
  f.original_file.content = attachment
109
- f.original_file.mime_type = 'image/x-adobe-dng'
110
+ f.original_file.mime_type = f.mime_type_from_fits
110
111
  f.save!
111
112
  end
112
113
  end
113
114
 
114
115
  it "transcodes" do
115
- expect(file.attached_files.key?('access')).to be_falsey
116
- expect(file.attached_files.key?('thumb')).to be_falsey
116
+ expect(file.attached_files.key?('original_file_access')).to be_falsey
117
+ expect(file.attached_files.key?('original_file_thumb')).to be_falsey
117
118
 
118
119
  file.create_derivatives(filename)
119
- expect(file.attached_files['access']).to have_content
120
- expect(file.attached_files['access'].mime_type).to eq('image/jpeg')
121
- expect(file.attached_files['thumb']).to have_content
122
- expect(file.attached_files['thumb'].mime_type).to eq('image/jpeg')
120
+ file.reload
121
+ expect(file.attached_files['original_file_access']).to have_content
122
+ expect(file.attached_files['original_file_access'].mime_type).to eq('image/jpeg')
123
+ expect(file.attached_files['original_file_thumb']).to have_content
124
+ expect(file.attached_files['original_file_thumb'].mime_type).to eq('image/jpeg')
123
125
  end
124
126
  end
125
127
 
126
- describe "with an attached pdf", unless: in_travis? do
128
+ describe "with an attached pdf", requires_imagemagick: true do
127
129
  let(:filename) { File.expand_path('../../fixtures/test.pdf', __FILE__) }
128
130
  let(:attachment) { File.open(filename) }
129
131
  let(:file) do
130
132
  GenericFile.new(mime_type_from_fits: 'application/pdf') do |t|
131
133
  t.original_file.content = attachment
132
- t.original_file.mime_type = 'application/pdf'
134
+ t.original_file.mime_type = t.mime_type_from_fits
133
135
  t.save
134
136
  end
135
137
  end
@@ -145,12 +147,13 @@ describe "Transcoding" do
145
147
  end
146
148
  end
147
149
 
148
- describe "with an attached audio", unless: in_travis? do
150
+ describe "with an attached audio", requires_ffmpeg: true do
149
151
  let(:filename) { File.expand_path('../../fixtures/piano_note.wav', __FILE__) }
150
152
  let(:attachment) { File.open(filename) }
151
153
  let(:file) do
152
- GenericFile.new(mime_type_from_fits: 'audio/wav').tap do |t|
154
+ GenericFile.new(mime_type_from_fits: 'audio/x-wav').tap do |t|
153
155
  t.original_file.content = attachment
156
+ t.original_file.mime_type = t.mime_type_from_fits
154
157
  t.save
155
158
  end
156
159
  end
@@ -165,11 +168,11 @@ describe "Transcoding" do
165
168
  end
166
169
  end
167
170
 
168
- describe "when the source datastrem has an unknown mime_type", unless: in_travis? do
171
+ describe "when the source datastrem has an unknown mime_type", requires_ffmpeg: true do
169
172
  let(:filename) { File.expand_path('../../fixtures/piano_note.wav', __FILE__) }
170
173
  let(:attachment) { File.open(filename) }
171
174
  let(:file) do
172
- GenericFile.new(mime_type_from_fits: 'audio/wav').tap do |t|
175
+ GenericFile.new(mime_type_from_fits: 'audio/x-wav').tap do |t|
173
176
  t.original_file.content = attachment
174
177
  t.original_file.mime_type = 'audio/vnd.wav'
175
178
  t.save
@@ -185,13 +188,14 @@ describe "Transcoding" do
185
188
  end
186
189
  end
187
190
 
188
- describe "with an attached video", unless: in_travis? do
191
+ describe "with an attached video", requires_ffmpeg: true do
189
192
  let(:filename) { File.expand_path('../../fixtures/countdown.avi', __FILE__) }
190
193
  let(:attachment) { File.open(filename) }
191
194
  let(:file) do
192
- GenericFile.create(mime_type_from_fits: 'video/avi') do |t|
195
+ GenericFile.create(mime_type_from_fits: 'video/x-msvideo') do |t|
193
196
  t.original_file.content = attachment
194
- t.original_file.mime_type = 'video/msvideo'
197
+ t.original_file.mime_type = t.mime_type_from_fits
198
+ t.save
195
199
  end
196
200
  end
197
201
 
@@ -220,12 +224,14 @@ describe "Transcoding" do
220
224
  end
221
225
  end
222
226
 
223
- describe "with an attached Powerpoint", unless: in_travis? do
227
+ describe "with an attached Powerpoint", requires_libreoffice: true do
224
228
  let(:filename) { File.expand_path('../../fixtures/FlashPix.ppt', __FILE__) }
225
229
  let(:attachment) { File.open(filename) }
226
230
  let(:file) do
227
231
  GenericFile.create(mime_type_from_fits: 'application/vnd.ms-powerpoint') do |t|
228
232
  t.original_file.content = attachment
233
+ t.original_file.mime_type = t.mime_type_from_fits
234
+ t.save
229
235
  end
230
236
  end
231
237
 
@@ -241,12 +247,13 @@ describe "Transcoding" do
241
247
  end
242
248
  end
243
249
 
244
- describe "with an attached rich text format", unless: in_travis? do
250
+ describe "with an attached rich text format", requires_libreoffice: true do
245
251
  let(:filename) { File.expand_path('../../fixtures/sample.rtf', __FILE__) }
246
252
  let(:attachment) { File.open(filename) }
247
253
  let(:file) do
248
254
  GenericFile.new(mime_type_from_fits: 'text/rtf').tap do |t|
249
255
  t.original_file.content = attachment
256
+ t.original_file.mime_type = t.mime_type_from_fits
250
257
  t.save
251
258
  end
252
259
  end
@@ -263,14 +270,14 @@ describe "Transcoding" do
263
270
  end
264
271
  end
265
272
 
266
- describe "with an attached word doc format", unless: in_travis? do
273
+ describe "with an attached word doc format", requires_libreoffice: true do
267
274
  let(:filename) { File.expand_path('../../fixtures/test.doc', __FILE__) }
268
275
  let(:attachment) { File.open(filename) }
269
276
 
270
277
  let(:file) do
271
278
  GenericFile.new(mime_type_from_fits: 'application/msword').tap do |t|
272
279
  t.original_file.content = attachment
273
- t.original_file.mime_type = 'application/msword'
280
+ t.original_file.mime_type = t.mime_type_from_fits
274
281
  t.save
275
282
  end
276
283
  end
@@ -287,14 +294,14 @@ describe "Transcoding" do
287
294
  end
288
295
  end
289
296
 
290
- describe "with an attached excel format", unless: in_travis? do
297
+ describe "with an attached excel format", requires_libreoffice: true do
291
298
  let(:filename) { File.expand_path('../../fixtures/test.xls', __FILE__) }
292
299
  let(:attachment) { File.open(filename) }
293
300
 
294
301
  let(:file) do
295
302
  GenericFile.new(mime_type_from_fits: 'application/vnd.ms-excel').tap do |t|
296
303
  t.original_file.content = attachment
297
- t.original_file.mime_type = 'application/vnd.ms-excel'
304
+ t.original_file.mime_type = t.mime_type_from_fits
298
305
  t.save
299
306
  end
300
307
  end
@@ -311,13 +318,14 @@ describe "Transcoding" do
311
318
  end
312
319
  end
313
320
 
314
- describe "with an attached tiff", unless: in_travis? do
321
+ describe "with an attached tiff", requires_kdu_compress: true do
315
322
  let(:filename) { File.expand_path('../../fixtures/test.tif', __FILE__) }
316
323
  let(:attachment) { File.open(filename) }
317
324
 
318
325
  let(:file) do
319
326
  GenericFile.new(mime_type_from_fits: 'image/tiff').tap do |t|
320
327
  t.original_file.content = attachment
328
+ t.original_file.mime_type = t.mime_type_from_fits
321
329
  t.save
322
330
  end
323
331
  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: 3.2.1
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-21 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -199,6 +199,7 @@ files:
199
199
  - lib/color_profiles/license.txt
200
200
  - lib/color_profiles/sRGB_IEC61966-2-1_no_black_scaling.icc
201
201
  - lib/hydra/derivatives.rb
202
+ - lib/hydra/derivatives/audio_encoder.rb
202
203
  - lib/hydra/derivatives/config.rb
203
204
  - lib/hydra/derivatives/io_decorator.rb
204
205
  - lib/hydra/derivatives/logger.rb
@@ -223,6 +224,7 @@ files:
223
224
  - lib/hydra/derivatives/runners/pdf_derivatives.rb
224
225
  - lib/hydra/derivatives/runners/runner.rb
225
226
  - lib/hydra/derivatives/runners/video_derivatives.rb
227
+ - lib/hydra/derivatives/services/capability_service.rb
226
228
  - lib/hydra/derivatives/services/mime_type_service.rb
227
229
  - lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb
228
230
  - lib/hydra/derivatives/services/persist_output_file_service.rb
@@ -271,6 +273,7 @@ files:
271
273
  - spec/services/retrieve_source_file_service_spec.rb
272
274
  - spec/services/tempfile_service_spec.rb
273
275
  - spec/spec_helper.rb
276
+ - spec/units/audio_encoder_spec.rb
274
277
  - spec/units/config_spec.rb
275
278
  - spec/units/derivatives_spec.rb
276
279
  - spec/units/io_decorator_spec.rb
@@ -296,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
296
299
  version: '0'
297
300
  requirements: []
298
301
  rubyforge_project:
299
- rubygems_version: 2.6.4
302
+ rubygems_version: 2.6.10
300
303
  signing_key:
301
304
  specification_version: 4
302
305
  summary: Derivative generation plugin for hydra
@@ -328,6 +331,7 @@ test_files:
328
331
  - spec/services/retrieve_source_file_service_spec.rb
329
332
  - spec/services/tempfile_service_spec.rb
330
333
  - spec/spec_helper.rb
334
+ - spec/units/audio_encoder_spec.rb
331
335
  - spec/units/config_spec.rb
332
336
  - spec/units/derivatives_spec.rb
333
337
  - spec/units/io_decorator_spec.rb