active_encode 0.2 → 0.4

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -0
  3. data/README.md +1 -16
  4. data/active_encode.gemspec +4 -4
  5. data/app/jobs/active_encode/polling_job.rb +4 -4
  6. data/lib/active_encode/callbacks.rb +2 -21
  7. data/lib/active_encode/core.rb +1 -35
  8. data/lib/active_encode/engine_adapters.rb +1 -3
  9. data/lib/active_encode/engine_adapters/elastic_transcoder_adapter.rb +32 -28
  10. data/lib/active_encode/engine_adapters/ffmpeg_adapter.rb +243 -0
  11. data/lib/active_encode/engine_adapters/matterhorn_adapter.rb +64 -97
  12. data/lib/active_encode/engine_adapters/test_adapter.rb +0 -12
  13. data/lib/active_encode/engine_adapters/zencoder_adapter.rb +53 -44
  14. data/lib/active_encode/input.rb +6 -0
  15. data/lib/active_encode/output.rb +7 -0
  16. data/lib/active_encode/persistence.rb +1 -1
  17. data/lib/active_encode/polling.rb +2 -2
  18. data/lib/active_encode/status.rb +0 -3
  19. data/lib/active_encode/technical_metadata.rb +7 -0
  20. data/lib/active_encode/version.rb +1 -1
  21. data/spec/fixtures/ffmpeg/cancelled-id/error.log +0 -0
  22. data/spec/fixtures/ffmpeg/cancelled-id/input_metadata +90 -0
  23. data/spec/fixtures/ffmpeg/cancelled-id/pid +1 -0
  24. data/spec/fixtures/ffmpeg/cancelled-id/progress +11 -0
  25. data/spec/fixtures/ffmpeg/completed-id/error.log +0 -0
  26. data/spec/fixtures/ffmpeg/completed-id/input_metadata +102 -0
  27. data/spec/fixtures/ffmpeg/completed-id/output_metadata-high +90 -0
  28. data/spec/fixtures/ffmpeg/completed-id/output_metadata-low +90 -0
  29. data/spec/fixtures/ffmpeg/completed-id/pid +1 -0
  30. data/spec/fixtures/ffmpeg/completed-id/progress +11 -0
  31. data/spec/fixtures/ffmpeg/completed-id/video-high.mp4 +0 -0
  32. data/spec/fixtures/ffmpeg/completed-id/video-low.mp4 +0 -0
  33. data/spec/fixtures/ffmpeg/failed-id/error.log +1 -0
  34. data/spec/fixtures/ffmpeg/failed-id/input_metadata +90 -0
  35. data/spec/fixtures/ffmpeg/failed-id/pid +1 -0
  36. data/spec/fixtures/ffmpeg/failed-id/progress +11 -0
  37. data/spec/fixtures/ffmpeg/running-id/error.log +0 -0
  38. data/spec/fixtures/ffmpeg/running-id/input_metadata +90 -0
  39. data/spec/fixtures/ffmpeg/running-id/pid +1 -0
  40. data/spec/fixtures/ffmpeg/running-id/progress +11 -0
  41. data/spec/fixtures/fireworks.mp4 +0 -0
  42. data/spec/integration/elastic_transcoder_adapter_spec.rb +21 -12
  43. data/spec/integration/ffmpeg_adapter_spec.rb +120 -0
  44. data/spec/integration/matterhorn_adapter_spec.rb +30 -59
  45. data/spec/integration/zencoder_adapter_spec.rb +242 -22
  46. data/spec/shared_specs/engine_adapter_specs.rb +116 -16
  47. data/spec/units/core_spec.rb +31 -0
  48. data/spec/units/input_spec.rb +25 -0
  49. data/spec/units/output_spec.rb +28 -1
  50. data/spec/units/polling_job_spec.rb +10 -10
  51. metadata +51 -11
  52. data/lib/active_encode/engine_adapters/active_job_adapter.rb +0 -21
  53. data/lib/active_encode/engine_adapters/inline_adapter.rb +0 -47
  54. data/lib/active_encode/engine_adapters/shingoncoder_adapter.rb +0 -63
  55. data/spec/integration/shingoncoder_adapter_spec.rb +0 -170
@@ -125,4 +125,35 @@ describe ActiveEncode::Core do
125
125
  its(:state) { is_expected.not_to be nil }
126
126
  end
127
127
  end
128
+
129
+ describe '#new' do
130
+ before do
131
+ class DefaultOptionsEncode < ActiveEncode::Base
132
+ def self.default_options(_input_url)
133
+ { preset: 'video' }
134
+ end
135
+ end
136
+ end
137
+ after do
138
+ Object.send(:remove_const, :DefaultOptionsEncode)
139
+ end
140
+
141
+ let(:encode_class) { DefaultOptionsEncode }
142
+ let(:default_options) { { preset: 'video' } }
143
+ let(:options) { { output: [{label: 'high', ffmpeg_opt: "640x480" }] } }
144
+ let(:encode) { encode_class.new(nil, options) }
145
+ subject { encode.options }
146
+
147
+ it 'merges default options and options parameter' do
148
+ expect(subject).to include default_options
149
+ expect(subject).to include options
150
+ end
151
+
152
+ context 'with collisions' do
153
+ let(:options) { { preset: 'avalon' } }
154
+ it 'prefers options parameter' do
155
+ expect(subject[:preset]).to eq 'avalon'
156
+ end
157
+ end
158
+ end
128
159
  end
@@ -9,4 +9,29 @@ describe ActiveEncode::Input do
9
9
  it { is_expected.to respond_to(:width, :height, :frame_rate, :checksum,
10
10
  :audio_codec, :video_codec, :audio_bitrate, :video_bitrate) }
11
11
  end
12
+
13
+ describe '#valid?' do
14
+ let(:valid_input) do
15
+ described_class.new.tap do |obj|
16
+ obj.id = "1"
17
+ obj.url = "file:///tmp/video.mp4"
18
+ obj.created_at = Time.now
19
+ obj.updated_at = Time.now
20
+ end
21
+ end
22
+
23
+ it 'returns true when conditions met' do
24
+ expect(valid_input).to be_valid
25
+ end
26
+
27
+ it 'returns false when conditions not met' do
28
+ expect(valid_input.tap { |obj| obj.id = nil }).not_to be_valid
29
+ expect(valid_input.tap { |obj| obj.url = nil }).not_to be_valid
30
+ expect(valid_input.tap { |obj| obj.created_at = nil }).not_to be_valid
31
+ expect(valid_input.tap { |obj| obj.created_at = "today" }).not_to be_valid
32
+ expect(valid_input.tap { |obj| obj.updated_at = nil }).not_to be_valid
33
+ expect(valid_input.tap { |obj| obj.updated_at = "today" }).not_to be_valid
34
+ expect(valid_input.tap { |obj| obj.created_at = Time.now }).not_to be_valid
35
+ end
36
+ end
12
37
  end
@@ -4,9 +4,36 @@ describe ActiveEncode::Output do
4
4
  subject { described_class.new }
5
5
 
6
6
  describe 'attributes' do
7
- it { is_expected.to respond_to(:id, :url) }
7
+ it { is_expected.to respond_to(:id, :url, :label) }
8
8
  it { is_expected.to respond_to(:state, :errors, :created_at, :updated_at) }
9
9
  it { is_expected.to respond_to(:width, :height, :frame_rate, :checksum,
10
10
  :audio_codec, :video_codec, :audio_bitrate, :video_bitrate) }
11
11
  end
12
+
13
+ describe '#valid?' do
14
+ let(:valid_output) do
15
+ described_class.new.tap do |obj|
16
+ obj.id = "1"
17
+ obj.url = "file:///tmp/video.mp4"
18
+ obj.label = "HD"
19
+ obj.created_at = Time.now
20
+ obj.updated_at = Time.now
21
+ end
22
+ end
23
+
24
+ it 'returns true when conditions met' do
25
+ expect(valid_output).to be_valid
26
+ end
27
+
28
+ it 'returns false when conditions not met' do
29
+ expect(valid_output.tap { |obj| obj.id = nil }).not_to be_valid
30
+ expect(valid_output.tap { |obj| obj.url = nil }).not_to be_valid
31
+ expect(valid_output.tap { |obj| obj.label = nil }).not_to be_valid
32
+ expect(valid_output.tap { |obj| obj.created_at = nil }).not_to be_valid
33
+ expect(valid_output.tap { |obj| obj.created_at = "today" }).not_to be_valid
34
+ expect(valid_output.tap { |obj| obj.updated_at = nil }).not_to be_valid
35
+ expect(valid_output.tap { |obj| obj.updated_at = "today" }).not_to be_valid
36
+ expect(valid_output.tap { |obj| obj.created_at = Time.now }).not_to be_valid
37
+ end
38
+ end
12
39
  end
@@ -7,9 +7,9 @@ describe ActiveEncode::PollingJob do
7
7
  class PollingEncode < ActiveEncode::Base
8
8
  include ActiveEncode::Polling
9
9
  after_status_update ->(encode) { encode.history << "PollingEncode ran after_status_update" }
10
- after_error ->(encode) { encode.history << "PollingEncode ran after_error" }
10
+ after_failed ->(encode) { encode.history << "PollingEncode ran after_failed" }
11
11
  after_cancelled ->(encode) { encode.history << "PollingEncode ran after_cancelled" }
12
- after_complete ->(encode) { encode.history << "PollingEncode ran after_complete" }
12
+ after_completed ->(encode) { encode.history << "PollingEncode ran after_completed" }
13
13
 
14
14
  def history
15
15
  @history ||= []
@@ -32,12 +32,12 @@ describe ActiveEncode::PollingJob do
32
32
  poll.perform(encode)
33
33
  end
34
34
 
35
- context "with job in error" do
36
- let(:state) { :error }
35
+ context "with job failed" do
36
+ let(:state) { :failed }
37
37
 
38
- it "runs after_error" do
38
+ it "runs after_failed" do
39
39
  is_expected.to include("PollingEncode ran after_status_update")
40
- is_expected.to include("PollingEncode ran after_error")
40
+ is_expected.to include("PollingEncode ran after_failed")
41
41
  end
42
42
 
43
43
  it "does not re-enqueue itself" do
@@ -58,12 +58,12 @@ describe ActiveEncode::PollingJob do
58
58
  end
59
59
  end
60
60
 
61
- context "with job complete" do
62
- let(:state) { :complete }
61
+ context "with job completed" do
62
+ let(:state) { :completed }
63
63
 
64
- it "runs after_complete" do
64
+ it "runs after_completed" do
65
65
  is_expected.to include("PollingEncode ran after_status_update")
66
- is_expected.to include("PollingEncode ran after_complete")
66
+ is_expected.to include("PollingEncode ran after_completed")
67
67
  end
68
68
 
69
69
  it "does not re-enqueue itself" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_encode
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
- - Michael Klein, Chris Colvard
7
+ - Michael Klein, Chris Colvard, Phuong Dinh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-05 00:00:00.000000000 Z
11
+ date: 2018-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -140,7 +140,7 @@ description: This gem serves as the basis for the interface between a Ruby (Rail
140
140
  application and a provider of transcoding services such as Opencast Matterhorn,
141
141
  Zencoder, and Amazon Elastic Transcoder.
142
142
  email:
143
- - mbklein@gmail.com, chris.colvard@gmail.com
143
+ - mbklein@gmail.com, chris.colvard@gmail.com, phuongdh@gmail.com
144
144
  executables: []
145
145
  extensions: []
146
146
  extra_rdoc_files: []
@@ -165,11 +165,9 @@ files:
165
165
  - lib/active_encode/engine.rb
166
166
  - lib/active_encode/engine_adapter.rb
167
167
  - lib/active_encode/engine_adapters.rb
168
- - lib/active_encode/engine_adapters/active_job_adapter.rb
169
168
  - lib/active_encode/engine_adapters/elastic_transcoder_adapter.rb
170
- - lib/active_encode/engine_adapters/inline_adapter.rb
169
+ - lib/active_encode/engine_adapters/ffmpeg_adapter.rb
171
170
  - lib/active_encode/engine_adapters/matterhorn_adapter.rb
172
- - lib/active_encode/engine_adapters/shingoncoder_adapter.rb
173
171
  - lib/active_encode/engine_adapters/test_adapter.rb
174
172
  - lib/active_encode/engine_adapters/zencoder_adapter.rb
175
173
  - lib/active_encode/global_id.rb
@@ -194,6 +192,27 @@ files:
194
192
  - spec/fixtures/elastic_transcoder/output_failed.json
195
193
  - spec/fixtures/elastic_transcoder/output_progressing.json
196
194
  - spec/fixtures/elastic_transcoder/output_submitted.json
195
+ - spec/fixtures/ffmpeg/cancelled-id/error.log
196
+ - spec/fixtures/ffmpeg/cancelled-id/input_metadata
197
+ - spec/fixtures/ffmpeg/cancelled-id/pid
198
+ - spec/fixtures/ffmpeg/cancelled-id/progress
199
+ - spec/fixtures/ffmpeg/completed-id/error.log
200
+ - spec/fixtures/ffmpeg/completed-id/input_metadata
201
+ - spec/fixtures/ffmpeg/completed-id/output_metadata-high
202
+ - spec/fixtures/ffmpeg/completed-id/output_metadata-low
203
+ - spec/fixtures/ffmpeg/completed-id/pid
204
+ - spec/fixtures/ffmpeg/completed-id/progress
205
+ - spec/fixtures/ffmpeg/completed-id/video-high.mp4
206
+ - spec/fixtures/ffmpeg/completed-id/video-low.mp4
207
+ - spec/fixtures/ffmpeg/failed-id/error.log
208
+ - spec/fixtures/ffmpeg/failed-id/input_metadata
209
+ - spec/fixtures/ffmpeg/failed-id/pid
210
+ - spec/fixtures/ffmpeg/failed-id/progress
211
+ - spec/fixtures/ffmpeg/running-id/error.log
212
+ - spec/fixtures/ffmpeg/running-id/input_metadata
213
+ - spec/fixtures/ffmpeg/running-id/pid
214
+ - spec/fixtures/ffmpeg/running-id/progress
215
+ - spec/fixtures/fireworks.mp4
197
216
  - spec/fixtures/matterhorn/cancelled_response.xml
198
217
  - spec/fixtures/matterhorn/completed_response.xml
199
218
  - spec/fixtures/matterhorn/create_response.xml
@@ -215,8 +234,8 @@ files:
215
234
  - spec/fixtures/zencoder/job_progress_failed.json
216
235
  - spec/fixtures/zencoder/job_progress_running.json
217
236
  - spec/integration/elastic_transcoder_adapter_spec.rb
237
+ - spec/integration/ffmpeg_adapter_spec.rb
218
238
  - spec/integration/matterhorn_adapter_spec.rb
219
- - spec/integration/shingoncoder_adapter_spec.rb
220
239
  - spec/integration/zencoder_adapter_spec.rb
221
240
  - spec/rails_helper.rb
222
241
  - spec/shared_specs/engine_adapter_specs.rb
@@ -232,9 +251,9 @@ files:
232
251
  - spec/units/polling_job_spec.rb
233
252
  - spec/units/polling_spec.rb
234
253
  - spec/units/status_spec.rb
235
- homepage: ''
254
+ homepage: https://github.com/samvera-labs/active_encode
236
255
  licenses:
237
- - MIT
256
+ - Apache-2.0
238
257
  metadata: {}
239
258
  post_install_message:
240
259
  rdoc_options: []
@@ -271,6 +290,27 @@ test_files:
271
290
  - spec/fixtures/elastic_transcoder/output_failed.json
272
291
  - spec/fixtures/elastic_transcoder/output_progressing.json
273
292
  - spec/fixtures/elastic_transcoder/output_submitted.json
293
+ - spec/fixtures/ffmpeg/cancelled-id/error.log
294
+ - spec/fixtures/ffmpeg/cancelled-id/input_metadata
295
+ - spec/fixtures/ffmpeg/cancelled-id/pid
296
+ - spec/fixtures/ffmpeg/cancelled-id/progress
297
+ - spec/fixtures/ffmpeg/completed-id/error.log
298
+ - spec/fixtures/ffmpeg/completed-id/input_metadata
299
+ - spec/fixtures/ffmpeg/completed-id/output_metadata-high
300
+ - spec/fixtures/ffmpeg/completed-id/output_metadata-low
301
+ - spec/fixtures/ffmpeg/completed-id/pid
302
+ - spec/fixtures/ffmpeg/completed-id/progress
303
+ - spec/fixtures/ffmpeg/completed-id/video-high.mp4
304
+ - spec/fixtures/ffmpeg/completed-id/video-low.mp4
305
+ - spec/fixtures/ffmpeg/failed-id/error.log
306
+ - spec/fixtures/ffmpeg/failed-id/input_metadata
307
+ - spec/fixtures/ffmpeg/failed-id/pid
308
+ - spec/fixtures/ffmpeg/failed-id/progress
309
+ - spec/fixtures/ffmpeg/running-id/error.log
310
+ - spec/fixtures/ffmpeg/running-id/input_metadata
311
+ - spec/fixtures/ffmpeg/running-id/pid
312
+ - spec/fixtures/ffmpeg/running-id/progress
313
+ - spec/fixtures/fireworks.mp4
274
314
  - spec/fixtures/matterhorn/cancelled_response.xml
275
315
  - spec/fixtures/matterhorn/completed_response.xml
276
316
  - spec/fixtures/matterhorn/create_response.xml
@@ -292,8 +332,8 @@ test_files:
292
332
  - spec/fixtures/zencoder/job_progress_failed.json
293
333
  - spec/fixtures/zencoder/job_progress_running.json
294
334
  - spec/integration/elastic_transcoder_adapter_spec.rb
335
+ - spec/integration/ffmpeg_adapter_spec.rb
295
336
  - spec/integration/matterhorn_adapter_spec.rb
296
- - spec/integration/shingoncoder_adapter_spec.rb
297
337
  - spec/integration/zencoder_adapter_spec.rb
298
338
  - spec/rails_helper.rb
299
339
  - spec/shared_specs/engine_adapter_specs.rb
@@ -1,21 +0,0 @@
1
- module ActiveEncode
2
- module EngineAdapters
3
- class ActiveJobAdapter
4
- def initialize
5
- ActiveSupport::Deprecation.warn("The ActiveJobAdapter is deprecated and will be removed in ActiveEncode 0.3.")
6
- end
7
-
8
- def create(_input_url, _options) end
9
-
10
- def find(_id) end
11
-
12
- def list(*_filters) end
13
-
14
- def cancel(_id end
15
-
16
- def purge(_encode) end
17
-
18
- def remove_output(_encode, _output_id) end
19
- end
20
- end
21
- end
@@ -1,47 +0,0 @@
1
- module ActiveEncode
2
- module EngineAdapters
3
- class InlineAdapter
4
- class_attribute :encodes, instance_accessor: false, instance_predicate: false
5
- InlineAdapter.encodes ||= {}
6
-
7
- def initialize
8
- ActiveSupport::Deprecation.warn("The InlineAdapter is deprecated and will be removed in ActiveEncode 0.3.")
9
- end
10
-
11
- def create(input_url, options = {})
12
- encode = ActiveEncode::Base.new(input_url, options)
13
- encode.id = SecureRandom.uuid
14
- self.class.encodes[encode.id] = encode
15
- # start encode
16
- encode.state = :running
17
- encode
18
- end
19
-
20
- def find(id, _opts = {})
21
- self.class.encodes[id]
22
- end
23
-
24
- def list(*_filters)
25
- raise NotImplementedError
26
- end
27
-
28
- def cancel(encode)
29
- inline_encode = self.class.encodes[encode.id]
30
- return if inline_encode.nil?
31
- inline_encode.state = :cancelled
32
- # cancel encode
33
- inline_encode
34
- end
35
-
36
- def purge(encode)
37
- self.class.encodes.delete encode.id
38
- end
39
-
40
- def remove_output(encode, output_id)
41
- inline_encode = self.class.encodes[encode.id]
42
- return if inline_encode.nil?
43
- inline_encode.output.delete(inline_encode.output.find { |o| o[:id] == output_id })
44
- end
45
- end
46
- end
47
- end
@@ -1,63 +0,0 @@
1
- require 'active_support'
2
- require 'active_support/core_ext'
3
-
4
- module ActiveEncode
5
- module EngineAdapters
6
- class ShingoncoderAdapter < ZencoderAdapter
7
- def initialize
8
- ActiveSupport::Deprecation.warn("The ShingoncoderAdapter is deprecated and will be removed in ActiveEncode 0.3.")
9
- end
10
-
11
- # @param [ActiveEncode::Base] encode
12
- def create(input_url, options = {})
13
- response = Shingoncoder::Job.create(input: input_url)
14
- build_encode(job_details(response.body["id"]))
15
- end
16
-
17
- # @param [Fixnum] id
18
- # @param [Hash] opts
19
- # @option opts :cast the class to cast the encoding job to.
20
- def find(id, opts = {})
21
- build_encode(job_details(id))
22
- end
23
-
24
- # @param [ActiveEncode::Base] encode
25
- def cancel(id)
26
- response = Shingoncoder::Job.cancel(id)
27
- build_encode(job_details(id)) if response.success?
28
- end
29
-
30
- private
31
-
32
- # @param [Fixnum] job_id the identifier for the job
33
- # @return [Shingoncoder::Response] the response from Shingoncoder
34
- def job_details(job_id)
35
- Shingoncoder::Job.details(job_id)
36
- end
37
-
38
- # @return [Shingoncoder::Response] the response from Shingoncoder
39
- def job_progress(job_id)
40
- Shingoncoder::Job.progress(job_id)
41
- end
42
-
43
- # @param [Shingoncoder::Response] job_details
44
- # @param [Class] cast the class of object to instantiate and return
45
- def build_encode(job_details)
46
- return nil if job_details.nil?
47
- encode = ActiveEncode::Base.new(convert_input(job_details), convert_options(job_details))
48
- encode.id = job_details.body["job"]["id"].to_s
49
- encode.state = convert_state(job_details)
50
- progress = job_progress(encode.id)
51
- encode.current_operations = convert_current_operations(progress)
52
- encode.percent_complete = convert_percent_complete(progress, job_details)
53
- encode.created_at = job_details.body["job"]["created_at"]
54
- encode.updated_at = job_details.body["job"]["updated_at"]
55
- encode.finished_at = job_details.body["job"]["finished_at"]
56
- encode.output = convert_output(job_details)
57
- encode.errors = convert_errors(job_details)
58
- encode.tech_metadata = convert_tech_metadata(job_details.body["job"]["input_media_file"])
59
- encode
60
- end
61
- end
62
- end
63
- end
@@ -1,170 +0,0 @@
1
- require 'spec_helper'
2
- require 'shingoncoder'
3
- require 'json'
4
-
5
- describe ActiveEncode::EngineAdapters::ShingoncoderAdapter do
6
- before(:all) do
7
- ActiveEncode::Base.engine_adapter = :shingoncoder
8
- end
9
- after(:all) do
10
- ActiveEncode::Base.engine_adapter = :test
11
- end
12
-
13
- let(:create_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_create.json'))) }
14
-
15
- before do
16
- allow(Shingoncoder::Job).to receive(:create).and_return(create_response)
17
- end
18
-
19
- let(:file) { "file://#{File.absolute_path('spec/fixtures/Bars_512kb.mp4')}" }
20
-
21
- describe "#create" do
22
- before do
23
- allow(Shingoncoder::Job).to receive(:details).and_return(details_response)
24
- allow(Shingoncoder::Job).to receive(:progress).and_return(progress_response)
25
- end
26
-
27
- let(:details_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_details_create.json'))) }
28
- let(:progress_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_progress_create.json'))) }
29
- let(:create_output) { [{ id: "511404522", url: "https://zencoder-temp-storage-us-east-1.s3.amazonaws.com/o/20150610/c09b61e4d130ddf923f0653418a80b9c/399ae101c3f99b4f318635e78a4e587a.mp4?AWSAccessKeyId=AKIAI456JQ76GBU7FECA&Signature=GY/9LMkQAiDOrMQwS5BkmOE200s%3D&Expires=1434033527", label: nil }] }
30
-
31
- subject { ActiveEncode::Base.create(file) }
32
- it { is_expected.to be_a ActiveEncode::Base }
33
- its(:id) { is_expected.not_to be_empty }
34
- it { is_expected.to be_running }
35
- its(:output) { is_expected.to eq create_output }
36
- its(:current_operations) { is_expected.to be_empty }
37
- its(:percent_complete) { is_expected.to eq 0 }
38
- its(:errors) { is_expected.to be_empty }
39
- its(:created_at) { is_expected.to eq '2015-06-10T14:38:47Z' }
40
- its(:updated_at) { is_expected.to eq '2015-06-10T14:38:47Z' }
41
- its(:finished_at) { is_expected.to be_nil }
42
- its(:tech_metadata) { is_expected.to be_empty }
43
- end
44
-
45
- describe "#find" do
46
- before do
47
- allow(Shingoncoder::Job).to receive(:details).and_return(details_response)
48
- allow(Shingoncoder::Job).to receive(:progress).and_return(progress_response)
49
- end
50
-
51
- context "a running encode" do
52
- let(:details_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_details_running.json'))) }
53
- let(:progress_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_progress_running.json'))) }
54
- let(:running_output) { [{ id: "510582971", url: "https://zencoder-temp-storage-us-east-1.s3.amazonaws.com/o/20150609/48a6907086c012f68b9ca43461280515/1726d7ec3e24f2171bd07b2abb807b6c.mp4?AWSAccessKeyId=AKIAI456JQ76GBU7FECA&Signature=vSvlxU94wlQLEbpG3Zs8ibp4MoY%3D&Expires=1433953106", label: nil }] }
55
- let(:running_tech_metadata) { { audio_bitrate: "52", audio_codec: "aac", audio_channels: "2", duration: "57992", mime_type: "mpeg4", video_framerate: "29.97", height: "240", video_bitrate: "535", video_codec: "h264", width: "320" } }
56
-
57
- subject { ActiveEncode::Base.find('166019107') }
58
- it { is_expected.to be_a ActiveEncode::Base }
59
- its(:id) { is_expected.to eq '166019107' }
60
- it { is_expected.to be_running }
61
- its(:output) { is_expected.to eq running_output }
62
- its(:current_operations) { is_expected.to be_empty }
63
- its(:percent_complete) { is_expected.to eq 30.0 }
64
- its(:errors) { is_expected.to be_empty }
65
- its(:created_at) { is_expected.to eq '2015-06-09T16:18:26Z' }
66
- its(:updated_at) { is_expected.to eq '2015-06-09T16:18:28Z' }
67
- its(:finished_at) { is_expected.to be_nil }
68
- its(:tech_metadata) { is_expected.to eq running_tech_metadata }
69
- end
70
-
71
- context "a cancelled encode" do
72
- let(:details_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_details_cancelled.json'))) }
73
- let(:progress_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_progress_cancelled.json'))) }
74
-
75
- subject { ActiveEncode::Base.find('165866551') }
76
- it { is_expected.to be_a ActiveEncode::Base }
77
- its(:id) { is_expected.to eq '165866551' }
78
- it { is_expected.to be_cancelled }
79
- its(:current_operations) { is_expected.to be_empty }
80
- its(:percent_complete) { is_expected.to eq 0 }
81
- its(:errors) { is_expected.to be_empty }
82
- its(:created_at) { is_expected.to eq '2015-06-08T20:43:23Z' }
83
- its(:updated_at) { is_expected.to eq '2015-06-08T20:43:26Z' }
84
- its(:finished_at) { is_expected.to eq '2015-06-08T20:43:26Z' }
85
- its(:tech_metadata) { is_expected.to be_empty }
86
- end
87
-
88
- context "a completed encode" do
89
- let(:details_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_details_completed.json'))) }
90
- let(:progress_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_progress_completed.json'))) }
91
- let(:completed_output) { { id: "509856876", audio_bitrate: "53", audio_codec: "aac", audio_channels: "2", duration: "5000", mime_type: "mpeg4", video_framerate: "29.97", height: "240", video_bitrate: "549", video_codec: "h264", width: "320", url: "https://zencoder-temp-storage-us-east-1.s3.amazonaws.com/o/20150608/ebbe865f8ef1b960d7c2bb0663b88a12/0f1948dcb2fd701fba30ff21908fe460.mp4?AWSAccessKeyId=AKIAI456JQ76GBU7FECA&Signature=1LgIyl/el9E7zeyPxzd/%2BNwez6Y%3D&Expires=1433873646", label: nil } }
92
- let(:completed_tech_metadata) { { audio_bitrate: "52", audio_codec: "aac", audio_channels: "2", duration: "57992", mime_type: "mpeg4", video_framerate: "29.97", height: "240", video_bitrate: "535", video_codec: "h264", width: "320" } }
93
-
94
- subject { ActiveEncode::Base.find('165839139') }
95
- it { is_expected.to be_a ActiveEncode::Base }
96
- its(:id) { is_expected.to eq '165839139' }
97
- it { is_expected.to be_completed }
98
- its(:output) { is_expected.to include completed_output }
99
- its(:current_operations) { is_expected.to be_empty }
100
- its(:percent_complete) { is_expected.to eq 100 }
101
- its(:errors) { is_expected.to be_empty }
102
- its(:created_at) { is_expected.to eq '2015-06-08T18:13:53Z' }
103
- its(:updated_at) { is_expected.to eq '2015-06-08T18:14:06Z' }
104
- its(:finished_at) { is_expected.to eq '2015-06-08T18:14:06Z' }
105
- its(:tech_metadata) { is_expected.to eq completed_tech_metadata }
106
- end
107
-
108
- context "a failed encode" do
109
- let(:details_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_details_failed.json'))) }
110
- let(:progress_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_progress_failed.json'))) }
111
- let(:failed_tech_metadata) { { mime_type: "video/mp4", checksum: "7ae24368ccb7a6c6422a14ff73f33c9a", duration: "6314", audio_codec: "AAC", audio_channels: "2", audio_bitrate: "171030.0", video_codec: "AVC", video_bitrate: "74477.0", video_framerate: "23.719", width: "200", height: "110" } }
112
- let(:failed_errors) { "The file is an XML file, and doesn't contain audio or video tracks." }
113
-
114
- subject { ActiveEncode::Base.find('166079902') }
115
- it { is_expected.to be_a ActiveEncode::Base }
116
- its(:id) { is_expected.to eq '166079902' }
117
- it { is_expected.to be_failed }
118
- its(:current_operations) { is_expected.to be_empty }
119
- its(:percent_complete) { is_expected.to eq 0 }
120
- its(:errors) { is_expected.to include failed_errors }
121
- its(:created_at) { is_expected.to eq '2015-06-09T20:52:57Z' }
122
- its(:updated_at) { is_expected.to eq '2015-06-09T20:53:00Z' }
123
- its(:finished_at) { is_expected.to eq '2015-06-09T20:53:00Z' }
124
- its(:tech_metadata) { is_expected.to be_empty }
125
- end
126
- end
127
-
128
- describe "#cancel!" do
129
- before do
130
- allow(Shingoncoder::Job).to receive(:cancel).and_return(cancel_response)
131
- allow(Shingoncoder::Job).to receive(:details).and_return(details_response)
132
- allow(Shingoncoder::Job).to receive(:progress).and_return(progress_response)
133
- end
134
-
135
- let(:cancel_response) { Shingoncoder::Response.new(code: 200) } # TODO: check that this is the correct response code for a successful cancel
136
- let(:details_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_details_cancelled.json'))) }
137
- let(:progress_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_progress_cancelled.json'))) }
138
-
139
- let(:encode) { ActiveEncode::Base.create(file) }
140
- subject { encode.cancel! }
141
- it { is_expected.to be_a ActiveEncode::Base }
142
- its(:id) { is_expected.to eq '165866551' }
143
- it { is_expected.to be_cancelled }
144
- end
145
-
146
- describe "reload" do
147
- before do
148
- allow(Shingoncoder::Job).to receive(:details).and_return(details_response)
149
- allow(Shingoncoder::Job).to receive(:progress).and_return(progress_response)
150
- end
151
-
152
- let(:details_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_details_running.json'))) }
153
- let(:progress_response) { Shingoncoder::Response.new(body: JSON.parse(File.read('spec/fixtures/zencoder/job_progress_running.json'))) }
154
- let(:reload_output) { [{ id: "510582971", url: "https://zencoder-temp-storage-us-east-1.s3.amazonaws.com/o/20150609/48a6907086c012f68b9ca43461280515/1726d7ec3e24f2171bd07b2abb807b6c.mp4?AWSAccessKeyId=AKIAI456JQ76GBU7FECA&Signature=vSvlxU94wlQLEbpG3Zs8ibp4MoY%3D&Expires=1433953106", label: nil }] }
155
- let(:reload_tech_metadata) { { audio_bitrate: "52", audio_codec: "aac", audio_channels: "2", duration: "57992", mime_type: "mpeg4", video_framerate: "29.97", height: "240", video_bitrate: "535", video_codec: "h264", width: "320" } }
156
-
157
- subject { ActiveEncode::Base.find('166019107').reload }
158
- it { is_expected.to be_a ActiveEncode::Base }
159
- its(:id) { is_expected.to eq '166019107' }
160
- it { is_expected.to be_running }
161
- its(:output) { is_expected.to eq reload_output }
162
- its(:current_operations) { is_expected.to be_empty }
163
- its(:percent_complete) { is_expected.to eq 30.0 }
164
- its(:errors) { is_expected.to be_empty }
165
- its(:created_at) { is_expected.to eq '2015-06-09T16:18:26Z' }
166
- its(:updated_at) { is_expected.to eq '2015-06-09T16:18:28Z' }
167
- its(:finished_at) { is_expected.to be_nil }
168
- its(:tech_metadata) { is_expected.to eq reload_tech_metadata }
169
- end
170
- end