eivid 1.0.3 → 1.0.8

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: 170f1105ae880129ff80583493e23aa7fb59d6753b0e6ee235577d01d6cab4e6
4
- data.tar.gz: 44f34c2db366c087f13a1cdbe4e9225a997cb8b7a498707aa2078dc9e1f049ca
3
+ metadata.gz: 18c4c4d966bf527f9b36d9d30fa7f0bd1a78cbe85ed82ed02264c2b15c23b022
4
+ data.tar.gz: 79899e7a07874171fba933e51a53bf4d5b6d9a531300ee6b59ac39f8fdd09070
5
5
  SHA512:
6
- metadata.gz: c54d80a42768cb50f24f253e66a03da55bc0ea9cf27601cb1c0cc7a80ddfe967fe54797c1b9d012daf56796405df6a6cb5dde02cf7913dc606bd800d7a270f73
7
- data.tar.gz: d20be465508e7e42f7d2fce872f769ea8bc0074d80a4a04cf8d01ccfa702db8782b8a08091cb59b7aff0a0c654c1740785e56ea5aefc5131b8da3d3f6d25560f
6
+ metadata.gz: 4b4c8890c237800b56c5bad688fc025a1fb2ed4b835afdb103435281dd421d14587a35f99265f8fdd0073e72c5ba8ffebaf6ce4dc6bbb88b509aa48052661f7a
7
+ data.tar.gz: 3016c7ad6bac8c16a5369516840269d53ce45f5c25a5f92fedebe16a042fd56324e01c23a8a1f018bb16cfed07c683c46250fadce006285d3df70f91537be56d
@@ -13,7 +13,7 @@ module Eivid
13
13
  before_action :validate_video_file, only: [:upload_video]
14
14
 
15
15
  def upload_video
16
- record = UploadService.upload(owner: @owner, user: @user, video_file: video_params["video_file"])
16
+ record = UploadService.upload(owner: @owner, user: @user, video_file: video_params["video_file"], video_title: video_title)
17
17
  render json: record
18
18
  end
19
19
 
@@ -44,5 +44,10 @@ module Eivid
44
44
  params.permit("video_file")
45
45
  end
46
46
 
47
+ def video_title
48
+ title = video_params["video_file"].original_filename
49
+ title.include?('.') ? title.split('.')[0..-2].join('.') : title
50
+ end
51
+
47
52
  end
48
53
  end
@@ -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,47 +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
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)
30
34
  end
31
35
 
32
- def set_url_hd
33
- @url_hd = dig_video_url :hd
36
+ def update_record
37
+ @video_record.update(uploaded: true, url_sd: @url_sd, url_hd: @url_hd, url_thumbnail: @url_thumbnail)
34
38
  end
35
39
 
36
- def dig_video_url(definition)
37
- @response[:files]&.find { |video| video[:quality] == definition.to_s }&.dig(:link)
40
+ def schedule_hd_url_job
41
+ Eivid::GetVimeoHdUrlJob.set(wait: 5.minutes).perform_later(video_record: @video_record, vimeo_id: @vimeo_id)
38
42
  end
39
43
 
40
- def set_url_thumbnail
41
- @url_thumbnail = @response&.dig(:pictures, :sizes)&.find { |url| url[:width] == 640 && url[:height] == 360 }&.dig(:link_with_play_button)
42
- end
43
44
 
44
45
  def validate_url_presence
45
- raise Eivid::VideoUrlsUnavailableError unless (@url_sd && @url_hd && @url_thumbnail)
46
+ raise Eivid::VideoUrlsUnavailableError unless @url_thumbnail && @url_sd
46
47
  end
47
48
 
48
49
  def validate_url_thumbnail
49
50
  raise Eivid::VideoUrlsUnavailableError if @url_thumbnail.include? 'video%2Fdefault'
50
51
  end
51
52
 
52
- def update_record
53
- @video_record.update(uploaded: true, url_sd: @url_sd, url_hd: @url_hd, url_thumbnail: @url_thumbnail)
54
- end
55
-
56
- def notify_front
57
- data = { video: @video_record.slice(:id, :user_id), progress: { percentage: 100, step: "All video versions are available on Vimeo." } }
58
- NotifyFrontService.progress('notify_method_on_versions_available', data)
59
- end
60
-
61
53
  end
62
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
@@ -1,9 +1,9 @@
1
1
  module Eivid::UploadService
2
2
  class << self
3
3
 
4
- def upload(owner:, user: nil, video_file:)
4
+ def upload(owner:, user: nil, video_file:, video_title:)
5
5
  @video_file = video_file
6
- @video_record = Eivid::Video.create(owner_id: owner.id, user_id: user&.id)
6
+ @video_record = Eivid::Video.create(owner_id: owner.id, user_id: user&.id, title: video_title)
7
7
  @user = user
8
8
  @file_name, @file_ext = @video_file.original_filename.split('.')
9
9
 
@@ -0,0 +1,5 @@
1
+ class AddTitleToVideo < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :eivid_videos, :title, :string
4
+ end
5
+ end
data/lib/eivid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eivid
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.8'
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.3
4
+ version: 1.0.8
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-06 00:00:00.000000000 Z
11
+ date: 2021-08-23 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
@@ -111,6 +115,7 @@ files:
111
115
  - db/migrate/20210419122001_change_url_to_embedded_url.rb
112
116
  - db/migrate/20210419122752_add_video_urls_to_videos.rb
113
117
  - db/migrate/20210420120017_add_user_id_to_eivid_videos.rb
118
+ - db/migrate/20210818121057_add_title_to_video.rb
114
119
  - lib/eivid.rb
115
120
  - lib/eivid/engine.rb
116
121
  - lib/eivid/version.rb