Ekledigim seyler:
- Birden fazla kelime aranabiliyor, hepsinin parca ismine/dosya ismine uymasi lazim
- Sadece sayi girilirse xmms o siradaki parcaya atliyor
- Girdi ':' ile baslarsa xmms'e direkt ruby kodu ile hukmedebiliyoruz (:stop, :play :next gibi). eval fonksiyonu sagolsun.
- Eger ilk arguman --dialog ise girdi bir dialog yardimiyla aliniyor.
#!/usr/bin/env ruby require 'xmms' def nextSong(args, xr) matching = [] i = 0 xr.playlist.each do |entry| if match(entry, args) matching << i $stderr.puts 'Matched: ' + entry[0] end i += 1 end if matching.length == 0 return false else xr.position = matching[rand(matching.length)] return true end end def match(entry, args) title, file, time = entry args.each do |arg| regex = /#{arg}/i return false unless (title =~ regex or file =~ regex) end return true end def is_int(str) return str =~ /^[0-9]+$/ end $stderr.puts 'Xmms-Ruby version ' << Xmms::Remote::VERSION # allocate a new Xmms::Remote object xr = Xmms::Remote::new if ARGV.length == 1 and ARGV[0] == '--dialog' cmd = open('| zenity --entry --text "xmms: give some keywords"') argStr = cmd.gets.strip args = argStr.split cmd.close puts args.to_s exit if args.length == 0 else argStr = ARGV.map{|s| s.strip}.join(' ') args = argStr.split end if args.length == 0 xr.next $stderr.puts 'next song' elsif is_int(argStr) and argStr.to_i <= xr.playlist.length and argStr.to_i > 0 xr.position = argStr.to_i - 1 $stderr.puts 'jump to position: ' + argStr elsif argStr[0] == ":"[0] $stderr.puts 'Evaluate: ' + argStr[1..-1] eval ('xr.' + argStr[1..-1]) elsif not nextSong(args, xr) $stderr.puts 'No match: ' + argStr end
No comments:
Post a Comment