#!/usr/bin/env ruby
# psituner: "Now listening to" XMMS2 script for Psi
# Copyright © 2010 David Palacio
# http://bakalacio.blogspot.com/
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details
require 'xmmsclient'
require 'xmmsclient_glib'
require 'glib2'
begin
xmms = Xmms::Client.new('psituner').connect(ENV['XMMS_PATH'])
rescue Xmms::Client::ClientError
puts 'Failed to connect to the XMMS2 daemon.'
exit 65536
end
TUNEPATH = ENV['HOME'] + '/.psi/tune';
xmms.add_to_glib_mainloop
ml = GLib::MainLoop.new(nil, false)
def nil_tune
File.truncate TUNEPATH, 0
end
nil_tune
def update dict
dict = dict.to_propdict
File.open TUNEPATH, 'w' do |tune|
tune.puts dict[:title]
tune.puts dict[:artist]
tune.puts dict[:album]
tune.puts dict[:tracknr]
tune.puts dict[:duration]/1000
end
end
xmms.broadcast_playback_current_id.notifier do |id|
if id == 0
STDERR.puts 'Currently playing nothing'
nil_tune
else
STDERR.puts "Currently playing #{id}"
xmms.medialib_get_info(id).notifier do |value|
update value
end
end
true
end
xmms.broadcast_playback_status.notifier do |status|
STDERR.puts "Current status: #{status}"
nil_tune if status == 0
true
end
xmms.broadcast_quit.notifier do
STDERR.puts 'Bye, bye XMMS2d'
nil_tune
exit 0
end
xmms.on_disconnect do
STDERR.puts 'Where did you go to, XMMS2d?'
nil_tune
exit 1
end
ml.run
Listening to: Firebird - Sound Online/Tsukasa
No hay comentarios.:
Publicar un comentario