class YoutubeDL::Runner

Utility class for running and managing youtube-dl

Attributes

executable[RW]

@return [String] Executable name to use

executable_path[R]

@return [String] Executable path

options[RW]

@return [YoutubeDL::Options] Options access.

url[RW]

@return [String] URL to download

Public Class Methods

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

Command Line runner initializer

@param url [String] URL to pass to youtube-dl executable @param options [Hash, Options] options to pass to the executable. Automatically converted to Options if it isn't already

# File lib/youtube-dl/runner.rb, line 22
def initialize(url, options = {})
  @url = url
  @options = YoutubeDL::Options.new(options)
  @executable = 'youtube-dl'
end

Public Instance Methods

backend_runner() click to toggle source

Returns Cocaine's runner engine

@return [CommandLineRunner] backend runner class

# File lib/youtube-dl/runner.rb, line 38
def backend_runner
  Cocaine::CommandLine.runner
end
backend_runner=(cocaine_runner) click to toggle source

Sets Cocaine's runner engine

@param cocaine_runner [CommandLineRunner] backend runner class @return [Object] whatever Cocaine::CommandLine.runner= returns.

# File lib/youtube-dl/runner.rb, line 46
def backend_runner=(cocaine_runner)
  Cocaine::CommandLine.runner = cocaine_runner
end
command()
Alias for: to_command
configure(*a, &b) click to toggle source

Options configuration. Just aliases to options.configure

@yield [config] options @param a [Array] arguments to pass to options#configure @param b [Proc] block to pass to options#configure

# File lib/youtube-dl/runner.rb, line 72
def configure(*a, &b)
  options.configure(*a, &b)
end
download()
Alias for: run
run() click to toggle source

Runs the command

@return [String] the output of youtube-dl

# File lib/youtube-dl/runner.rb, line 61
def run
  cocaine_line(options_to_commands).run(@options.store)
end
Also aliased as: download
to_command() click to toggle source

Returns the command string without running anything

@return [String] command line string

# File lib/youtube-dl/runner.rb, line 53
def to_command
  cocaine_line(options_to_commands).command(@options.store)
end
Also aliased as: command

Private Instance Methods

options_to_commands() click to toggle source

Parses options and converts them to Cocaine's syntax

@return [String] commands ready to do cocaine

# File lib/youtube-dl/runner.rb, line 81
def options_to_commands
  commands = []
  @options.sanitize_keys.each_paramized_key do |key, paramized_key|
    if @options[key].to_s == 'true'
      commands.push "--#{paramized_key}"
    elsif @options[key].to_s == 'false'
      commands.push "--no-#{paramized_key}"
    else
      commands.push "--#{paramized_key} :#{key}"
    end
  end
  commands.push quoted(url)
  commands.join(' ')
end