multi_video_streaming 1.0.1.beta → 1.0.1.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f823ff71e880e3e7efce69dcbdb48456176327e2f0731b9d40d2870d23f0b71
4
- data.tar.gz: 9807632350465257894274a8818f498d5593b19757ab59db1f063c8fa26ccc6a
3
+ metadata.gz: 765bcaf5804a6f5cba3e24afa63bc7a5bbcfe753b1e6bd784af486c2a6a9ae7f
4
+ data.tar.gz: 816678de1d83ef07d15e27367ba1bee62f4586ad4074704e843f9f7fd059e63d
5
5
  SHA512:
6
- metadata.gz: 8e4cd7670fd8b64ccc9f7b1ccb49ae6180cfb966f625b9942075b58dc9e2999b8c7dfbb9d48dc21b32ba1e2256af194e793feeaf29616b6875f48fcad4465412
7
- data.tar.gz: 104882165a54cd6bc82b918b67b566cc5965cd492fc7f851a1de471283443cf00836d71c99d2f39f379c792020513681694af2f343407270e3d3aea8119fb70b
6
+ metadata.gz: ed105c282801bb02ab5bd5a3d27ea7c0f915ed15fa017e5314bc6f40df551de2e742b3fc51a703c0f89882f7e36ebdf45979394f18e9827977e5241ee4d7d953
7
+ data.tar.gz: 0bddcb8383e6594b97373394aad0e8d56d3f89bd5a095aaa15cb50ffd901eb957517798d8b582fa3d07928bdeb000a00e5c18f541868b6a6ba40d8f976308008
@@ -99,10 +99,10 @@ module MultiVideoStreaming
99
99
  end
100
100
 
101
101
  response["directPlay"] = "https://video.bunnycdn.com/play/#{library_id}/#{video_id}"
102
- response["availableResolutions"] = response["availableResolutions"].split(",")
102
+ response["availableResolutions"] = response["availableResolutions"]&.split(",")
103
103
 
104
104
  files = []
105
- response["availableResolutions"].map do |available_resolution|
105
+ response["availableResolutions"]&.map do |available_resolution|
106
106
  files <<
107
107
  {
108
108
  file: "https://#{pull_zone}.b-cdn.net/#{response["guid"]}/play_#{available_resolution}.mp4",
@@ -116,6 +116,10 @@ module MultiVideoStreaming
116
116
 
117
117
  response["status"] = STATUS_EQUIVALENT[response["status"].to_s]
118
118
 
119
+ if response["status"] != "available"
120
+ raise MultiVideoStreaming::Helpers::GetDefaultErrorMessage.not_available
121
+ end
122
+
119
123
  return self.response_instance.add_response(
120
124
  platform_name: "bunny",
121
125
  status: "success",
@@ -29,7 +29,7 @@ module MultiVideoStreaming
29
29
  response = Aws::S3::Resource.new().bucket(bucket).object(video_id)
30
30
  video_url = response.public_url
31
31
 
32
- url_signed = generate_presign_url(bucket: bucket, key: video_id)
32
+ url_signed = MultiVideoStreaming::Utils::S3.generate_presign_url(method: :get, bucket: bucket, key: video_id, download: false)
33
33
  data = {
34
34
  "key": response.key,
35
35
  "title": response.key,
@@ -140,11 +140,6 @@ module MultiVideoStreaming
140
140
  Aws.config.update(credentials: credentials, region: region, force_path_style: true)
141
141
  end
142
142
  end
143
-
144
- def generate_presign_url(bucket:, key:)
145
- signer = Aws::S3::Presigner.new
146
- signer.presigned_url(:get_object, bucket: bucket, key: key, expires_in: 900)
147
- end
148
143
  end
149
144
  end
150
145
  end
@@ -105,7 +105,7 @@ module MultiVideoStreaming
105
105
 
106
106
  available_resolutions = []
107
107
  files = []
108
- response["files"].each do |file|
108
+ response["files"]&.each do |file|
109
109
  if file["rendition"] != "adaptive"
110
110
  available_resolutions << file["rendition"]
111
111
  files << { file: file["link"], label: file["rendition"] }
@@ -116,6 +116,11 @@ module MultiVideoStreaming
116
116
  response["files"] = files
117
117
  response["available_resolutions"] = available_resolutions
118
118
  response["status"] = STATUS_EQUIVALENT[response["status"]]
119
+
120
+ if response["status"] != "available"
121
+ raise MultiVideoStreaming::Helpers::GetDefaultErrorMessage.not_available
122
+ end
123
+
119
124
  return self.response_instance.add_response(
120
125
  platform_name: "vimeo",
121
126
  status: "success",
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MultiVideoStreaming
4
+ module Errors
5
+ class InvalidS3MethodName < StandardError
6
+ def initialize(method)
7
+ super("Method name #{method} is invalid")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,5 +3,6 @@
3
3
  require "multi_video_streaming/errors/duplicated_platform_name"
4
4
  require "multi_video_streaming/errors/invalid_platform_name"
5
5
  require "multi_video_streaming/errors/invalid_platforms_param"
6
+ require "multi_video_streaming/errors/invalid_s3_method_name"
6
7
  require "multi_video_streaming/errors/missing_param"
7
8
  require "multi_video_streaming/errors/s3_is_not_valid_to_upload"
@@ -21,6 +21,10 @@ module MultiVideoStreaming
21
21
  def self.not_found(video_id:)
22
22
  "The video with id: #{video_id} does not exist."
23
23
  end
24
+
25
+ def self.not_available
26
+ "The video was successfully found, but it is currently not available."
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -4,7 +4,7 @@ module MultiVideoStreaming
4
4
  module Helpers
5
5
  class TitleFromUrl
6
6
  def self.get(url:)
7
- URI(url.to_s).path.split('/').last
7
+ URI(url.to_s).path.split('/').last.gsub!(/[^._0-9A-Za-z]/, '')
8
8
  end
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "multi_video_streaming/helpers/title_from_url.rb"
4
- require "multi_video_streaming/helpers/sort_files_array_by_label.rb"
5
- require "multi_video_streaming/helpers/get_default_error_message.rb"
3
+ require "multi_video_streaming/helpers/title_from_url"
4
+ require "multi_video_streaming/helpers/sort_files_array_by_label"
5
+ require "multi_video_streaming/helpers/get_default_error_message"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MultiVideoStreaming
4
+ module Utils
5
+ module S3
6
+ def self.generate_presign_url(method:, bucket:, key:, download:)
7
+ methods = { :get => :get_object, :put => :put_object, :delete => :delete_object }
8
+ method_to_generate_presign_url = methods[method]
9
+ raise MultiVideoStreaming::Errors::InvalidS3MethodName.new(method) if method_to_generate_presign_url.nil?
10
+ signer = Aws::S3::Presigner.new
11
+ if download
12
+ signer.presigned_url(method_to_generate_presign_url, bucket: bucket, key: key, expires_in: 900, whitelist_headers: ['response-content-disposition'], response_content_disposition: 'attachment')
13
+ else
14
+ signer.presigned_url(method_to_generate_presign_url, bucket: bucket, key: key, expires_in: 900)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "multi_video_streaming/utils/s3/generate_presign_url"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MultiVideoStreaming
4
- VERSION = "1.0.1.beta"
4
+ VERSION = "1.0.1.beta3"
5
5
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thread'
4
- require 'thwait'
5
3
  require "uri"
6
4
  require "net/http"
7
5
  require "openssl"
@@ -16,13 +14,12 @@ require "multi_video_streaming/factories"
16
14
  require "multi_video_streaming/errors"
17
15
  require "multi_video_streaming/response"
18
16
  require "multi_video_streaming/helpers"
17
+ require "multi_video_streaming/utils"
19
18
  require "multi_video_streaming/version"
20
19
  require "multi_video_streaming/validators"
21
20
 
22
21
  module MultiVideoStreaming
23
22
  def self.upload(url, *platforms)
24
- threads = []
25
-
26
23
  MultiVideoStreaming::Validators::PlatformsArrayValidator.validate(platforms_array: platforms)
27
24
  MultiVideoStreaming::Validators::PlatformsHashValidator.validate(platforms_hash: platforms, method: :create, number_of_platforms: platforms.length)
28
25
 
@@ -31,19 +28,16 @@ module MultiVideoStreaming
31
28
  https_service_instance = MultiVideoStreaming::Services::Https.new
32
29
 
33
30
  platforms.each do |platform|
34
- threads << Thread.new {
35
- platform_instance = MultiVideoStreaming::Factories::Drive.get_platform_instance(
36
- platform_name: platform[:platform_name],
37
- dependency_params: platform[:dependency_params],
38
- response_instance: response_instance,
39
- required_fields_validator_instance: required_fields_validator_instance,
40
- https_service_instance: https_service_instance
41
- )
42
- platform_instance.upload_video(url: url)
43
- }
31
+ platform_instance = MultiVideoStreaming::Factories::Drive.get_platform_instance(
32
+ platform_name: platform[:platform_name],
33
+ dependency_params: platform[:dependency_params],
34
+ response_instance: response_instance,
35
+ required_fields_validator_instance: required_fields_validator_instance,
36
+ https_service_instance: https_service_instance
37
+ )
38
+ platform_instance.upload_video(url: url)
44
39
  end
45
40
 
46
- ThreadsWait.all_waits(*threads)
47
41
  response_instance.get_all_response
48
42
  end
49
43
 
@@ -76,8 +70,6 @@ module MultiVideoStreaming
76
70
  end
77
71
 
78
72
  def self.delete(*platforms)
79
- threads = []
80
-
81
73
  MultiVideoStreaming::Validators::PlatformsArrayValidator.validate(platforms_array: platforms)
82
74
  MultiVideoStreaming::Validators::PlatformsHashValidator.validate(platforms_hash: platforms, method: :get, number_of_platforms: platforms.length)
83
75
 
@@ -86,19 +78,15 @@ module MultiVideoStreaming
86
78
  https_service_instance = MultiVideoStreaming::Services::Https.new
87
79
 
88
80
  platforms.each do |platform|
89
- threads << Thread.new {
90
- platform_instance = MultiVideoStreaming::Factories::Drive.get_platform_instance(
91
- platform_name: platform[:platform_name],
92
- dependency_params: platform[:dependency_params],
93
- response_instance: response_instance,
94
- required_fields_validator_instance: required_fields_validator_instance,
95
- https_service_instance: https_service_instance
96
- )
97
- platform_instance.delete_video
98
- }
81
+ platform_instance = MultiVideoStreaming::Factories::Drive.get_platform_instance(
82
+ platform_name: platform[:platform_name],
83
+ dependency_params: platform[:dependency_params],
84
+ response_instance: response_instance,
85
+ required_fields_validator_instance: required_fields_validator_instance,
86
+ https_service_instance: https_service_instance
87
+ )
88
+ platform_instance.delete_video
99
89
  end
100
-
101
- ThreadsWait.all_waits(*threads)
102
90
  response_instance.get_all_response
103
91
  end
104
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_video_streaming
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.beta
4
+ version: 1.0.1.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Schmeller
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-09-29 00:00:00.000000000 Z
13
+ date: 2022-10-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -83,6 +83,7 @@ files:
83
83
  - lib/multi_video_streaming/errors/duplicated_platform_name.rb
84
84
  - lib/multi_video_streaming/errors/invalid_platform_name.rb
85
85
  - lib/multi_video_streaming/errors/invalid_platforms_param.rb
86
+ - lib/multi_video_streaming/errors/invalid_s3_method_name.rb
86
87
  - lib/multi_video_streaming/errors/missing_param.rb
87
88
  - lib/multi_video_streaming/errors/s3_is_not_valid_to_upload.rb
88
89
  - lib/multi_video_streaming/factories.rb
@@ -99,6 +100,8 @@ files:
99
100
  - lib/multi_video_streaming/response.rb
100
101
  - lib/multi_video_streaming/services.rb
101
102
  - lib/multi_video_streaming/services/https.rb
103
+ - lib/multi_video_streaming/utils.rb
104
+ - lib/multi_video_streaming/utils/s3/generate_presign_url.rb
102
105
  - lib/multi_video_streaming/validators.rb
103
106
  - lib/multi_video_streaming/validators/platform_name_validator.rb
104
107
  - lib/multi_video_streaming/validators/platforms_array_validator.rb