Class: YoutubeDL::Video

Inherits:
Runner
  • Object
show all
Defined in:
lib/youtube-dl/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

#cocaine_line, #quoted, #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



28
29
30
31
32
# 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

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



64
65
66
67
68
69
70
71
72
# 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

Instance Attribute Details

#download_optionsYoutubeDL::Options (readonly)

Returns Download Options for the last download.

Returns:



22
23
24
# File 'lib/youtube-dl/video.rb', line 22

def download_options
  @download_options
end

Class Method Details

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

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

Parameters:

  • url (String)

    URL to use and download

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

    Options to pass in

Returns:



13
14
15
16
17
# File 'lib/youtube-dl/video.rb', line 13

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

.getYoutubeDL::Video

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

Parameters:

  • url (String)

    URL to use and download

  • options (Hash)

    Options to pass in

Returns:



18
19
20
21
22
# File 'lib/youtube-dl/video.rb', line 18

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

Instance Method Details

#downloadObject Also known as: get

Download the video.

Raises:

  • (ArgumentError)


35
36
37
38
39
40
# 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

#filenameString

Returns the expected filename

Returns:

  • (String)

    Filename downloaded to



47
48
49
# File 'lib/youtube-dl/video.rb', line 47

def filename
  self._filename
end

#informationOpenStruct

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

Returns:

  • (OpenStruct)

    information



54
55
56
# File 'lib/youtube-dl/video.rb', line 54

def information
  @information || grab_information_without_download
end