Class: Vidload::Mp2t::Api::Downloader
- Inherits:
-
Object
- Object
- Vidload::Mp2t::Api::Downloader
- Defined in:
- lib/vidload/mp2t/api.rb
Class Method Summary collapse
- .builder ⇒ Object
- .display_with_spinner(loading_msg = 'Loading...') ⇒ 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(**kwargs) ⇒ Downloader
constructor
A new instance of Downloader.
Constructor Details
#initialize(**kwargs) ⇒ Downloader
Returns a new instance of Downloader.
97 98 99 100 |
# File 'lib/vidload/mp2t/api.rb', line 97 def initialize(**kwargs) @max_lines = IO.console.winsize[0] @kwargs = kwargs end |
Class Method Details
.builder ⇒ Object
102 103 104 |
# File 'lib/vidload/mp2t/api.rb', line 102 def self.builder DownloaderBuilder.new end |
.display_with_spinner(loading_msg = 'Loading...') ⇒ Object
138 139 140 141 142 143 |
# File 'lib/vidload/mp2t/api.rb', line 138 def self.display_with_spinner(loading_msg = 'Loading...') spinner = TTY::Spinner.new("[:spinner] #{loading_msg}") spinner.auto_spin yield spinner.success('(done)') end |
.from_hash(hash) ⇒ Object
106 107 108 |
# File 'lib/vidload/mp2t/api.rb', line 106 def self.from_hash(hash) builder.with_kwargs(**hash).build end |
Instance Method Details
#display_calling_args ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/vidload/mp2t/api.rb', line 129 def display_calling_args puts 'Constants:' puts "\tDEMUXER_PATH=#{DEMUXER_PATH}" puts 'Called with:' @kwargs.each do |key, value| puts "\t#{key}=#{value}" end end |
#download_video(video_starter_callbacks: []) ⇒ Object
main func to be called in your own scripts defined under web/
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/vidload/mp2t/api.rb', line 111 def download_video(video_starter_callbacks: []) Playwright.create(playwright_cli_executable_path: @kwargs[:playwright_cli_path]) do |playwright| browser = playwright.chromium.launch(headless: false) page = browser.new_page manage_video_download(page, *video_starter_callbacks) if wait_until_video_start_downloading(timeout: 10).nil? puts 'Not possible to download video. Restarting new session' browser.close download_video(video_starter_callbacks: video_starter_callbacks) else wait_until_video_downloaded browser.close end end end |