hyrax-active_encode 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1af71cc4821101302f9d3ea4e22d2e484a07175
4
+ data.tar.gz: ab0cdbf961034b7d5e37d77f1fa50335d851c248
5
+ SHA512:
6
+ metadata.gz: dc3adf07cc77a543574cb40c1a3e5133c0445517abfb34d3aabdb1870b9d5159a226309097f6de8e2374d8579530c6c2b6ab1e4b4006d1db910d17a539f19e5b
7
+ data.tar.gz: 31ec954ee8b310d397bba9d47986c39bb511819feff9841b3cfced1a05d0725293d7df826414547758bd18aef49281b2311ebdefce7c9bbace81a00f6830ed78
@@ -0,0 +1,115 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # legacy needed for phantomjs
10
+ - image: circleci/ruby:2.5.1-node-browsers-legacy
11
+ - image: circleci/redis:4
12
+ - image: ualbertalib/docker-fcrepo4:4.7
13
+ environment:
14
+ CATALINA_OPTS: "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
15
+ - image: solr:7
16
+ command: bin/solr -cloud -noprompt -f -p 8985
17
+
18
+ # Specify service dependencies here if necessary
19
+ # CircleCI maintains a library of pre-built images
20
+ # documented at https://circleci.com/docs/2.0/circleci-images/
21
+ # - image: circleci/postgres:9.4
22
+
23
+ working_directory: ~/repo
24
+ parallelism: 2
25
+
26
+ environment:
27
+ RAILS_ENV: test
28
+ RACK_ENV: test
29
+ FCREPO_TEST_PORT: 8080/fcrepo
30
+ BUNDLE_JOBS: 4
31
+ BUNDLE_RETRY: 3
32
+ NOKOGIRI_USE_SYSTEM_LIBRARIES: true
33
+ ENGINE_CART_RAILS_OPTIONS: --skip-git --skip-bundle --skip-listen --skip-spring --skip-yarn --skip-keeps --skip-coffee --skip-puma --skip-test
34
+ COVERALLS_PARALLEL: true
35
+
36
+ steps:
37
+ - restore_cache:
38
+ keys:
39
+ - source-v1-{{ .Branch }}-{{ .Revision }}
40
+
41
+ - checkout
42
+
43
+ - save_cache:
44
+ key: source-v1-{{ .Branch }}-{{ .Revision }}
45
+ paths:
46
+ - ".git"
47
+
48
+ # BUNDLE_PATH is unset to allow for `bundle config path` to take precedence.
49
+ - run:
50
+ name: Extra environment setup
51
+ command: |
52
+ echo 'unset BUNDLE_PATH' >> $BASH_ENV
53
+
54
+ - restore_cache:
55
+ keys:
56
+ - v1-internal-test-app-{{ .Branch }}-{{ checksum "hyrax-active_encode.gemspec" }}
57
+
58
+ # Download and cache dependencies
59
+ - restore_cache:
60
+ keys:
61
+ - v1-dependencies-{{ .Branch }}-{{ checksum "hyrax-active_encode.gemspec" }}
62
+ - v1-dependencies-{{ .Branch }}
63
+ - v1-dependencies-
64
+
65
+ - run:
66
+ name: Install dependencies
67
+ command: |
68
+ gem update --system
69
+ gem update bundler
70
+ bundle config path $CIRCLE_WORKING_DIRECTORY/vendor/bundle
71
+ bundle install
72
+
73
+ - run:
74
+ name: Call Rubocop
75
+ command: bundle exec rubocop
76
+
77
+ - run:
78
+ name: Generate test app, ensure top-level Gemfile.lock is valid
79
+ command: |
80
+ [ -e ./.internal_test_app ] || bundle exec rake engine_cart:generate
81
+
82
+ - save_cache:
83
+ paths:
84
+ - ./.internal_test_app
85
+ key: v1-internal-test-app-{{ .Branch }}-{{ checksum "hyrax-active_encode.gemspec" }}
86
+
87
+ - run:
88
+ name: Load config into SolrCloud
89
+ command: |
90
+ cd .internal_test_app/solr/config
91
+ zip -1 -r solr_hyrax_config.zip ./*
92
+ curl -H "Content-type:application/octet-stream" --data-binary @solr_hyrax_config.zip "http://localhost:8985/solr/admin/configs?action=UPLOAD&name=hyrax"
93
+ curl -H 'Content-type: application/json' http://localhost:8985/api/collections/ -d '{create: {name: hydra-test, config: hyrax, numShards: 1}}'
94
+
95
+ - run:
96
+ name: Run rspec in parallel
97
+ command: |
98
+ mkdir /tmp/test-results
99
+ bundle exec rspec $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
100
+
101
+ - run:
102
+ name: Clean dependencies
103
+ command: bundle clean
104
+
105
+ - save_cache:
106
+ paths:
107
+ - ./vendor/bundle
108
+ key: v1-dependencies-{{ .Branch }}-{{ checksum "hyrax-active_encode.gemspec" }}
109
+
110
+ # collect reports
111
+ - store_test_results:
112
+ path: /tmp/test-results
113
+ - store_artifacts:
114
+ path: /tmp/test-results
115
+ destination: test-results
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ Gemfile.lock
5
+ .internal_test_app
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ inherit_gem:
2
+ bixby: bixby_default.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.3
6
+ DisplayCopNames: true
7
+
8
+ Naming/FileName:
9
+ Exclude:
10
+ - 'Gemfile'
11
+ - 'hyrax-active_encode.gemspec'
12
+
13
+ Bundler/DuplicatedGem:
14
+ Exclude:
15
+ - 'Gemfile'
16
+
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - 'spec/models/file_set_spec.rb'
20
+ - 'spec/services/active_encode_derivative_service_spec.rb'
21
+ - 'spec/services/derivative_service_spec.rb'
22
+ - 'spec/services/default_option_service_spec.rb'
23
+ - 'spec/services/persist_active_encode_derivatives_spec.rb'
24
+
25
+ RSpec/ExampleLength:
26
+ Exclude:
27
+ - 'spec/services/default_option_service_spec.rb'
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ dist: trusty
3
+
4
+ cache:
5
+ bundler: true
6
+
7
+ before_install:
8
+ - gem update --system
9
+ - gem install bundler
10
+
11
+ rvm:
12
+ - 2.5.0
13
+
14
+ env:
15
+ global:
16
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
17
+ - ENGINE_CART_RAILS_OPTIONS='--skip-git --skip-bundle --skip-listen --skip-spring --skip-yarn --skip-keeps --skip-coffee --skip-puma --skip-test'
18
+ # Travis should check every minor version in a range of supported versions, because
19
+ # rails does not follow sem-ver conventions, see http://guides.rubyonrails.org/maintenance_policy.html
20
+ # It should be sufficient to test only the latest of the patch versions for a minor version, they
21
+ # should be compatible across patch versions (only bug fixes are released in patch versions).
22
+ matrix:
23
+ - "RAILS_VERSION=5.1.4"
24
+
data/Gemfile ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
+
5
+ # Declare your gem's dependencies in hyrax-active_encode.gemspec.
6
+ # Bundler will treat runtime dependencies like base dependencies, and
7
+ # development dependencies will be added by default to the :development group.
8
+ gemspec
9
+
10
+ # Declare any dependencies that are still in development here instead of in
11
+ # your gemspec. These might include edge Rails or gems from your path or
12
+ # Git. Remember to move these dependencies to your gemspec before releasing
13
+ # your gem to rubygems.org.
14
+
15
+ # To use a debugger
16
+ # gem 'byebug', group: [:development, :test]
17
+ # BEGIN ENGINE_CART BLOCK
18
+ # engine_cart: 2.0.1
19
+ # engine_cart stanza: 0.10.0
20
+ # the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
21
+ file = File.expand_path('Gemfile', ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path('.internal_test_app', File.dirname(__FILE__)))
22
+ if File.exist?(file)
23
+ begin
24
+ eval_gemfile file
25
+ rescue Bundler::GemfileError => e
26
+ Bundler.ui.warn '[EngineCart] Skipping Rails application dependencies:'
27
+ Bundler.ui.warn e.message
28
+ end
29
+ else
30
+ Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"
31
+
32
+ if ENV['RAILS_VERSION']
33
+ if ENV['RAILS_VERSION'] == 'edge'
34
+ gem 'rails', github: 'rails/rails'
35
+ ENV['ENGINE_CART_RAILS_OPTIONS'] = '--edge --skip-turbolinks'
36
+ else
37
+ gem 'rails', ENV['RAILS_VERSION']
38
+ end
39
+ end
40
+ end
41
+ # END ENGINE_CART BLOCK
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # hyrax-active_encode
2
+ Hyrax plugin to enable audiovisual derivative generation through active_encode
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'rdoc/task'
9
+
10
+ RDoc::Task.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'Hyrax::ActiveEncode'
13
+ rdoc.options << '--line-numbers'
14
+ rdoc.rdoc_files.include('README.md')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ # APP_RAKEFILE = File.expand_path(".internal_test_app/Rakefile", __dir__)
19
+ # load 'rails/tasks/engine.rake'
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+ require 'bundler/gem_tasks'
24
+
25
+ require 'rake/testtask'
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+ require 'rspec/core/rake_task'
34
+ require 'engine_cart/rake_task'
35
+ require 'rubocop/rake_task'
36
+
37
+ task default: :ci
38
+
39
+ desc 'Run style checker'
40
+ RuboCop::RakeTask.new(:rubocop) do |task|
41
+ task.fail_on_error = true
42
+ end
43
+
44
+ RSpec::Core::RakeTask.new(:spec)
45
+
46
+ task :spec_with_server do
47
+ require 'solr_wrapper' # necessary for rake_support to work
48
+ require 'fcrepo_wrapper' # necessary for rake_support to work
49
+ require 'active_fedora/rake_support'
50
+
51
+ ENV['environment'] = "test"
52
+ with_test_server do
53
+ Rake::Task['spec'].invoke
54
+ end
55
+ end
56
+
57
+ desc "CI build"
58
+ task ci: [:rubocop, "engine_cart:generate", :spec_with_server]
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module ActiveEncode
4
+ module IndexesFileMetadata
5
+ def generate_solr_document
6
+ super.tap do |solr_doc|
7
+ solr_doc['derivatives_metadata_ssi'] = object.derivatives_metadata.to_json
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyrax
4
+ module ActiveEncode
5
+ class ActiveEncodeIndexer < Hyrax::FileSetIndexer
6
+ include Hyrax::ActiveEncode::IndexesFileMetadata
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ require 'active_fedora/with_metadata/external_file_uri_schema'
3
+
4
+ module Hyrax
5
+ module ActiveEncode
6
+ module FileSetBehavior
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ # Is this too late? Has the ActiveFedora::File metadata schema been frozen already?
11
+ ActiveFedora::WithMetadata::DefaultMetadataClassFactory.file_metadata_schemas += [ActiveFedora::WithMetadata::ExternalFileUriSchema]
12
+
13
+ # The following doesn't work because through isn't allowed on directly_contains even though it is on directly_contains_one
14
+ # directly_contains :derivatives, through: :files, type: ::RDF::URI('http://pcdm.org/use#ServiceFile'), class_name: 'Hydra::PCDM::File'
15
+ end
16
+
17
+ def build_derivative
18
+ # This only works when the file_set has already been saved
19
+ files.build.tap do |file|
20
+ file.metadata_node.type << ::RDF::URI('http://pcdm.org/use#ServiceFile')
21
+ end
22
+ end
23
+
24
+ def derivatives
25
+ filter_files_by_type(::RDF::URI('http://pcdm.org/use#ServiceFile'))
26
+ end
27
+
28
+ def derivatives_metadata
29
+ derivatives.collect { |f| { id: f.id, label: f.label.first, external_file_uri: f.external_file_uri.first } }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+ require 'active_encode'
3
+
4
+ module Hyrax
5
+ module ActiveEncode
6
+ class ActiveEncodeDerivativeService < Hyrax::DerivativeService
7
+ attr_accessor :encode_class, :options_service_class
8
+
9
+ def initialize(file_set, encode_class: ::ActiveEncode::Base, options_service_class: DefaultOptionService, local_streaming: true)
10
+ super(file_set)
11
+ @encode_class = encode_class
12
+ @options_service_class = options_service_class
13
+ @local_streaming = local_streaming
14
+ end
15
+
16
+ def create_derivatives(filename)
17
+ options = options_service_class.call(@file_set)
18
+ options.each do |option|
19
+ option[:file_set_id] = file_set.id
20
+ option[:local_streaming] = true if local_streaming?
21
+ end
22
+ Hydra::Derivatives::ActiveEncodeDerivatives.create(filename, outputs: options, encode_class: @encode_class)
23
+ end
24
+
25
+ # What should this return?
26
+ def derivative_url(file_label)
27
+ derivative = file_set.derivatives.find { |d| d.label.first == file_label }
28
+ derivative.nil? ? nil : derivative.external_file_uri.first
29
+ end
30
+
31
+ def valid?
32
+ supported_mime_types.include?(file_set.mime_type) && file_set.class.include?(Hyrax::ActiveEncode::FileSetBehavior)
33
+ end
34
+
35
+ # TODO: Implement this?
36
+ def cleanup_derivatives; end
37
+
38
+ def local_streaming?
39
+ @local_streaming == true
40
+ end
41
+
42
+ private
43
+
44
+ def supported_mime_types
45
+ file_set.class.audio_mime_types + file_set.class.video_mime_types
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require 'active_encode'
3
+
4
+ module Hyrax
5
+ module ActiveEncode
6
+ class DefaultOptionService
7
+ # Returns default audio/video output options for ActiveEncode.
8
+ # @param fileset the data to be persisted
9
+ # @return an array of hashes of output options for audio/video
10
+ def self.call(file_set)
11
+ # Defaults adapted from hydra-derivatives
12
+ audio_encoder = Hydra::Derivatives::AudioEncoder.new
13
+ if file_set.audio?
14
+ [{ outputs: [{ label: 'mp3', extension: 'mp3' },
15
+ { label: 'ogg', extension: 'ogg' }] }]
16
+ elsif file_set.video?
17
+ [{ outputs: [{ label: 'mp4', extension: 'mp4', ffmpeg_opt: "-s 320x240 -g 30 -b:v 345k -ac 2 -ab 96k -ar 44100 -vcodec libx264 -acodec #{audio_encoder.audio_encoder}" },
18
+ { label: 'webm', extension: 'webm', ffmpeg_opt: "-s 320x240 -g 30 -b:v 345k -ac 2 -ab 96k -ar 44100 -vcodec libvpx -acodec libvorbis" }] }]
19
+ else
20
+ []
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyrax
4
+ module ActiveEncode
5
+ class PersistActiveEncodeDerivatives
6
+ # @param [ActiveEncode::Output] output the output from the active_encode adapter
7
+ # @param [Hash] directives directions which can be used to determine where to persist to.
8
+ # @option directives [String] local_streaming flag for copying to Hyrax derivative directory
9
+ # @option directives [String] file_set_id the id of the file set to add the derivative
10
+ def self.call(output, directives)
11
+ file_set = ActiveFedora::Base.find(directives[:file_set_id])
12
+ if directives[:local_streaming]
13
+ old_url = output.url
14
+ move_derivative(output, file_set)
15
+ output.url = Hyrax::Engine.routes.url_helpers.download_path(file_set, file: File.basename(old_url))
16
+ end
17
+ create_pcdm_file(output, file_set)
18
+ end
19
+
20
+ def self.create_pcdm_file(output, file_set)
21
+ pcdm_file = file_set.build_derivative
22
+ pcdm_file.label = output.label
23
+ pcdm_file.external_file_uri = output.url
24
+ pcdm_file.content = ''
25
+ file_set.save!
26
+ end
27
+ private_class_method :create_pcdm_file
28
+
29
+ def self.move_derivative(output, file_set)
30
+ output_uri = URI(output.url)
31
+ move_path = Hyrax::DerivativePath.derivative_path_for_reference(file_set.id, File.basename(output_uri.path))
32
+ FileUtils.mkdir_p File.dirname(move_path)
33
+ if output_uri.scheme == "file"
34
+ FileUtils.mv output_uri.path, move_path
35
+ else
36
+ # Read from remote url and persist to derivative_path
37
+ open(output_uri.to_s) { |io| IO.copy_stream(io, File.open(move_path, 'wb')) }
38
+ end
39
+ move_path
40
+ end
41
+ private_class_method :move_derivative
42
+ end
43
+ end
44
+ end
data/bin/rails ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ # This command will automatically be run when you run "rails" with Rails gems
4
+ # installed from the root of your application.
5
+
6
+ ENGINE_ROOT = File.expand_path('..', __dir__)
7
+ ENGINE_PATH = File.expand_path('../lib/hyrax/active_encode/engine', __dir__)
8
+ # APP_PATH = File.expand_path('../.internal_test_app/config/application', __dir__)
9
+
10
+ # Set up gems listed in the Gemfile.
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
12
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
13
+
14
+ require 'rails/all'
15
+ require 'rails/engine/commands'
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
3
+
4
+ # Maintain your gem's version:
5
+ require "hyrax/active_encode/version"
6
+
7
+ # Describe your gem and declare its dependencies:
8
+ Gem::Specification.new do |s|
9
+ s.name = "hyrax-active_encode"
10
+ s.version = Hyrax::ActiveEncode::VERSION
11
+ s.authors = ["Chris Colvard", "Brian Keese", "Ying Feng", "Phuong Dinh", "Carrick Rogers"]
12
+ s.email = ["cjcolvar@indiana.edu", "bkeese@indiana.edu", "yingfeng@iu.edu", "phuongdh@gmail.com", "carrickr@umich.edu"]
13
+ s.summary = "Hyrax plugin to enable audiovisual derivative generation through active_encode"
14
+ s.description = "Hyrax plugin to enable audiovisual derivative generation through active_encode"
15
+ s.license = 'Apache-2.0'
16
+
17
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ s.add_dependency "active_encode", "~> 0.4"
22
+ s.add_dependency "hyrax", "~> 2.1"
23
+
24
+ s.add_development_dependency 'bixby'
25
+ s.add_development_dependency 'coffee-rails'
26
+ s.add_development_dependency 'database_cleaner'
27
+ s.add_development_dependency 'engine_cart', '~> 2.0'
28
+ s.add_development_dependency 'fcrepo_wrapper'
29
+ s.add_development_dependency "rspec-rails", "~> 3.8"
30
+ s.add_development_dependency 'solr_wrapper'
31
+ s.add_development_dependency 'webmock'
32
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ # These are the default properties defined on a resource that has WithMetadata
3
+ # added to it. This is most commonly used with ActiveFedora::File, when we want
4
+ # to add rdf triples to a non-rdf resource and have them persisted.
5
+ module ActiveFedora::WithMetadata
6
+ class ExternalFileUriSchema < ActiveTriples::Schema
7
+ # Don't cast to keep values as RDF::URI instead of RDF::Resource
8
+ property :external_file_uri, predicate: ::RDF::Vocab::EBUCore.locator, cast: false do |index|
9
+ index.as :stored_searchable
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'rails/generators'
3
+
4
+ module Hyrax
5
+ module ActiveEncode
6
+ class InstallGenerator < Rails::Generators::Base
7
+ source_root "../templates"
8
+
9
+ def enhance_file_set
10
+ insert_into_file 'app/models/file_set.rb', after: 'include ::Hyrax::FileSetBehavior' do
11
+ "\n" \
12
+ " include Hyrax::ActiveEncode::FileSetBehavior\n" \
13
+ " self.indexer = Hyrax::ActiveEncode::ActiveEncodeIndexer"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'active_encode'
3
+
4
+ module Hyrax
5
+ module ActiveEncode
6
+ class Engine < ::Rails::Engine
7
+ isolate_namespace Hyrax::ActiveEncode
8
+
9
+ initializer "hyrax.active_encode.prepend_derivative_service" do
10
+ Hyrax::DerivativeService.services = [Hyrax::ActiveEncode::ActiveEncodeDerivativeService] + Hyrax::DerivativeService.services
11
+ end
12
+
13
+ initializer "hyrax.active_encode.ffmpeg_adapter" do
14
+ ::ActiveEncode::Base.engine_adapter = :ffmpeg
15
+ end
16
+
17
+ initializer "hyrax.active_encode.output_service" do
18
+ Hydra::Derivatives::ActiveEncodeDerivatives.output_file_service = Hyrax::ActiveEncode::PersistActiveEncodeDerivatives
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module ActiveEncode
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ require "hyrax/active_encode/engine"
3
+
4
+ module Hyrax
5
+ module ActiveEncode
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :hyrax_active_encode do
4
+ # # Task goes here
5
+ # end
metadata ADDED
@@ -0,0 +1,215 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hyrax-active_encode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Colvard
8
+ - Brian Keese
9
+ - Ying Feng
10
+ - Phuong Dinh
11
+ - Carrick Rogers
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2018-10-01 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: active_encode
19
+ requirement: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "~>"
22
+ - !ruby/object:Gem::Version
23
+ version: '0.4'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '0.4'
31
+ - !ruby/object:Gem::Dependency
32
+ name: hyrax
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - "~>"
36
+ - !ruby/object:Gem::Version
37
+ version: '2.1'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '2.1'
45
+ - !ruby/object:Gem::Dependency
46
+ name: bixby
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ type: :development
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ - !ruby/object:Gem::Dependency
60
+ name: coffee-rails
61
+ requirement: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: database_cleaner
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ - !ruby/object:Gem::Dependency
88
+ name: engine_cart
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '2.0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '2.0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: fcrepo_wrapper
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ - !ruby/object:Gem::Dependency
116
+ name: rspec-rails
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '3.8'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '3.8'
129
+ - !ruby/object:Gem::Dependency
130
+ name: solr_wrapper
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: webmock
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ description: Hyrax plugin to enable audiovisual derivative generation through active_encode
158
+ email:
159
+ - cjcolvar@indiana.edu
160
+ - bkeese@indiana.edu
161
+ - yingfeng@iu.edu
162
+ - phuongdh@gmail.com
163
+ - carrickr@umich.edu
164
+ executables: []
165
+ extensions: []
166
+ extra_rdoc_files: []
167
+ files:
168
+ - ".circleci/config.yml"
169
+ - ".gitignore"
170
+ - ".rspec"
171
+ - ".rubocop.yml"
172
+ - ".travis.yml"
173
+ - Gemfile
174
+ - LICENSE
175
+ - README.md
176
+ - Rakefile
177
+ - app/indexers/concerns/hyrax/active_encode/indexes_file_metadata.rb
178
+ - app/indexers/hyrax/active_encode/active_encode_indexer.rb
179
+ - app/models/concerns/hyrax/active_encode/file_set_behavior.rb
180
+ - app/services/hyrax/active_encode/active_encode_derivative_service.rb
181
+ - app/services/hyrax/active_encode/default_option_service.rb
182
+ - app/services/hyrax/active_encode/persist_active_encode_derivatives.rb
183
+ - bin/rails
184
+ - hyrax-active_encode.gemspec
185
+ - lib/active_fedora/with_metadata/external_file_uri_schema.rb
186
+ - lib/generators/hyrax/active_encode/install_generator.rb
187
+ - lib/hyrax/active_encode.rb
188
+ - lib/hyrax/active_encode/engine.rb
189
+ - lib/hyrax/active_encode/version.rb
190
+ - lib/tasks/hyrax/active_encode_tasks.rake
191
+ homepage:
192
+ licenses:
193
+ - Apache-2.0
194
+ metadata: {}
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ requirements: []
210
+ rubyforge_project:
211
+ rubygems_version: 2.6.14
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Hyrax plugin to enable audiovisual derivative generation through active_encode
215
+ test_files: []