Class: Vidload::Custom::Api::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/vidload/custom/api.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Downloader

Returns a new instance of Downloader.



63
64
65
# File 'lib/vidload/custom/api.rb', line 63

def initialize(**kwargs)
  @kwargs = kwargs
end

Class Method Details

.builderObject



67
68
69
# File 'lib/vidload/custom/api.rb', line 67

def self.builder
  DownloaderBuilder.new
end

.display_with_spinner(loading_msg = 'Loading...') ⇒ Object



94
95
96
97
98
99
# File 'lib/vidload/custom/api.rb', line 94

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



71
72
73
# File 'lib/vidload/custom/api.rb', line 71

def self.from_hash(hash)
  builder.with_kwargs(**hash).build
end

Instance Method Details

#display_calling_argsObject



87
88
89
90
91
92
# File 'lib/vidload/custom/api.rb', line 87

def display_calling_args
  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/



76
77
78
79
80
81
82
83
84
85
# File 'lib/vidload/custom/api.rb', line 76

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)

    browser.close
  end
end