Module: YtDlp::Support
Overview
Some support methods and glue logic.
Instance Method Summary collapse
-
#quoted(url) ⇒ String
Helper to add quotes to beginning and end of a URL or whatever you want.…
-
#terrapin_line(command, executable_path = nil) ⇒ Terrapin::CommandLine
Helper for doing lines of terrapin (initializing, auto executable stuff, etc).
-
#usable_executable_path_for(exe) ⇒ String
(also: #executable_path_for)
Returns a usable yt-dlp executable (system or vendor).
-
#which(cmd) ⇒ String
Cross-platform way of finding an executable in the $PATH.
Instance Method Details
#quoted(url) ⇒ String
Helper to add quotes to beginning and end of a URL or whatever you want.…
38 39 40 |
# File 'lib/yt-dlp/support.rb', line 38 def quoted(url) "\"#{url}\"" end |
#terrapin_line(command, executable_path = nil) ⇒ Terrapin::CommandLine
Helper for doing lines of terrapin (initializing, auto executable stuff, etc)
29 30 31 32 |
# File 'lib/yt-dlp/support.rb', line 29 def terrapin_line(command, executable_path = nil) executable_path = executable_path_for('yt-dlp') if executable_path.nil? Terrapin::CommandLine.new(executable_path, command) end |
#usable_executable_path_for(exe) ⇒ String Also known as: executable_path_for
Returns a usable yt-dlp executable (system or vendor)
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/yt-dlp/support.rb', line 10 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 |
#which(cmd) ⇒ String
Cross-platform way of finding an executable in the $PATH. Stolen from stackoverflow.com/a/5471032
which('ruby') #=> /usr/bin/ruby
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/yt-dlp/support.rb', line 49 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 |