Class: YtDlp::Video

Inherits:
Runner show all
Defined in:
lib/yt-dlp/video.rb

Overview

Video model for using and downloading a single video.

Instance Attribute Summary collapse

Attributes inherited from Runner

#executable, #executable_path, #options, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Runner

#backend_runner, #backend_runner=, #configure, #run, #to_command

Methods included from Support

#quoted, #terrapin_line, #usable_executable_path_for, #which

Constructor Details

#initialize(url, options = {}) ⇒ Video

Instantiate new model

Parameters:

  • url (String)

    URL to initialize with

  • options (Hash) (defaults to: {})

    Options to populate the everything with



35
36
37
38
39
# File 'lib/yt-dlp/video.rb', line 35

def initialize(url, options = {})
  @url = url
  @options = YtDlp::Options.new(options.merge(default_options))
  @options.banned_keys = banned_keys
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Redirect methods for information getting

Parameters:

  • method (Symbol)

    method name

  • args (Array)

    method arguments

  • block (Proc)

    explict block

Returns:

  • (Object)

    The value from @information



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/yt-dlp/video.rb', line 71

def method_missing(method, *args, &block)
  value =
    if information.is_a?(Array)
      information.first[method]
    else
      information[method]
    end

  if value.nil?
    super
  else
    value
  end
end

Instance Attribute Details

#download_optionsYtDlp::Options (readonly)

Returns Download Options for the last download.

Returns:



29
30
31
# File 'lib/yt-dlp/video.rb', line 29

def download_options
  @download_options
end

Class Method Details

.download(url, options = {}) ⇒ YtDlp::Video

Instantiate a new Video model and download the video

YtDlp.download 'https://www.youtube.com/watch?v=KLRDLIIl8bA' # => #<YtDlp::Video:0x00000000000000>
YtDlp.get 'https://www.youtube.com/watch?v=ia1diPnNBgU', extract_audio: true, audio_quality: 0

Parameters:

  • url (String)

    URL to use and download

  • options (Hash) (defaults to: {})

    Options to pass in

Returns:



15
16
17
18
19
# File 'lib/yt-dlp/video.rb', line 15

def download(url, options = {})
  video = new(url, options)
  video.download
  video
end

.getYtDlp::Video

Instantiate a new Video model and download the video

YtDlp.download 'https://www.youtube.com/watch?v=KLRDLIIl8bA' # => #<YtDlp::Video:0x00000000000000>
YtDlp.get 'https://www.youtube.com/watch?v=ia1diPnNBgU', extract_audio: true, audio_quality: 0

Parameters:

  • url (String)

    URL to use and download

  • options (Hash)

    Options to pass in

Returns:



20
21
22
23
24
# File 'lib/yt-dlp/video.rb', line 20

def download(url, options = {})
  video = new(url, options)
  video.download
  video
end

.information(url, options = {}) ⇒ Object



22
23
24
25
# File 'lib/yt-dlp/video.rb', line 22

def information(url, options = {})
  video = new(url, options)
  video.information
end

Instance Method Details

#downloadObject Also known as: get

Download the video.

Raises:

  • (ArgumentError)


42
43
44
45
46
47
# File 'lib/yt-dlp/video.rb', line 42

def download
  raise ArgumentError, 'url cannot be nil' if @url.nil?
  raise ArgumentError, 'url cannot be empty' if @url.empty?

  set_information_from_json(YtDlp::Runner.new(url, runner_options).run)
end

#filenameString

Returns the expected filename

Returns:

  • (String)

    Filename downloaded to



54
55
56
# File 'lib/yt-dlp/video.rb', line 54

def filename
  _filename
end

#informationOpenStruct

Metadata information for the video, gotten from –print-json

Returns:

  • (OpenStruct)

    information



61
62
63
# File 'lib/yt-dlp/video.rb', line 61

def information
  @information || grab_information_without_download
end