You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

#!/usr/bin/ruby
#command to run as player
player = "smplayer"
basepath = "~/TEMP/"
# Directories where to look for scripts
# Order does matter - you can override generic script by your own
directories = [
"~/.yt-smplayer.d/",
"#{basepath}yt-smplayer/private.d/",
"#{basepath}yt-smplayer/scripts.d/"
]
if ARGV[0].nil? or ARGV[0].empty? then
$stderr.puts "No link as parameter."
exit
else
link = "#{ARGV[0]}"
end
# for file in Dir.glob("/home/chytrex/TEMP/yt-smplayer/private.d/*.rb").sort!
# List of expected return codes
#
# 0 - Link processed - player started
# 1 - Link doesn't match
# 127 - Link not present - fatal failure - stop whole further processing
directories.each {
|dir|
# Make sure to expand paths like ~
dir = File.expand_path(dir)
if Dir.exist?(dir) then
for file in Dir.glob("#{dir}/*.rb").sort!
# puts "Running - ruby \"#{file}\" \"#{link}\" \"#{player}\""
system("ruby \"#{file}\" \"#{link}\" \"#{player}\"")
rc = $?.exitstatus.to_i
if rc == 0
exit 0
elsif rc == 127
$stderr.puts "Fatal error trigerred by #{file}. Terminating..."
exit 1
end
end
end
}
exec "x-www-browser \"#{link}\""