class Sportsflix::Players::VLC::Client
Constants
- ALTERNATIVE_PLAYER_PATHS
Public Class Methods
new(options)
click to toggle source
# File lib/sportsflix/players/vlc.rb, line 17 def initialize(options) @verbose = options[:verbose] @server_only = options['server-only'] @video_player_path = options['video-player-path'] @proxy_delay = options['proxy-delay'] @executor = Sportsflix::Utils::Executor.new(options) @stream_proxies = { :default => Sportsflix::Players::Proxies::Default::Client.new(options), :acestream => Sportsflix::Players::Proxies::Acestream::Client.new(options) } end
Public Instance Methods
start(stream)
click to toggle source
# File lib/sportsflix/players/vlc.rb, line 30 def start(stream) proxy = @stream_proxies[stream[:proxy]] proxy.stop proxy.start # Waiting for proxy to start puts "Waiting for proxy to start (#{@proxy_delay})..." sleep(@proxy_delay) stream_final_url = proxy.url(stream[:uri]) puts "Playing #{stream_final_url}" unless @server_only video_player = find_video_player @executor.run %{#{video_player} #{stream_final_url}} proxy.stop end end
Private Instance Methods
find_video_player()
click to toggle source
# File lib/sportsflix/players/vlc.rb, line 52 def find_video_player unless which(@video_player_path) || File.exist?(@video_player_path) puts "Could not find video player #{@video_player_path}, searching for alternatives ..." ALTERNATIVE_PLAYER_PATHS.each do |path| if which(path) || File.exist?(path) puts "Found VLC player in #{path}" return path end end puts 'Could not find vlc in any of the alternative locations' exit(1) end @video_player_path end
which(cmd)
click to toggle source
Cross-platform way of finding an executable in the $PATH. Source: stackoverflow.com/posts/5471032/revisions
# File lib/sportsflix/players/vlc.rb, line 72 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each {|ext| bin = File.join(path, "#{cmd}#{ext}") return File.executable?(bin) && !File.directory?(bin) } end false end