eivid 1.0.2 → 1.0.7

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: 8b3eceac4a1719f232b34c2fca6011cef48444cfe64646109dfde436b7f12557
4
- data.tar.gz: f9578d5f26ae5a6864dfc6a59d0cc1ff49ccd72520cb7008b0ff21fcf93fd98c
3
+ metadata.gz: b995a651b9c7d8ae829041db1b2dcb8bd272ff646687db1b714d4c71f01f4892
4
+ data.tar.gz: e9142b432d08eb85f21217965af5ddca7a5ba4962401a219e0c4f236980072a4
5
5
  SHA512:
6
- metadata.gz: 3a5dc2db193354a88552cefc6b07512e2d079e8a05a2ecf4ba4f32e902451950b5401930adfdf5ec8b4f2cfc1f3007b7a2542b98e6eddcaac928337369f2cb6a
7
- data.tar.gz: 8cceee092aa705daa738624cae4c245bf969f0ee01c215b2d8a531527bd01a20a87950ebade229103e3ce3672a5b6aec3bf86ad78cc2bbc5148531ade64acf22
6
+ metadata.gz: 9b48dadeee80c0bee563b30e5852016b7e23184d08a494ceca635aa3f160721c5ba8b0e41e9d32bb9be7a0eafc9c61273d1bc1c8a07b89985b8a5f96de4b40c4
7
+ data.tar.gz: 67500bcd2c6723eaa6900aaef6a6b31786c0adb64b6fcd12ccdf11962d77f8d388058dc170957ef68020d89f448c1a20f9dbdb8cef4f7236dfb1270fd5a186d3
data/README.md CHANGED
@@ -10,18 +10,8 @@ Add the following to your application's Gemfile and run $bundle:
10
10
 
11
11
  ```ruby
12
12
 
13
- gem 'eivid', git: 'https://github.com/eitje-app/eivid_engine', branch: 'production'
13
+ gem 'eivid', "1.0.0" # check the latest version on: https://rubygems.org/gems/eivid
14
14
 
15
- ```
16
- Or, for development purposes, add instead:
17
-
18
- ```ruby
19
- local_eivid_path = "/Users/jurriaanschrofer/Documents/eivid"
20
- if ENV["RAILS_ENV"] == 'development' && Dir.glob(local_eivid_path).any?
21
- gem 'eivid', path: local_eivid_path
22
- else
23
- gem 'eivid', git: 'https://github.com/eitje-app/eivid_engine', branch: 'production'
24
- end
25
15
  ```
26
16
 
27
17
  Add the following file to your app's config/initializers directory:
@@ -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
@@ -3,7 +3,7 @@ module Eivid
3
3
 
4
4
  has_many :videos
5
5
 
6
- validates :external_id, presence: true #, uniqueness: true # comment out for dev only
6
+ validates :external_id, presence: true, uniqueness: true
7
7
 
8
8
  before_create :get_folder_id
9
9
 
@@ -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.2'
2
+ VERSION = '1.0.7'
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.2
4
+ version: 1.0.7
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-04 00:00:00.000000000 Z
11
+ date: 2021-08-19 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