class YoutubeDL::Runner
Utility class for running and managing youtube-dl
Attributes
@return [String] Executable name to use
@return [String] Executable path
@return [YoutubeDL::Options] Options
access.
@return [String] URL to download
Public Class Methods
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
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
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
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
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
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
Private Instance Methods
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