Class: YoutubeDL::Runner

Inherits:
Object
  • Object
show all
Includes:
Support
Defined in:
lib/youtube-dl/runner.rb

Overview

Utility class for running and managing youtube-dl

Direct Known Subclasses

Video

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support

#cocaine_line, #quoted, #usable_executable_path_for, #which

Constructor Details

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

Command Line runner initializer

Parameters:

  • url (String)

    URL to pass to youtube-dl executable

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

    options to pass to the executable. Automatically converted to Options if it isn’t already



22
23
24
25
26
# File 'lib/youtube-dl/runner.rb', line 22

def initialize(url, options = {})
  @url = url
  @options = YoutubeDL::Options.new(options)
  @executable = 'youtube-dl'
end

Instance Attribute Details

#executableString

Returns Executable name to use.

Returns:

  • (String)

    Executable name to use



16
17
18
# File 'lib/youtube-dl/runner.rb', line 16

def executable
  @executable
end

#executable_pathString (readonly)

Returns usable executable path for youtube-dl

Returns:

  • (String)

    usable executable path for youtube-dl



13
14
15
# File 'lib/youtube-dl/runner.rb', line 13

def executable_path
  @executable_path
end

#optionsYoutubeDL::Options

Returns Options access.

Returns:



10
11
12
# File 'lib/youtube-dl/runner.rb', line 10

def options
  @options
end

#urlString

Returns URL to download.

Returns:

  • (String)

    URL to download



7
8
9
# File 'lib/youtube-dl/runner.rb', line 7

def url
  @url
end

Instance Method Details

#backend_runnerCommandLineRunner

Returns Cocaine’s runner engine

Returns:

  • (CommandLineRunner)

    backend runner class



38
39
40
# File 'lib/youtube-dl/runner.rb', line 38

def backend_runner
  Cocaine::CommandLine.runner
end

#backend_runner=(cocaine_runner) ⇒ Object

Sets Cocaine’s runner engine

Parameters:

  • cocaine_runner (CommandLineRunner)

    backend runner class

Returns:

  • (Object)

    whatever Cocaine::CommandLine.runner= returns.



46
47
48
# File 'lib/youtube-dl/runner.rb', line 46

def backend_runner=(cocaine_runner)
  Cocaine::CommandLine.runner = cocaine_runner
end

#configure(*a, &b) {|config| ... } ⇒ Object

Options configuration. Just aliases to options.configure

Parameters:

  • a (Array)

    arguments to pass to options#configure

  • b (Proc)

    block to pass to options#configure

Yields:

  • (config)

    options



72
73
74
# File 'lib/youtube-dl/runner.rb', line 72

def configure(*a, &b)
  options.configure(*a, &b)
end

#runString Also known as: download

Runs the command

Returns:

  • (String)

    the output of youtube-dl



61
62
63
# File 'lib/youtube-dl/runner.rb', line 61

def run
  cocaine_line(options_to_commands).run(@options.store)
end

#to_commandString Also known as: command

Returns the command string without running anything

Returns:

  • (String)

    command line string



53
54
55
# File 'lib/youtube-dl/runner.rb', line 53

def to_command
  cocaine_line(options_to_commands).command(@options.store)
end