eivid 1.0.4 → 1.0.9

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: f3be70d9d3f995714108df4fb59cc7d437f02170ec3121ea58b349843873b149
4
- data.tar.gz: '03315880246a5a57c4be6062fa6e6a3d19ba171cf16b783a9a323023265da1b4'
3
+ metadata.gz: 077c29117cf2cded883cfaa9a2fa6357ad7abe30f67c7bc98f2ce53a001bc696
4
+ data.tar.gz: 2968dca76bba1938d819fcdd44d982119f8e5811e8db15a91b1700ca1918a063
5
5
  SHA512:
6
- metadata.gz: 78b739ae6ad9a47dc281a2bbbe268cc87b26d600bc183d2907d63f036e61a237ecc22e5cb275019d01c6aeaa291cb20424f6146e8c15fae4c72e00a1f6e38d4a
7
- data.tar.gz: fbb92b8cee87d4c61eae547dffd79358245fd92c6536d7b9ff68120d06e3d8d4289bcb4dd2ed4650a14b5ef34492b62f2576bee8be57e89735de19ddc5c0d56e
6
+ metadata.gz: 3d97c505a4859479a8046bc0dfdd07b4f291e577d359399e23a6a8e37a4277bb5bfb597cd0edc850e200ca9234409e5ebc89f81308301a96025f7b3788249f90
7
+ data.tar.gz: 3bac18de6b24adc6643c2615e889e8846d592b168da890bb4b244455ed9902d97467c72103b0b40d4bd0011fada3406e1a41bc4489e24bad3c787c0f5f04efa6
@@ -0,0 +1,4 @@
1
+ module Eivid
2
+ class VideoUnavailableAllAttemptsFailedError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Eivid
2
+ class VideoUrlsAllAttemptsFailedError < StandardError
3
+ end
4
+ end
@@ -1,7 +1,12 @@
1
1
  module Eivid
2
2
  class CheckVimeoStatusJob < ApplicationJob
3
3
 
4
- retry_on VideoUnavailableError, wait: 10.seconds, attempts: 50
4
+ retry_on(VideoUnavailableError, wait: 10.seconds, attempts: 50) do |job, error|
5
+ raise Eivid::VideoUnavailableAllAttemptsFailedError, "failed after the set max attempts (#{job.executions} times)"
6
+ end
7
+
8
+ discard_on ActiveJob::DeserializationError
9
+
5
10
  after_perform :poll_vimeo_urls
6
11
 
7
12
  def perform(video_record:)
@@ -0,0 +1,24 @@
1
+ module Eivid
2
+ class GetVimeoHdUrlJob < ApplicationJob
3
+
4
+ include Eivid::GetVimeoUrlsMixin
5
+
6
+ def perform(video_record:, vimeo_id:)
7
+ @video_record = video_record
8
+ @vimeo_id = vimeo_id
9
+
10
+ set_response
11
+ set_url_hd
12
+
13
+ return unless @url_hd
14
+ update_record
15
+ end
16
+
17
+ private
18
+
19
+ def update_record
20
+ @video_record.update(url_hd: @url_hd)
21
+ end
22
+
23
+ end
24
+ end
@@ -1,7 +1,13 @@
1
1
  module Eivid
2
2
  class GetVimeoUrlsJob < ApplicationJob
3
3
 
4
- retry_on VideoUrlsUnavailableError, wait: 10.seconds, attempts: 50
4
+ include Eivid::GetVimeoUrlsMixin
5
+
6
+ retry_on(VideoUrlsUnavailableError, wait: 10.seconds, attempts: 50) do |job, error|
7
+ raise Eivid::VideoUrlsAllAttemptsFailedError, "failed after the set max attempts (#{job.executions} times)"
8
+ end
9
+
10
+ discard_on ActiveJob::DeserializationError
5
11
 
6
12
  def perform(video_record:, vimeo_id:)
7
13
  @video_record = video_record
@@ -16,55 +22,33 @@ module Eivid
16
22
  validate_url_thumbnail
17
23
 
18
24
  update_record
25
+ schedule_hd_url_job
19
26
  notify_front
20
27
  end
21
28
 
22
29
  private
23
30
 
24
- def set_response
25
- @response = Eivid::RequestService.get_video @vimeo_id
26
- end
27
-
28
- def set_url_sd
29
- @url_sd = dig_video_url :sd
30
- end
31
-
32
- def set_url_hd
33
- @url_hd = dig_video_url :hd
34
- end
35
-
36
- def dig_video_url(definition)
37
- @response[:files]&.find { |video| video[:quality] == definition.to_s }&.dig(:link)
31
+ def notify_front
32
+ data = { video: @video_record.slice(:id, :user_id), progress: { percentage: 100, step: "All video versions are available on Vimeo." } }
33
+ NotifyFrontService.progress('notify_method_on_versions_available', data)
38
34
  end
39
35
 
40
- def set_url_thumbnail
41
- @url_thumbnail = find_high_res_thumbnail || find_low_res_thumbnail
36
+ def update_record
37
+ @video_record.update(uploaded: true, url_sd: @url_sd, url_hd: @url_hd, url_thumbnail: @url_thumbnail)
42
38
  end
43
39
 
44
- def find_high_res_thumbnail
45
- @response&.dig(:pictures, :sizes)&.find { |url| url[:width] == 960 && url[:height] == 540 }&.dig(:link_with_play_button)
40
+ def schedule_hd_url_job
41
+ Eivid::GetVimeoHdUrlJob.set(wait: 5.minutes).perform_later(video_record: @video_record, vimeo_id: @vimeo_id)
46
42
  end
47
43
 
48
- def find_low_res_thumbnail
49
- @response&.dig(:pictures, :sizes)&.find { |url| url[:width] == 640 && url[:height] == 360 }&.dig(:link_with_play_button)
50
- end
51
44
 
52
45
  def validate_url_presence
53
- raise Eivid::VideoUrlsUnavailableError unless (@url_sd && @url_hd && @url_thumbnail)
46
+ raise Eivid::VideoUrlsUnavailableError unless @url_thumbnail && @url_sd
54
47
  end
55
48
 
56
49
  def validate_url_thumbnail
57
50
  raise Eivid::VideoUrlsUnavailableError if @url_thumbnail.include? 'video%2Fdefault'
58
51
  end
59
52
 
60
- def update_record
61
- @video_record.update(uploaded: true, url_sd: @url_sd, url_hd: @url_hd, url_thumbnail: @url_thumbnail)
62
- end
63
-
64
- def notify_front
65
- data = { video: @video_record.slice(:id, :user_id), progress: { percentage: 100, step: "All video versions are available on Vimeo." } }
66
- NotifyFrontService.progress('notify_method_on_versions_available', data)
67
- end
68
-
69
53
  end
70
54
  end
@@ -0,0 +1,36 @@
1
+ module Eivid::GetVimeoUrlsMixin
2
+ extend ActiveSupport::Concern
3
+ included do
4
+
5
+ private
6
+
7
+ def set_response
8
+ @response = Eivid::RequestService.get_video @vimeo_id
9
+ end
10
+
11
+ def set_url_sd
12
+ @url_sd = dig_video_url :sd
13
+ end
14
+
15
+ def set_url_hd
16
+ @url_hd = dig_video_url :hd
17
+ end
18
+
19
+ def dig_video_url(definition)
20
+ @response[:files]&.find { |video| video[:quality] == definition.to_s }&.dig(:link)
21
+ end
22
+
23
+ def set_url_thumbnail
24
+ @url_thumbnail = find_high_res_thumbnail || find_low_res_thumbnail
25
+ end
26
+
27
+ def find_high_res_thumbnail
28
+ @response&.dig(:pictures, :sizes)&.find { |url| url[:width] == 960 && url[:height] == 540 }&.dig(:link_with_play_button)
29
+ end
30
+
31
+ def find_low_res_thumbnail
32
+ @response&.dig(:pictures, :sizes)&.find { |url| url[:width] == 640 && url[:height] == 360 }&.dig(:link_with_play_button)
33
+ end
34
+
35
+ end
36
+ end
@@ -12,5 +12,7 @@ module Eivid::Concerns::MainApp::VideoConcerns
12
12
  scope :has_processed_video, -> { joins(:videos).where('eivid_videos.uploaded': true).distinct }
13
13
  scope :has_unprocessed_video, -> { joins(:videos).where('eivid_videos.uploaded' => false).distinct }
14
14
 
15
+ scope :has_video_from_user, -> (user_id) { joins(:videos).where('eivid_videos.user_id = ?', user_id) }
16
+
15
17
  end
16
18
  end
@@ -6,7 +6,7 @@ module Eivid::Concerns::RequestService::ManageFolder
6
6
  end
7
7
 
8
8
  def create_folder(namespace:, id:)
9
- body = { "name" => "#{Rails.env}_#{namespace}_#{id}" }
9
+ body = { "name" => "#{rails_environment}_#{namespace}_#{id}" }
10
10
 
11
11
  @response = HTTParty.post Eivid::RequestService::FOLDER_URL, body: body.to_json, headers: default_headers
12
12
  get_folder_id
@@ -20,6 +20,11 @@ module Eivid::Concerns::RequestService::ManageFolder
20
20
  HTTParty.put endpoint, headers: default_headers
21
21
  end
22
22
 
23
+ def rails_environment
24
+ return "test" if Figaro.env.IS_TEST_SERVER
25
+ Rails.env
26
+ end
27
+
23
28
  private
24
29
 
25
30
  def get_folder_id
data/lib/eivid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eivid
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eivid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-18 00:00:00.000000000 Z
11
+ date: 2021-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -71,11 +71,15 @@ files:
71
71
  - app/errors/eivid/maximum_vimeo_poll_reached_error.rb
72
72
  - app/errors/eivid/video_file_not_present_error.rb
73
73
  - app/errors/eivid/video_file_size_too_big_error.rb
74
+ - app/errors/eivid/video_unavailable_all_attempts_failed_error.rb
74
75
  - app/errors/eivid/video_unavailable_error.rb
76
+ - app/errors/eivid/video_urls_all_attempts_failed_error.rb
75
77
  - app/errors/eivid/video_urls_unavailable_error.rb
76
78
  - app/jobs/eivid/application_job.rb
77
79
  - app/jobs/eivid/check_vimeo_status_job.rb
80
+ - app/jobs/eivid/get_vimeo_hd_url_job.rb
78
81
  - app/jobs/eivid/get_vimeo_urls_job.rb
82
+ - app/jobs/eivid/get_vimeo_urls_mixin.rb
79
83
  - app/jobs/eivid/upload_vimeo_job.rb
80
84
  - app/mailers/eivid/application_mailer.rb
81
85
  - app/models/eivid/application_record.rb