class AirPlayer::YoutubeDl
Constants
- EXTRACT_EXTRACTOR_AND_URL
- GENERIC_EXTRACTOR
Attributes
path[RW]
path[R]
Public Class Methods
default_path()
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 65 def default_path @default_path ||= `which youtube-dl 2> /dev/null`.strip end
enabled?()
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 61 def enabled? path && ! path.empty? end
filename(url)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 83 def filename(url) if enabled? new.get_filename(url) else File.basename(url) end end
get_title(uri)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 91 def get_title(uri) if enabled? new.get_title(uri) else File.basename(uri) end end
get_url(uri)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 69 def get_url(uri) if enabled? new.get_url(uri) else uri end end
new(path = self.class.path || self.class.default_path)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 8 def initialize(path = self.class.path || self.class.default_path) @path = path if @path File.exist?(@path) or raise "youtube-dl could not be found at #{@path}" end @output = '2> /dev/null'.freeze end
supports?(path)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 77 def supports?(path) if enabled? new.supports?(path) end end
Public Instance Methods
enabled?()
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 18 def enabled? @path && ! @path.empty? end
execute(*args)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 51 def execute(*args) return '' unless enabled? escape = Shellwords.method(:escape) parts = [ path, args.flat_map(&escape), @output ] %x`#{parts.flatten.join(' ')}`.strip end
get_filename(url)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 43 def get_filename(url) execute('--get-filename', url) end
get_title(url)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 47 def get_title(url) execute('--get-title', url) end
get_url(url)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 39 def get_url(url) execute('--get-url', url) end
list_extractors(*urls)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 35 def list_extractors(*urls) execute('--list-extractors', *urls) end
supports?(url)
click to toggle source
# File lib/airplayer/youtube_dl.rb, line 29 def supports?(url) extractors = list_extractors(url).scan(EXTRACT_EXTRACTOR_AND_URL).flatten extractors.delete(GENERIC_EXTRACTOR) ! extractors.empty? end