bitmovin-ruby 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.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +13 -0
  6. data/Gemfile.lock +125 -0
  7. data/Guardfile +70 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +44 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/bitmovin-ruby.gemspec +31 -0
  14. data/examples/simple_dash.rb +191 -0
  15. data/lib/bitmovin/bitmovin_error.rb +7 -0
  16. data/lib/bitmovin/child_collection.rb +41 -0
  17. data/lib/bitmovin/client.rb +35 -0
  18. data/lib/bitmovin/configuration_resource.rb +4 -0
  19. data/lib/bitmovin/encoding/codec_configurations/aac_configuration.rb +7 -0
  20. data/lib/bitmovin/encoding/codec_configurations/h264_configuration.rb +9 -0
  21. data/lib/bitmovin/encoding/codec_configurations/h265_configuration.rb +8 -0
  22. data/lib/bitmovin/encoding/codec_configurations/vp9_configuration.rb +8 -0
  23. data/lib/bitmovin/encoding/codec_configurations.rb +23 -0
  24. data/lib/bitmovin/encoding/encodings/encoding_task.rb +67 -0
  25. data/lib/bitmovin/encoding/encodings/list.rb +39 -0
  26. data/lib/bitmovin/encoding/encodings/muxing_list.rb +19 -0
  27. data/lib/bitmovin/encoding/encodings/muxings/fmp4_muxing.rb +5 -0
  28. data/lib/bitmovin/encoding/encodings/muxings/fmp4_muxing_list.rb +5 -0
  29. data/lib/bitmovin/encoding/encodings/muxings/mp4_muxing.rb +4 -0
  30. data/lib/bitmovin/encoding/encodings/muxings/mp4_muxing_list.rb +5 -0
  31. data/lib/bitmovin/encoding/encodings/muxings/muxing_resource.rb +56 -0
  32. data/lib/bitmovin/encoding/encodings/muxings/ts_muxing.rb +5 -0
  33. data/lib/bitmovin/encoding/encodings/muxings/ts_muxing_list.rb +5 -0
  34. data/lib/bitmovin/encoding/encodings/muxings/webm_muxing.rb +5 -0
  35. data/lib/bitmovin/encoding/encodings/muxings/webm_muxing_list.rb +5 -0
  36. data/lib/bitmovin/encoding/encodings/stream.rb +102 -0
  37. data/lib/bitmovin/encoding/encodings/stream_input.rb +51 -0
  38. data/lib/bitmovin/encoding/encodings/stream_list.rb +5 -0
  39. data/lib/bitmovin/encoding/encodings.rb +24 -0
  40. data/lib/bitmovin/encoding/inputs/analysis.rb +27 -0
  41. data/lib/bitmovin/encoding/inputs/analysis_task.rb +73 -0
  42. data/lib/bitmovin/encoding/inputs/aspera_input.rb +7 -0
  43. data/lib/bitmovin/encoding/inputs/azure_input.rb +8 -0
  44. data/lib/bitmovin/encoding/inputs/ftp_input.rb +7 -0
  45. data/lib/bitmovin/encoding/inputs/gcs_input.rb +7 -0
  46. data/lib/bitmovin/encoding/inputs/generic_s3_input.rb +7 -0
  47. data/lib/bitmovin/encoding/inputs/http_input.rb +7 -0
  48. data/lib/bitmovin/encoding/inputs/https_input.rb +7 -0
  49. data/lib/bitmovin/encoding/inputs/rtmp_input.rb +6 -0
  50. data/lib/bitmovin/encoding/inputs/s3_input.rb +7 -0
  51. data/lib/bitmovin/encoding/inputs/sftp_input.rb +7 -0
  52. data/lib/bitmovin/encoding/inputs.rb +27 -0
  53. data/lib/bitmovin/encoding/manifests/audio_adaptation_set.rb +22 -0
  54. data/lib/bitmovin/encoding/manifests/dash_manifest.rb +56 -0
  55. data/lib/bitmovin/encoding/manifests/dash_representations.rb +14 -0
  56. data/lib/bitmovin/encoding/manifests/fmp4_representation.rb +18 -0
  57. data/lib/bitmovin/encoding/manifests/hls_manifest.rb +7 -0
  58. data/lib/bitmovin/encoding/manifests/manifest_resource.rb +16 -0
  59. data/lib/bitmovin/encoding/manifests/period.rb +17 -0
  60. data/lib/bitmovin/encoding/manifests/video_adaptation.rb +8 -0
  61. data/lib/bitmovin/encoding/manifests/video_adaptation_set.rb +22 -0
  62. data/lib/bitmovin/encoding/manifests.rb +23 -0
  63. data/lib/bitmovin/encoding/outputs/gcs_output.rb +6 -0
  64. data/lib/bitmovin/encoding/outputs/s3_output.rb +6 -0
  65. data/lib/bitmovin/encoding/outputs.rb +17 -0
  66. data/lib/bitmovin/encoding/stream_output.rb +44 -0
  67. data/lib/bitmovin/encoding.rb +10 -0
  68. data/lib/bitmovin/helpers.rb +55 -0
  69. data/lib/bitmovin/input_resource.rb +16 -0
  70. data/lib/bitmovin/resource.rb +86 -0
  71. data/lib/bitmovin/version.rb +3 -0
  72. data/lib/bitmovin.rb +30 -0
  73. metadata +225 -0
@@ -0,0 +1,27 @@
1
+ module Bitmovin::Encoding
2
+ module Inputs
3
+ def Inputs.list(limit = 100, offset = 0)
4
+ response = Bitmovin.client.get '/v1/encoding/inputs', { limit: limit, offset: offset }
5
+ result = (JSON.parse(response.body))['data']['result']
6
+ list = result['items'].map do |item|
7
+ case item['type'].downcase
8
+ when "s3"
9
+ S3Input.new(item)
10
+ end
11
+ end
12
+ list
13
+ end
14
+ end
15
+ end
16
+ require 'bitmovin/encoding/inputs/s3_input'
17
+ require 'bitmovin/encoding/inputs/rtmp_input'
18
+ require 'bitmovin/encoding/inputs/generic_s3_input'
19
+ require 'bitmovin/encoding/inputs/gcs_input'
20
+ require 'bitmovin/encoding/inputs/azure_input'
21
+ require 'bitmovin/encoding/inputs/ftp_input'
22
+ require 'bitmovin/encoding/inputs/sftp_input'
23
+ require 'bitmovin/encoding/inputs/http_input'
24
+ require 'bitmovin/encoding/inputs/https_input'
25
+ require 'bitmovin/encoding/inputs/aspera_input'
26
+ require 'bitmovin/encoding/inputs/analysis'
27
+ require 'bitmovin/encoding/inputs/analysis_task'
@@ -0,0 +1,22 @@
1
+ module Bitmovin::Encoding::Manifests
2
+ class AudioAdaptationSet < Bitmovin::Resource
3
+ include Bitmovin::ChildCollection
4
+ def initialize(manifest_id, period_id, hash = {})
5
+ path = File.join("/v1/encoding/manifests/dash/", manifest_id, "periods", period_id, "adaptationsets/audio")
6
+ self.class.init(path)
7
+ @manifest_id = manifest_id
8
+ @period_id = period_id
9
+ end
10
+
11
+ child_collection(:fmp4_representations, "/v1/encoding/manifests/dash/%s/periods/%s/adaptationsets/%s/representations/fmp4", [:manifest_id, :period_id, :id], Fmp4Representation)
12
+
13
+ attr_accessor :manifest_id
14
+ attr_accessor :period_id
15
+ attr_accessor :roles
16
+ attr_accessor :lang
17
+
18
+ def ignore_fields
19
+ [:@manifest_id, :@period_id]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,56 @@
1
+ module Bitmovin::Encoding::Manifests
2
+ class DashManifest < Bitmovin::Resource
3
+ include Bitmovin::ChildCollection
4
+ init("/v1/encoding/manifests/dash")
5
+
6
+ def initialize(hash = {})
7
+ hsh = ActiveSupport::HashWithIndifferentAccess.new(underscore_hash(hash))
8
+ super(hash)
9
+ @outputs = (hsh[:outputs] || []).map { |output| Bitmovin::Encoding::StreamOutput.new(output) }
10
+ @periods = nil
11
+ end
12
+
13
+ child_collection(:periods, "/v1/encoding/manifests/dash/%s/periods", [:id], Bitmovin::Encoding::Manifests::Period)
14
+
15
+ attr_accessor :outputs, :manifest_name
16
+
17
+ def persisted?
18
+ !@id.nil?
19
+ end
20
+
21
+ def reload!
22
+ @periods = nil
23
+ end
24
+
25
+ def start!
26
+ path = File.join("/v1/encoding/manifests/dash/", @id, "start")
27
+ Bitmovin.client.post(path)
28
+ end
29
+
30
+ def full_status
31
+ path = File.join("/v1/encoding/manifests/dash/", @id, "status")
32
+ response = Bitmovin.client.get(path)
33
+ hash_to_struct(result(response))
34
+ end
35
+
36
+ def status
37
+ full_status.status
38
+ end
39
+
40
+ def progress
41
+ full_status.progress
42
+ end
43
+
44
+ private
45
+
46
+ def collect_attributes
47
+ val = Hash.new
48
+ [:name, :description, :manifest_name].each do |name|
49
+ json_name = ActiveSupport::Inflector.camelize(name.to_s, false)
50
+ val[json_name] = instance_variable_get("@#{name}")
51
+ end
52
+ val["outputs"] = @outputs.map { |o| o.send(:collect_attributes) }
53
+ val
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,14 @@
1
+ module Bitmovin::Encoding::Manifests
2
+ class DashRepresentations
3
+ def initialize(id)
4
+ @manifest_id = id
5
+ end
6
+ attr_accessor :manifest_id
7
+
8
+ [:fmp4, :webm].each do |representation|
9
+ define_method representation do
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module Bitmovin::Encoding::Manifests
2
+ class Fmp4Representation < Bitmovin::Resource
3
+ def initialize(manifest_id, period_id, adaptationset_id, hash = {})
4
+ path = File.join("/v1/encoding/manifests/dash/", manifest_id, "periods", period_id, "adaptationsets/", adaptationset_id, "representations/fmp4")
5
+ self.class.init(path)
6
+ super(hash)
7
+ @manifest_id = manifest_id
8
+ @period_id = period_id
9
+ @adaptationset_id = adaptationset_id
10
+ end
11
+
12
+ attr_accessor :manifest_id
13
+ attr_accessor :period_id
14
+ attr_accessor :adaptationset_id
15
+
16
+ attr_accessor :type, :encoding_id, :muxing_id, :start_segment_number, :end_segment_number, :segment_path
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module Bitmovin::Encoding::Manifests
2
+ class HlsManifest < Bitmovin::Resource
3
+ init("/v1/encoding/manifests/hls")
4
+
5
+ attr_accessor :outputs, :manifest_name
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ module Bitmovin::Encoding::Manifests
2
+ class ManifestResource < Bitmovin::Resource
3
+ def initialize(hash = {})
4
+ hsh = ActiveSupport::HashWithIndifferentAccess.new(underscore_hash(hash))
5
+ muxing_type = self.class.name.demodulize.gsub(/(.*)Muxing/, '\1').downcase
6
+ self.class.init(File.join("/v1/encoding/manifests/", encoding_id, "muxings", muxing_type))
7
+ super(hsh)
8
+ @outputs = (hsh[:outputs] || []).map do |output|
9
+ Bitmovin::Encoding::Encodings::StreamOutput.new(encoding_id, @id, output)
10
+ end
11
+ @streams = (hsh[:streams] || []).map do |stream|
12
+ stream[:stream_id]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module Bitmovin::Encoding::Manifests
2
+ class Period < Bitmovin::Resource
3
+ include Bitmovin::ChildCollection
4
+
5
+ def initialize(manifest_id, hash = {})
6
+ self.class.init(File.join("/v1/encoding/manifests/dash/", manifest_id, "periods"))
7
+ @manifest_id = manifest_id
8
+ super(hash)
9
+ @video_adaptationsets = nil
10
+ @audio_adaptationsets = nil
11
+ end
12
+ attr_accessor :manifest_id, :duration, :start
13
+
14
+ child_collection(:video_adaptationsets, "/v1/encoding/manifests/dash/%s/periods/%s/adaptationsets/video", [:manifest_id, :id], VideoAdaptationSet)
15
+ child_collection(:audio_adaptationsets, "/v1/encoding/manifests/dash/%s/periods/%s/adaptationsets/audio", [:manifest_id, :id], AudioAdaptationSet)
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ module Bitmovin::Encoding::Manifests
2
+ class VideoAdaptation
3
+ def initialize(manifest_id)
4
+ @manifest_id = manifest_id
5
+ end
6
+ attr_accessor :manifest_id
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ module Bitmovin::Encoding::Manifests
2
+ class VideoAdaptationSet < Bitmovin::Resource
3
+ include Bitmovin::ChildCollection
4
+ def initialize(manifest_id, period_id, hash = {})
5
+ path = File.join("/v1/encoding/manifests/dash/", manifest_id, "periods", period_id, "adaptationsets/video")
6
+ self.class.init(path)
7
+ super(hash)
8
+ @manifest_id = manifest_id
9
+ @period_id = period_id
10
+ end
11
+
12
+ child_collection(:fmp4_representations, "/v1/encoding/manifests/dash/%s/periods/%s/adaptationsets/%s/representations/fmp4", [:manifest_id, :period_id, :id], Fmp4Representation)
13
+
14
+ attr_accessor :manifest_id
15
+ attr_accessor :period_id
16
+ attr_accessor :roles
17
+
18
+ def ignore_fields
19
+ [:@manifest_id, :@period_id]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ module Bitmovin::Encoding
2
+ module Manifests
3
+ def self.list(*args)
4
+ # TODO
5
+ end
6
+
7
+ def self.dash
8
+ # TODO
9
+ end
10
+
11
+ def self.hls
12
+ # TODO
13
+ end
14
+ end
15
+ end
16
+
17
+ require 'bitmovin/encoding/manifests/fmp4_representation'
18
+ require 'bitmovin/encoding/manifests/audio_adaptation_set'
19
+ require 'bitmovin/encoding/manifests/video_adaptation_set'
20
+ require 'bitmovin/encoding/manifests/period'
21
+ require 'bitmovin/encoding/manifests/dash_manifest'
22
+ require 'bitmovin/encoding/manifests/hls_manifest'
23
+ require 'bitmovin/encoding/manifests/dash_representations'
@@ -0,0 +1,6 @@
1
+ module Bitmovin::Encoding::Outputs
2
+ class GcsOutput < Bitmovin::Resource
3
+ init 'encoding/outputs/gcs'
4
+ attr_accessor :id, :name, :description, :created_at, :modified_at, :bucket_name, :cloud_region
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Bitmovin::Encoding::Outputs
2
+ class S3Output < Bitmovin::Resource
3
+ init 'encoding/outputs/s3'
4
+ attr_accessor :id, :name, :description, :created_at, :modified_at, :bucket_name, :cloud_region
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ module Bitmovin::Encoding
2
+ module Outputs
3
+ def self.list(limit = 100, offset = 0)
4
+ response = Bitmovin.client.get '/v1/encoding/outputs', { limit: limit, offset: offset }
5
+ result = (JSON.parse(response.body))['data']['result']
6
+ list = result['items'].map do |item|
7
+ case item['type'].downcase
8
+ when "s3"
9
+ S3Output.new(item)
10
+ end
11
+ end
12
+ list
13
+ end
14
+ end
15
+ end
16
+ require 'bitmovin/encoding/outputs/s3_output'
17
+ require 'bitmovin/encoding/outputs/gcs_output'
@@ -0,0 +1,44 @@
1
+ module Bitmovin::Encoding
2
+ class StreamOutput
3
+ def initialize(hash = {})
4
+ @errors = []
5
+ hash.each do |name, value|
6
+ instance_variable_set("@#{ActiveSupport::Inflector.underscore(name)}", value)
7
+ end
8
+ end
9
+
10
+ attr_accessor :output_id, :output_path, :acl
11
+
12
+ def valid?
13
+ validate!
14
+ @errors.empty?
15
+ end
16
+
17
+ def invalid?
18
+ !valid?
19
+ end
20
+
21
+ def errors
22
+ @errors
23
+ end
24
+
25
+ def to_json(args)
26
+ collect_attributes.to_json(args)
27
+ end
28
+
29
+ private
30
+
31
+ def collect_attributes
32
+ val = Hash.new
33
+ [:output_id, :output_path, :acl].each do |name|
34
+ json_name = ActiveSupport::Inflector.camelize(name.to_s, false)
35
+ val[json_name] = instance_variable_get("@#{name}")
36
+ end
37
+ val
38
+ end
39
+ def validate!
40
+ @errors << "output_id cannot be blank" if @output_id.blank?
41
+ @errors << "output_path cannot be blank" if @output_path.blank?
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,10 @@
1
+ module Bitmovin
2
+ module Encoding
3
+ end
4
+ end
5
+ require 'bitmovin/encoding/inputs'
6
+ require 'bitmovin/encoding/outputs'
7
+ require 'bitmovin/encoding/codec_configurations'
8
+ require 'bitmovin/encoding/encodings'
9
+ require 'bitmovin/encoding/manifests'
10
+ require 'bitmovin/encoding/stream_output'
@@ -0,0 +1,55 @@
1
+ module Bitmovin::Helpers
2
+ def result(response)
3
+ Bitmovin::Helpers.result(response)
4
+ end
5
+
6
+ def self.result(response)
7
+ (JSON.parse(response.body))['data']['result']
8
+ end
9
+
10
+ def camelize_hash(hash)
11
+ ret = Hash.new
12
+ hash.each do |key, value|
13
+ ret[ActiveSupport::Inflector.camelize(key, false)] = value
14
+ end
15
+ ret
16
+ end
17
+
18
+ def underscore_hash(hash)
19
+ if !hash.instance_of? Hash
20
+ return hash
21
+ end
22
+
23
+ ret = Hash.new
24
+ hash.each do |key, value|
25
+ if value.instance_of?(Hash)
26
+ value = underscore_hash(value)
27
+ end
28
+ if (value.instance_of?(Array))
29
+ value = value.map { |v| underscore_hash(v) }
30
+ end
31
+ new_key = ActiveSupport::Inflector.underscore(key)
32
+ new_key = new_key.to_sym if key.instance_of? Symbol
33
+ ret[new_key] = value
34
+ end
35
+ ret
36
+ end
37
+
38
+ def hash_to_struct(hash)
39
+ if !hash.instance_of? Hash
40
+ return hash
41
+ end
42
+
43
+ ret = Hash.new
44
+ hash.each do |key, value|
45
+ if value.instance_of?(Hash)
46
+ value = hash_to_struct(value)
47
+ end
48
+ if value.instance_of?(Array)
49
+ value = value.map { |v| hash_to_struct(v) }
50
+ end
51
+ ret[key] = value
52
+ end
53
+ OpenStruct.new(ret)
54
+ end
55
+ end
@@ -0,0 +1,16 @@
1
+ module Bitmovin
2
+ class InputResource < Resource
3
+ def analyze!(options)
4
+ path = File.join("/v1/encoding/inputs/", @id, "analysis")
5
+ response = Bitmovin.client.post(path) do |req|
6
+ req.body = camelize_hash(options)
7
+ end
8
+ result = (JSON.parse(response.body))['data']['result']
9
+ Bitmovin::Encoding::Inputs::AnalysisTask.new(self, result['id'])
10
+ end
11
+
12
+ def analyses
13
+ Encoding::Inputs::Analysis.new(@id)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,86 @@
1
+ require 'pry'
2
+ module Bitmovin
3
+ class Resource
4
+ include Bitmovin::Helpers
5
+
6
+ class << self
7
+ def init(path)
8
+ @resource_path = path
9
+ end
10
+ attr_reader :resource_path
11
+
12
+
13
+ def list(limit = 100, offset = 0)
14
+ response = Bitmovin.client.get @resource_path, limit: limit, offset: offset
15
+ Bitmovin::Helpers.result(response)['items'].map do |item|
16
+ new(item)
17
+ end
18
+ end
19
+
20
+ def find(id)
21
+ response = Bitmovin.client.get File.join(@resource_path, id)
22
+ new(Bitmovin::Helpers.result(response))
23
+ end
24
+ end
25
+
26
+ attr_accessor :id, :name, :description, :created_at, :modified_at
27
+
28
+
29
+ def initialize(hash = {})
30
+ init_from_hash(hash)
31
+ end
32
+
33
+ def save!
34
+ if @id
35
+ raise BitmovinError.new(self), "Cannot save already persisted resource"
36
+ end
37
+
38
+ response = Bitmovin.client.post do |post|
39
+ post.url self.class.resource_path
40
+ post.body = collect_attributes
41
+ end
42
+ init_from_hash(result(response))
43
+ self
44
+ end
45
+
46
+ def persisted?
47
+ !@id.nil?
48
+ end
49
+
50
+ def delete!
51
+ Bitmovin.client.delete File.join(self.class.resource_path, @id)
52
+ end
53
+
54
+ def inspect
55
+ "#{self.class.name}(id: #{@id}, name: #{@name})"
56
+ end
57
+
58
+ private
59
+
60
+ def init_from_hash(hash = {})
61
+ hash.each do |name, value|
62
+ instance_variable_set("@#{ActiveSupport::Inflector.underscore(name)}", value)
63
+ end
64
+ end
65
+
66
+ def collect_attributes
67
+ val = Hash.new
68
+ ignored_variables = []
69
+ if (self.respond_to?(:ignore_fields))
70
+ ignored_variables = self.ignore_fields
71
+ end
72
+ instance_variables.each do |name|
73
+ if ignored_variables.include?(name)
74
+ next
75
+ end
76
+ if name == :@max_ctu_size
77
+ val['maxCTUSize'] = instance_variable_get(name)
78
+ else
79
+ json_name = ActiveSupport::Inflector.camelize(name.to_s.gsub(/@/, ''), false)
80
+ val[json_name] = instance_variable_get(name)
81
+ end
82
+ end
83
+ val
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module Bitmovin
2
+ VERSION = "0.1.0"
3
+ end
data/lib/bitmovin.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'bundler/setup'
4
+ require 'faraday'
5
+ require 'faraday_middleware'
6
+ require 'securerandom'
7
+ require 'active_support'
8
+ require 'active_support/core_ext'
9
+
10
+ require 'bitmovin/version'
11
+ require 'bitmovin/bitmovin_error'
12
+ require 'bitmovin/helpers'
13
+ require 'bitmovin/child_collection'
14
+ require 'bitmovin/resource'
15
+ require 'bitmovin/input_resource'
16
+ require 'bitmovin/configuration_resource'
17
+ require 'bitmovin/client'
18
+ require 'bitmovin/encoding'
19
+
20
+ module Bitmovin
21
+ @@client = nil
22
+
23
+ def self.init(api_key)
24
+ @@client = Client.new({ api_key: api_key })
25
+ end
26
+
27
+ def self.client
28
+ @@client
29
+ end
30
+ end