Sha256: b1492de6367808b852df950a188de3362f6928df879de84055253210b48b6345

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'cocaine'

module YoutubeDL
  class Runner
    attr_accessor :url
    attr_accessor :options
    attr_accessor :executable_path

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

    def backend_runner
      Cocaine::CommandLine.runner
    end

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

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

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

    private
    def options_to_commands
      commands = []
      options.each_paramized_key do |key, paramized_key|
        if options[key].to_s == 'true'
          commands.push "--#{paramized_key}"
        else
          commands.push "--#{paramized_key} :#{key}"
        end
      end
      commands.push url
      commands.join(' ')
    end

    def cocaine_line(command)
      Cocaine::CommandLine.new(@executable_path, command)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
youtube-dl.rb-0.0.1 lib/youtube-dl/runner.rb