vidload 0.3.2 → 0.3.4

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: a24a8d21e0c6a4d1c29211c2fc730a34d7f27e1629cec415e3014820a7b13a2e
4
- data.tar.gz: 64b502cf0d8b0ddb8f3c7e17246df47c8a04e415b91d67c167a941f8bcf98cc8
3
+ metadata.gz: a4ec46038fec427696fc8d8e1f86c84f3df2d0ea39663a3a39daf5dfcafcd2c5
4
+ data.tar.gz: f519d1682b9fb02c9eaf123b9cc68850bf120234b84281cb9fd175dc1c40ba07
5
5
  SHA512:
6
- metadata.gz: 04e6bef3507ec3580f0ed69ddf427d9b6d9405ea7e46ddf35149e6babde4ee2f680670145bba4179282938dbc199e62bdd5124b3e2a06de5824025525c5d9a22
7
- data.tar.gz: 36613f4b862a7adeccf1b5581049e40e9f7e0f3cc3e9602d3e0c919e6f39178784989f636f285949facbc731b5d333d0ecef56eea13f2f5cc807b1d6efd19a12
6
+ metadata.gz: a4f75f282726d7c831bd716c6b7bcdb9fd892832350a8fb8d84b5a0c93801bf347fa6e3aaaccfb6fccc5d5733130083cf82c3a6b90609ff23b28e763751f855d
7
+ data.tar.gz: aaf65273085bff9ad12b516c6a264c96b07f1246c989b01a479583a402d6a1097d169c51596a324147003a4f0a52b876ac7625ec532bd682699a03d5a5d40d0d
@@ -5,12 +5,14 @@ require 'tty-spinner'
5
5
  require 'open3'
6
6
  require 'm3u8'
7
7
  require 'io/console'
8
+ require 'fileutils'
8
9
 
9
10
  module Vidload
10
11
  module Mp2t
11
12
  module Api
12
- DEMUXER_PATH = "#{__dir__}/remuxer.sh"
13
+ DEMUXER_PATH = "#{__dir__}/remuxer.sh".freeze
13
14
  VIDEO_DOWNLOADED_EVENT_QUEUE = Queue.new
15
+ VIDEO_START_DOWNLOAD_EVENT_QUEUE = Queue.new
14
16
  VIDEO_INDEX_EVENT_QUEUE = Queue.new
15
17
  ANSI_BOLD_WHITE = "\033[1;97m"
16
18
  ANSI_LIGHT_GREY = "\033[37m"
@@ -108,13 +110,19 @@ module Vidload
108
110
  # main func to be called in your own scripts defined under web/
109
111
  def download_video(video_starter_callbacks: [])
110
112
  Playwright.create(playwright_cli_executable_path: @kwargs[:playwright_cli_path]) do |playwright|
111
- browser = playwright.chromium.launch
113
+ browser = playwright.chromium.launch(headless: false)
112
114
  page = browser.new_page
113
115
 
114
116
  manage_video_download(page, *video_starter_callbacks)
115
- wait_until_video_downloaded
116
117
 
117
- browser.close
118
+ if wait_until_video_start_downloading(timeout: 10).nil?
119
+ puts 'Not possible to download video. Restarting new session'
120
+ browser.close
121
+ download_video(video_starter_callbacks: video_starter_callbacks)
122
+ else
123
+ wait_until_video_downloaded
124
+ browser.close
125
+ end
118
126
  end
119
127
  end
120
128
 
@@ -156,8 +164,14 @@ module Vidload
156
164
  VIDEO_DOWNLOADED_EVENT_QUEUE.pop
157
165
  end
158
166
 
167
+ def wait_until_video_start_downloading(timeout:)
168
+ VIDEO_START_DOWNLOAD_EVENT_QUEUE.pop(timeout: timeout)
169
+ end
170
+
159
171
  def trigger_video_download(video_url, seg_qty)
172
+ VIDEO_START_DOWNLOAD_EVENT_QUEUE << true
160
173
  puts 'Video starts. Starting download...'
174
+ FileUtils.mkdir_p(@kwargs[:output_dir], mode: 0o755)
161
175
  run_cmd(DEMUXER_PATH, video_url, "#{@kwargs[:output_dir]}#{@kwargs[:video_name]}",
162
176
  @kwargs[:video_referer]) do |line|
163
177
  if (line.include?('hls @') || line.include?('https @')) && line.match?(/#{@kwargs[:ts_seg_pattern]}/i)
@@ -209,11 +223,7 @@ module Vidload
209
223
 
210
224
  _rows, cols = IO.console.winsize
211
225
  @lines.each do |line|
212
- if line.length > cols
213
- puts "#{line.slice(0, cols - 3)}..."
214
- else
215
- puts line
216
- end
226
+ line.length > cols ? (puts "#{line.slice(0, cols - 3)}...") : (puts line)
217
227
  end
218
228
  end
219
229
 
@@ -107,9 +107,8 @@ module Vidload
107
107
  end
108
108
 
109
109
  def listen_to_video_starts(_page, response)
110
- unless response.url.start_with?(@kwargs[:video_hub_url]) && response.headers['content-type']&.include?('video/mp4')
111
- return
112
- end
110
+ content_type = response.headers['content-type']
111
+ return unless response.url.start_with?(@kwargs[:video_hub_url]) && content_type&.include?('video/mp4')
113
112
 
114
113
  body = response.text
115
114
  File.open("video-#{@kwargs[:video_name]}.mp4", 'wb') do |f|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vidload
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patacode <pata.codegineer@gmail.com>
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: '0'
122
+ version: '3.3'
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="