vidload 0.2.1 → 0.3.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 +4 -4
- data/lib/vidload/cli.rb +17 -0
- data/lib/vidload/mp4/api.rb +130 -0
- data/lib/vidload/mp4.rb +7 -0
- data/lib/vidload/version.rb +1 -1
- data/lib/vidload.rb +1 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d7f2ad6f46978b5cad7216f00d0c9a74bb2cd7ec537ddab8145d9f8bd0914cde
|
|
4
|
+
data.tar.gz: 0146cabc4cb8f7f39c2b3adaa76293eefa86acf4233890a5116f4988ef590fdd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c195fbe2098e82a3da3317f61cacf1c10f667a6195c0b4a0ebd9d38eee8cec222703cf00aeb1cba48ff14b9d0a98ffc6334ef5a14f4b74aad259683db471ff4c
|
|
7
|
+
data.tar.gz: dd4a308b63da84aa3dcfc8796556f8f48fc53eeabb73c92d39ed2689181bc72b1bb99c776e67cd352db415d405b759975d40c3c85ae877bf898c0644bd95dadf
|
data/lib/vidload/cli.rb
CHANGED
|
@@ -23,10 +23,27 @@ module Vidload
|
|
|
23
23
|
process_mp2t(params)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
desc 'mp4 VIDEO_URL', 'download a mp4 video'
|
|
27
|
+
method_option :video_name, type: :string, required: false
|
|
28
|
+
method_option :video_hub_url, type: :string, required: true
|
|
29
|
+
method_option :playwright_cli_path, type: :string, required: true
|
|
30
|
+
def mp4(video_url)
|
|
31
|
+
params = {
|
|
32
|
+
video_url: video_url,
|
|
33
|
+
**options
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
process_mp4(params)
|
|
37
|
+
end
|
|
38
|
+
|
|
26
39
|
private
|
|
27
40
|
|
|
28
41
|
def process_mp2t(params)
|
|
29
42
|
raise NotImplementedError
|
|
30
43
|
end
|
|
44
|
+
|
|
45
|
+
def process_mp4(params)
|
|
46
|
+
raise NotImplementedError
|
|
47
|
+
end
|
|
31
48
|
end
|
|
32
49
|
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'playwright'
|
|
4
|
+
require 'open3'
|
|
5
|
+
require 'io/console'
|
|
6
|
+
|
|
7
|
+
module Vidload
|
|
8
|
+
module Mp4
|
|
9
|
+
module Api
|
|
10
|
+
VIDEO_DOWNLOADED_EVENT_QUEUE = Queue.new
|
|
11
|
+
|
|
12
|
+
class DownloaderBuilder
|
|
13
|
+
REQUIRED_ARGS = %i[video_url video_hub_url playwright_cli_path].freeze
|
|
14
|
+
|
|
15
|
+
def initialize
|
|
16
|
+
@kwargs = {}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def with_kwargs(**kwargs)
|
|
20
|
+
@kwargs = kwargs
|
|
21
|
+
self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def with_video_name(video_name)
|
|
25
|
+
@kwargs[:video_name] = video_name
|
|
26
|
+
self
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def with_video_url(video_url)
|
|
30
|
+
@kwargs[:video_url] = video_url
|
|
31
|
+
self
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def with_video_hub_url(video_hub_url)
|
|
35
|
+
@kwargs[:video_hub_url] = video_hub_url
|
|
36
|
+
self
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def with_playwright_cli_path(playwright_cli_path)
|
|
40
|
+
@kwargs[:playwright_cli_path] = playwright_cli_path
|
|
41
|
+
self
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def build
|
|
45
|
+
REQUIRED_ARGS.each do |required_arg|
|
|
46
|
+
raise ArgumentError, "#{required_arg} must be provided" unless @kwargs[required_arg]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
@kwargs[:video_name] = @kwargs[:video_url].split('/').last unless @kwargs[:video_name]
|
|
50
|
+
|
|
51
|
+
Downloader.new(**@kwargs)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class Downloader
|
|
56
|
+
def initialize(**kwargs)
|
|
57
|
+
@max_lines = IO.console.winsize[0]
|
|
58
|
+
@kwargs = kwargs
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.builder
|
|
62
|
+
DownloaderBuilder.new
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.from_hash(hash)
|
|
66
|
+
builder.with_kwargs(**hash).build
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# main func to be called in your own scripts defined under web/
|
|
70
|
+
def download_video
|
|
71
|
+
Playwright.create(playwright_cli_executable_path: @kwargs[:playwright_cli_path]) do |playwright|
|
|
72
|
+
browser = playwright.chromium.launch
|
|
73
|
+
page = browser.new_page
|
|
74
|
+
|
|
75
|
+
manage_video_download(page)
|
|
76
|
+
wait_until_video_downloaded
|
|
77
|
+
|
|
78
|
+
browser.close
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def display_calling_args
|
|
83
|
+
puts 'Called with:'
|
|
84
|
+
@kwargs.each do |key, value|
|
|
85
|
+
puts "\t#{key}=#{value}"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def self.display_with_spinner(loading_msg = 'Loading...')
|
|
90
|
+
spinner = TTY::Spinner.new("[:spinner] #{loading_msg}")
|
|
91
|
+
spinner.auto_spin
|
|
92
|
+
yield
|
|
93
|
+
spinner.success('(done)')
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
|
|
98
|
+
def manage_video_download(page)
|
|
99
|
+
@lines = [''] * @max_lines
|
|
100
|
+
page.on('response', ->(resp) { listen_to_video_starts(page, resp) })
|
|
101
|
+
navigate_to_url(@kwargs[:video_url], page)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def wait_until_video_downloaded
|
|
105
|
+
Downloader.display_with_spinner('Downloading mp4 video...') do
|
|
106
|
+
VIDEO_DOWNLOADED_EVENT_QUEUE.pop
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def listen_to_video_starts(_page, response)
|
|
111
|
+
unless response.url.start_with?(@kwargs[:video_hub_url]) && response.headers['content-type']&.include?('video/mp4')
|
|
112
|
+
return
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
body = response.text
|
|
116
|
+
File.open("video-#{@kwargs[:video_name]}.mp4", 'wb') do |f|
|
|
117
|
+
f.write(body)
|
|
118
|
+
end
|
|
119
|
+
VIDEO_DOWNLOADED_EVENT_QUEUE << true
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def navigate_to_url(url, page)
|
|
123
|
+
Downloader.display_with_spinner("Page #{url} loading...") do
|
|
124
|
+
page.goto(url)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
data/lib/vidload/mp4.rb
ADDED
data/lib/vidload/version.rb
CHANGED
data/lib/vidload.rb
CHANGED
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.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Patacode <pata.codegineer@gmail.com>
|
|
@@ -105,6 +105,8 @@ files:
|
|
|
105
105
|
- lib/vidload/mp2t.rb
|
|
106
106
|
- lib/vidload/mp2t/api.rb
|
|
107
107
|
- lib/vidload/mp2t/remuxer.sh
|
|
108
|
+
- lib/vidload/mp4.rb
|
|
109
|
+
- lib/vidload/mp4/api.rb
|
|
108
110
|
- lib/vidload/version.rb
|
|
109
111
|
homepage:
|
|
110
112
|
licenses: []
|