Class: Vidload::Mp2t::Api::Downloader
- Inherits:
-
Object
- Object
- Vidload::Mp2t::Api::Downloader
- Defined in:
- lib/vidload/mp2t/api.rb
Instance Attribute Summary collapse
-
#hls_url ⇒ Object
readonly
Returns the value of attribute hls_url.
-
#master_playlist_name ⇒ Object
readonly
Returns the value of attribute master_playlist_name.
-
#playwright_cli_path ⇒ Object
readonly
Returns the value of attribute playwright_cli_path.
-
#video_name ⇒ Object
readonly
Returns the value of attribute video_name.
-
#video_referer ⇒ Object
readonly
Returns the value of attribute video_referer.
-
#video_url ⇒ Object
readonly
Returns the value of attribute video_url.
Class Method Summary collapse
- .display_with_spinner(loading_msg = "Loading...") ⇒ Object
- .from_argv ⇒ Object
- .from_hash(hash) ⇒ Object
Instance Method Summary collapse
- #display_calling_args ⇒ Object
-
#download_video(video_starter_callbacks: []) ⇒ Object
main func to be called in your own scripts defined under web/.
-
#initialize(video_url:, video_name:, author_name:, hls_url:, master_playlist_name:, playwright_cli_path:, video_referer:, ts_seg_pattern:, hls_index_pattern:, output_dir:) ⇒ Downloader
constructor
A new instance of Downloader.
Constructor Details
#initialize(video_url:, video_name:, author_name:, hls_url:, master_playlist_name:, playwright_cli_path:, video_referer:, ts_seg_pattern:, hls_index_pattern:, output_dir:) ⇒ Downloader
Returns a new instance of Downloader.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vidload/mp2t/api.rb', line 19 def initialize( video_url:, video_name:, author_name:, hls_url:, master_playlist_name:, playwright_cli_path:, video_referer:, ts_seg_pattern:, hls_index_pattern:, output_dir: ) raise ArgumentError, "video_url must be provided" unless video_url raise ArgumentError, "hls_url must be provided" unless hls_url raise ArgumentError, "master_playlist_name must be provided" unless master_playlist_name raise ArgumentError, "playwright_cli_path must be provided" unless playwright_cli_path raise ArgumentError, "video_referer must be provided" unless video_referer raise ArgumentError, "ts_seg_pattern must be provided" unless ts_seg_pattern raise ArgumentError, "hls_index_pattern must be provided" unless hls_index_pattern @video_url = video_url @hls_url = hls_url @master_playlist_name = master_playlist_name @playwright_cli_path = playwright_cli_path @video_referer = video_referer @ts_seg_pattern = ts_seg_pattern @hls_index_pattern = hls_index_pattern @max_lines = IO.console.winsize[0] @author_name = @video_name = if @author_name then "#{@author_name}_#{video_name}" else nil end @output_dir = output_dir || "./" end |
Instance Attribute Details
#hls_url ⇒ Object (readonly)
Returns the value of attribute hls_url.
17 18 19 |
# File 'lib/vidload/mp2t/api.rb', line 17 def hls_url @hls_url end |
#master_playlist_name ⇒ Object (readonly)
Returns the value of attribute master_playlist_name.
17 18 19 |
# File 'lib/vidload/mp2t/api.rb', line 17 def master_playlist_name @master_playlist_name end |
#playwright_cli_path ⇒ Object (readonly)
Returns the value of attribute playwright_cli_path.
17 18 19 |
# File 'lib/vidload/mp2t/api.rb', line 17 def playwright_cli_path @playwright_cli_path end |
#video_name ⇒ Object (readonly)
Returns the value of attribute video_name.
17 18 19 |
# File 'lib/vidload/mp2t/api.rb', line 17 def video_name @video_name end |
#video_referer ⇒ Object (readonly)
Returns the value of attribute video_referer.
17 18 19 |
# File 'lib/vidload/mp2t/api.rb', line 17 def video_referer @video_referer end |
#video_url ⇒ Object (readonly)
Returns the value of attribute video_url.
17 18 19 |
# File 'lib/vidload/mp2t/api.rb', line 17 def video_url @video_url end |
Class Method Details
.display_with_spinner(loading_msg = "Loading...") ⇒ Object
108 109 110 111 112 113 |
# File 'lib/vidload/mp2t/api.rb', line 108 def self.display_with_spinner(loading_msg = "Loading...") spinner = TTY::Spinner.new("[:spinner] #{loading_msg}") spinner.auto_spin yield spinner.success("(done)") end |
.from_argv ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vidload/mp2t/api.rb', line 52 def self.from_argv new( video_url: ARGV[0], video_name: ARGV[1], hls_url: ARGV[2], master_playlist_name: ARGV[3], playwright_cli_path: ARGV[4], video_referer: ARGV[5], ts_seg_pattern: ARGV[6], hls_index_pattern: ARGV[7], author_name: ARGV[8], ) end |
.from_hash(hash) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vidload/mp2t/api.rb', line 66 def self.from_hash(hash) new( video_url: hash[:video_url], author_name: hash[:author_name], video_name: hash[:video_name], hls_url: hash[:hls_url], master_playlist_name: hash[:master_playlist_name], playwright_cli_path: hash[:playwright_cli_path], video_referer: hash[:video_referer], ts_seg_pattern: hash[:ts_seg_pattern], hls_index_pattern: hash[:hls_index_pattern], ) end |
Instance Method Details
#display_calling_args ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/vidload/mp2t/api.rb', line 93 def display_calling_args puts "Constants:" puts "\tDEMUXER_PATH=#{DEMUXER_PATH}" puts "Called with:" puts "\tvideo_url=#{@video_url}" puts "\tvideo_name=#{@video_name}" puts "\thls_url=#{@hls_url}" puts "\tmaster_playlist_name=#{@master_playlist_name}" puts "\tplaywright_cli_path=#{@playwright_cli_path}" puts "\tvideo_referer=#{@video_referer}" puts "\tts_seg_pattern=#{@ts_seg_pattern}" puts "\thls_index_pattern=#{@hls_index_pattern}" puts "\tauthor_name=#{@author_name}" end |
#download_video(video_starter_callbacks: []) ⇒ Object
main func to be called in your own scripts defined under web/
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/vidload/mp2t/api.rb', line 81 def download_video(video_starter_callbacks: []) Playwright.create(playwright_cli_executable_path: @playwright_cli_path) do |playwright| browser = playwright.chromium.launch page = browser.new_page manage_video_download(page, *video_starter_callbacks) wait_until_video_downloaded browser.close end end |