vidload 0.3.4 → 0.5.0

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: a4ec46038fec427696fc8d8e1f86c84f3df2d0ea39663a3a39daf5dfcafcd2c5
4
- data.tar.gz: f519d1682b9fb02c9eaf123b9cc68850bf120234b84281cb9fd175dc1c40ba07
3
+ metadata.gz: d991f1940c3b16c4d30982c802a24b21aa1e467fc0e5f3544bacce4b711d8e8a
4
+ data.tar.gz: 303da39859fa070f77c47da10b0d8070e4e8bd0edb525141d7e113d021ea81da
5
5
  SHA512:
6
- metadata.gz: a4f75f282726d7c831bd716c6b7bcdb9fd892832350a8fb8d84b5a0c93801bf347fa6e3aaaccfb6fccc5d5733130083cf82c3a6b90609ff23b28e763751f855d
7
- data.tar.gz: aaf65273085bff9ad12b516c6a264c96b07f1246c989b01a479583a402d6a1097d169c51596a324147003a4f0a52b876ac7625ec532bd682699a03d5a5d40d0d
6
+ metadata.gz: 1654b94190934e9d8d771564e33d601c2e823d01a93cc649574f7124617e1bca33c01a0dde97f285268d8e59be42637c7f43d9da41832c446da81d83f5d16bc8
7
+ data.tar.gz: 04fb1174a63b6675e290be8c05448b6db8e0bfc402bbc5e8a42b5840379a4c78c245f3b204f5b8420b3de34cd69b4e37157c1db5382b712c318762c581689246
data/lib/vidload/cli.rb CHANGED
@@ -8,6 +8,8 @@ module Vidload
8
8
  method_option :video_name, type: :string, required: false
9
9
  method_option :author_name, type: :string, required: false
10
10
  method_option :output_dir, type: :string, required: false
11
+ method_option :non_headless, type: :boolean, default: false
12
+ method_option :author_dir, type: :boolean, default: false
11
13
  method_option :hls_url, type: :string, required: true
12
14
  method_option :master_playlist_name, type: :string, required: true
13
15
  method_option :playwright_cli_path, type: :string, required: true
@@ -27,6 +29,7 @@ module Vidload
27
29
  method_option :video_name, type: :string, required: false
28
30
  method_option :video_hub_url, type: :string, required: true
29
31
  method_option :playwright_cli_path, type: :string, required: true
32
+ method_option :non_headless, type: :boolean, default: false
30
33
  def mp4(video_url)
31
34
  params = {
32
35
  video_url: video_url,
@@ -46,6 +46,21 @@ module Vidload
46
46
  self
47
47
  end
48
48
 
49
+ def with_output_dir(output_dir)
50
+ @kwargs[:output_dir] = output_dir
51
+ self
52
+ end
53
+
54
+ def non_headless?(non_headless)
55
+ @kwargs[:non_headless] = non_headless
56
+ self
57
+ end
58
+
59
+ def author_dir?(author_dir)
60
+ @kwargs[:author_dir] = author_dir
61
+ self
62
+ end
63
+
49
64
  def with_hls_url(hls_url)
50
65
  @kwargs[:hls_url] = hls_url
51
66
  self
@@ -76,17 +91,11 @@ module Vidload
76
91
  self
77
92
  end
78
93
 
79
- def with_output_dir(output_dir)
80
- @kwargs[:output_dir] = output_dir
81
- self
82
- end
83
-
84
94
  def build
85
95
  REQUIRED_ARGS.each do |required_arg|
86
96
  raise ArgumentError, "#{required_arg} must be provided" unless @kwargs[required_arg]
87
97
  end
88
98
 
89
- @kwargs[:output_dir] = './' unless @kwargs[:output_dir]
90
99
  @kwargs[:video_name] = "#{@kwargs[:author_name]}_#{@kwargs[:video_name]}" if @kwargs[:author_name]
91
100
 
92
101
  Downloader.new(**@kwargs)
@@ -110,7 +119,7 @@ module Vidload
110
119
  # main func to be called in your own scripts defined under web/
111
120
  def download_video(video_starter_callbacks: [])
112
121
  Playwright.create(playwright_cli_executable_path: @kwargs[:playwright_cli_path]) do |playwright|
113
- browser = playwright.chromium.launch(headless: false)
122
+ browser = playwright.chromium.launch(headless: !@kwargs[:non_headless])
114
123
  page = browser.new_page
115
124
 
116
125
  manage_video_download(page, *video_starter_callbacks)
@@ -171,8 +180,19 @@ module Vidload
171
180
  def trigger_video_download(video_url, seg_qty)
172
181
  VIDEO_START_DOWNLOAD_EVENT_QUEUE << true
173
182
  puts 'Video starts. Starting download...'
174
- FileUtils.mkdir_p(@kwargs[:output_dir], mode: 0o755)
175
- run_cmd(DEMUXER_PATH, video_url, "#{@kwargs[:output_dir]}#{@kwargs[:video_name]}",
183
+ video_parent_dirs = if @kwargs[:author_dir]
184
+ if @kwargs[:output_dir]
185
+ "#{@kwargs[:output_dir]}/#{@kwargs[:author_name]}"
186
+ else
187
+ @kwargs[:author_name]
188
+ end
189
+ else
190
+ @kwargs[:output_dir]
191
+ end
192
+
193
+ puts video_parent_dirs
194
+ FileUtils.mkdir_p(video_parent_dirs, mode: 0o755)
195
+ run_cmd(DEMUXER_PATH, video_url, "#{video_parent_dirs}/#{@kwargs[:video_name]}",
176
196
  @kwargs[:video_referer]) do |line|
177
197
  if (line.include?('hls @') || line.include?('https @')) && line.match?(/#{@kwargs[:ts_seg_pattern]}/i)
178
198
  seg_nb = line.match(/#{@kwargs[:ts_seg_pattern]}/i)[:seg_nb]
@@ -181,7 +201,7 @@ module Vidload
181
201
  end
182
202
  end
183
203
  print "\r\e[2K"
184
- puts "✔ Video downloaded successfully! Available in #{@kwargs[:output_dir]}#{@kwargs[:video_name]}.mp4"
204
+ puts "✔ Video downloaded successfully! Available in #{video_parent_dirs}/#{@kwargs[:video_name]}.mp4"
185
205
  VIDEO_DOWNLOADED_EVENT_QUEUE << true
186
206
  end
187
207
 
@@ -22,13 +22,13 @@ module Vidload
22
22
  self
23
23
  end
24
24
 
25
- def with_video_name(video_name)
26
- @kwargs[:video_name] = video_name
25
+ def with_video_url(video_url)
26
+ @kwargs[:video_url] = video_url
27
27
  self
28
28
  end
29
29
 
30
- def with_video_url(video_url)
31
- @kwargs[:video_url] = video_url
30
+ def with_video_name(video_name)
31
+ @kwargs[:video_name] = video_name
32
32
  self
33
33
  end
34
34
 
@@ -42,6 +42,11 @@ module Vidload
42
42
  self
43
43
  end
44
44
 
45
+ def non_headless?(non_headless)
46
+ @kwargs[:non_headless] = non_headless
47
+ self
48
+ end
49
+
45
50
  def build
46
51
  REQUIRED_ARGS.each do |required_arg|
47
52
  raise ArgumentError, "#{required_arg} must be provided" unless @kwargs[required_arg]
@@ -69,7 +74,7 @@ module Vidload
69
74
  # main func to be called in your own scripts defined under web/
70
75
  def download_video
71
76
  Playwright.create(playwright_cli_executable_path: @kwargs[:playwright_cli_path]) do |playwright|
72
- browser = playwright.chromium.launch
77
+ browser = playwright.chromium.launch(headless: !@kwargs[:non_headless])
73
78
  page = browser.new_page
74
79
 
75
80
  manage_video_download(page)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vidload
4
- VERSION = '0.3.4'
4
+ VERSION = '0.5.0'
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.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patacode <pata.codegineer@gmail.com>