module YoutubeDL::Support
Some support methods and glue logic.
Public Instance Methods
cocaine_line(command, executable_path = nil)
click to toggle source
Helper for doing lines of cocaine (initializing, auto executable stuff, etc)
@param command [String] command switches to run @param executable_path [String] executable to run. Defaults to usable youtube-dl. @return [Cocaine::CommandLine] initialized Cocaine instance
# File lib/youtube-dl/support.rb, line 27 def cocaine_line(command, executable_path = nil) executable_path = executable_path_for('youtube-dl') if executable_path.nil? Cocaine::CommandLine.new(executable_path, command) end
quoted(url)
click to toggle source
Helper to add quotes to beginning and end of a URL or whatever you want.…
@param url [String] Raw URL @return [String] Quoted URL
# File lib/youtube-dl/support.rb, line 36 def quoted(url) "\"#{url}\"" end
usable_executable_path_for(exe)
click to toggle source
Returns a usable youtube-dl executable (system or vendor)
@param exe [String] Executable to search for @return [String] executable path
# File lib/youtube-dl/support.rb, line 8 def usable_executable_path_for(exe) system_path = which(exe) if system_path.nil? # TODO: Search vendor bin for executable before just saying it's there. vendor_path = File.absolute_path("#{__FILE__}/../../../vendor/bin/#{exe}") File.chmod(775, vendor_path) unless File.executable?(vendor_path) # Make sure vendor binary is executable vendor_path else system_path.strip end end
Also aliased as: executable_path_for
which(cmd)
click to toggle source
Cross-platform way of finding an executable in the $PATH. Stolen from stackoverflow.com/a/5471032
which('ruby') #=> /usr/bin/ruby
@param cmd [String] cmd to search for @return [String] full path for the cmd
# File lib/youtube-dl/support.rb, line 47 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end nil end