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.
107 108 109 110 |
# File 'lib/vidload/mp2t/api.rb', line 107 def initialize(**kwargs) @max_lines = IO.console.winsize[0] @kwargs = kwargs end |
Class Method Details
.builder ⇒ Object
112 113 114 |
# File 'lib/vidload/mp2t/api.rb', line 112 def self.builder DownloaderBuilder.new end |
.display_with_spinner(loading_msg = 'Loading...') ⇒ Object
148 149 150 151 152 153 |
# File 'lib/vidload/mp2t/api.rb', line 148 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
116 117 118 |
# File 'lib/vidload/mp2t/api.rb', line 116 def self.from_hash(hash) builder.with_kwargs(**hash).build end |
Instance Method Details
#display_calling_args ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/vidload/mp2t/api.rb', line 139 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/
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/vidload/mp2t/api.rb', line 121 def download_video(video_starter_callbacks: []) Playwright.create(playwright_cli_executable_path: @kwargs[:playwright_cli_path]) do |playwright| browser = playwright.chromium.launch(headless: @kwargs[:headless]) 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 |