multi_video_streaming 1.0.0.beta → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c1ae1d10ba98cf2adfd9db15e18956c5ec601e0afdd47f4857c5313d5b5661c
4
- data.tar.gz: e972c5a015cb6e813c9423d21a0993646aacc807b549797f6db638f3686823c4
3
+ metadata.gz: 92365a32422c9c1f7706b66f408f0afd9e8d35c71c4c1adfc7b97eeda74f5f0b
4
+ data.tar.gz: d7bda7860ead53a260ab9053f375ac1481ab7d65d7715f18d6fac8883205ece7
5
5
  SHA512:
6
- metadata.gz: 1feb06fa08e5ec6775c208ea859371083956b99d95c71b419b040823cfa307156c1acaeb110ae012bf12c6d573636ef800752d3fb3ed3ed74415ecb6db1bac2f
7
- data.tar.gz: a4cf1f7c854d9b3b4838e459c75417441078fccc2ac2b09ff02751855d29579126529a701efc7303da03ea5a96604da6ca8d746e2b5158b7da75a610b1c99982
6
+ metadata.gz: b920bd4787764978ddf96c2841dc67988bd5db4e67ddfe628d08557cba1a66678482b424a41544662234dcac1c6cb3f3fcf60b0a77a2d23693ecc3b551f0a354
7
+ data.tar.gz: 98a84c8c5130240d39159b4d313f515ac91a8c2a973658004a0bc4a84a3559e6612d97f2d588cdedd22ddec5cb8f92cfe78d8587f2b9b1d213cb000d6429b07f
@@ -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",
@@ -110,11 +110,16 @@ module MultiVideoStreaming
110
110
  }
111
111
  end
112
112
 
113
+ MultiVideoStreaming::Helpers::SortFilesArrayByLabel.sort(array: files)
113
114
  response["files"] = files
114
115
  status = STATUS_EQUIVALENT[response["status"].to_s]
115
116
 
116
117
  response["status"] = STATUS_EQUIVALENT[response["status"].to_s]
117
118
 
119
+ if response["status"] != "available"
120
+ raise MultiVideoStreaming::Helpers::GetDefaultErrorMessage.not_available
121
+ end
122
+
118
123
  return self.response_instance.add_response(
119
124
  platform_name: "bunny",
120
125
  status: "success",
@@ -29,17 +29,18 @@ 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
33
  data = {
33
34
  "key": response.key,
34
35
  "title": response.key,
35
36
  "status": STATUS_EQUIVALENT[:true],
36
37
  "files": [
37
38
  {
38
- file: video_url
39
+ file: url_signed
39
40
  }
40
41
  ],
41
42
  "available_resolutions": [],
42
- "direct_play": video_url,
43
+ "direct_play": url_signed,
43
44
  "date_uploaded": response.data.last_modified
44
45
  }
45
46
 
@@ -139,6 +140,11 @@ module MultiVideoStreaming
139
140
  Aws.config.update(credentials: credentials, region: region, force_path_style: true)
140
141
  end
141
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
142
148
  end
143
149
  end
144
150
  end
@@ -105,16 +105,22 @@ 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"] }
112
112
  end
113
113
  end
114
114
 
115
+ MultiVideoStreaming::Helpers::SortFilesArrayByLabel.sort(array: files)
115
116
  response["files"] = files
116
117
  response["available_resolutions"] = available_resolutions
117
118
  response["status"] = STATUS_EQUIVALENT[response["status"]]
119
+
120
+ if response["status"] != "available"
121
+ raise MultiVideoStreaming::Helpers::GetDefaultErrorMessage.not_available
122
+ end
123
+
118
124
  return self.response_instance.add_response(
119
125
  platform_name: "vimeo",
120
126
  status: "success",
@@ -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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MultiVideoStreaming
4
+ module Helpers
5
+ class SortFilesArrayByLabel
6
+ def self.sort(array:)
7
+ array.sort! { |lastFile, nextFile| /[\d]+/.match(nextFile[:label])[0].to_i <=> /[\d]+/.match(lastFile[:label])[0].to_i }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "multi_video_streaming/helpers/title_from_url.rb"
4
+ require "multi_video_streaming/helpers/sort_files_array_by_label.rb"
4
5
  require "multi_video_streaming/helpers/get_default_error_message.rb"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MultiVideoStreaming
4
- VERSION = "1.0.0.beta"
4
+ VERSION = "1.0.0.beta1"
5
5
  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.0.beta
4
+ version: 1.0.0.beta1
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-08-10 00:00:00.000000000 Z
13
+ date: 2022-09-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -89,6 +89,7 @@ files:
89
89
  - lib/multi_video_streaming/factories/drive.rb
90
90
  - lib/multi_video_streaming/helpers.rb
91
91
  - lib/multi_video_streaming/helpers/get_default_error_message.rb
92
+ - lib/multi_video_streaming/helpers/sort_files_array_by_label.rb
92
93
  - lib/multi_video_streaming/helpers/title_from_url.rb
93
94
  - lib/multi_video_streaming/platforms_support.rb
94
95
  - lib/multi_video_streaming/protocols.rb