class YoutubeDL::Video

Video model for using and downloading a single video.

Attributes

download_options[R]

@return [YoutubeDL::Options] Download Options for the last download

Public Class Methods

download(url, options = {}) click to toggle source

Instantiate a new Video model and download the video

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

@param url [String] URL to use and download @param options [Hash] Options to pass in @return [YoutubeDL::Video] new Video model

# File lib/youtube-dl/video.rb, line 13
def download(url, options = {})
  video = new(url, options)
  video.download
  video
end
Also aliased as: get
get(url, options = {})
Alias for: download
new(url, options = {}) click to toggle source

Instantiate new model

@param url [String] URL to initialize with @param options [Hash] Options to populate the everything with

# File lib/youtube-dl/video.rb, line 28
def initialize(url, options = {})
  @url = url
  @options = YoutubeDL::Options.new(options.merge(default_options))
  @options.banned_keys = banned_keys
end

Public Instance Methods

download() click to toggle source

Download the video.

# File lib/youtube-dl/video.rb, line 35
def download
  raise ArgumentError.new('url cannot be nil') if @url.nil?
  raise ArgumentError.new('url cannot be empty') if @url.empty?

  set_information_from_json(YoutubeDL::Runner.new(url, runner_options).run)
end
Also aliased as: get
filename() click to toggle source

Returns the expected filename

@return [String] Filename downloaded to

# File lib/youtube-dl/video.rb, line 47
def filename
  self._filename
end
get()
Alias for: download
information() click to toggle source

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

@return [OpenStruct] information

# File lib/youtube-dl/video.rb, line 54
def information
  @information || grab_information_without_download
end
method_missing(method, *args, &block) click to toggle source

Redirect methods for information getting

@param method [Symbol] method name @param args [Array] method arguments @param block [Proc] explict block @return [Object] The value from @information

Calls superclass method
# File lib/youtube-dl/video.rb, line 64
def method_missing(method, *args, &block)
  value = information[method]

  if value.nil?
    super
  else
    value
  end
end

Private Instance Methods

banned_keys() click to toggle source
# File lib/youtube-dl/video.rb, line 85
def banned_keys
  [
    :get_url,
    :get_title,
    :get_id,
    :get_thumbnail,
    :get_description,
    :get_duration,
    :get_filename,
    :get_format
  ]
end
default_options() click to toggle source

Add in other default options here.

# File lib/youtube-dl/video.rb, line 77
def default_options
  {
    color: false,
    progress: false,
    print_json: true
  }
end
runner_options() click to toggle source
# File lib/youtube-dl/video.rb, line 98
def runner_options
  YoutubeDL::Options.new(@options.to_h.merge(default_options))
end