#!/usr/bin/python import xchat import dbus __module_name__ = "MP3 Announcer" __module_version__ = "1.2.4" __module_description__ = "Announce music from and control Banshee Music Player." if_name = 'org.bansheeproject.Banshee' if_path = '/org/bansheeproject/Banshee/PlayerEngine' bus = dbus.SessionBus() # Debug mode; 1 = on, 0 = off debug = 0 class Dbus: def __init__(self): obj = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') iface = dbus.Interface(obj, 'org.freedesktop.DBus') if if_name in iface.ListNames(): global banshee_obj banshee_obj = bus.get_object(if_name, if_path) else: xchat.prnt("\002Banshee is not registered with DBus. Please start Banshee.\002") return def grab_track_data(self): global track_title global track_artist global track_album global track_genre global track_length global track_bitrate info = banshee_obj.GetCurrentTrack() if debug is 1: keys = info.keys() keys.sort() for key in keys: value = info[key] print "key [%s] value [%s]" % (key, value) #track_title = info['name'] try: track_title = info['name'] except(KeyError): track_title = "[undefined title]" #track_artist = info['artist'] try: track_artist = info['artist'] except(KeyError): track_artist = "[undefined artist]" #track_album = info['album'] try: track_album = info['album'] except(KeyError): track_album = "[undefined album]" #track_genre = info['genre'] try: track_genre = info['genre'] except(KeyError): track_genre = "Other" track_length = info['length'] time = track_length min = time / 60 secs = time % 60 min = int(min) secs = int(secs) if secs <= 9: secs = "0%s" % secs track_length = "%s\002:\002%s" % (min, secs) track_bitrate = info['bit-rate'] class Commands: def mabout(self, word, word_eol, nil): xchat.prnt("\002\037%s\037\002" % __module_name__) xchat.prnt(" \002Help:\002") xchat.prnt(" * \037/media\037 - Displays the currently playing track") return xchat.EAT_ALL def media(self, word, word_eol, nil): Dbus().grab_track_data() # With album info # # xchat.command("me media: \037%s\037 by \002%s\002 on %s (%s) .. -%skbps- [%s]" % (track_title, track_artist, track_album, track_length, track_bitrate, track_genre)) # return xchat.EAT_ALL # Without album info # xchat.command("me media: \037%s\037 by \002%s\002 \002\0372(\037\002%s\002\0372)\037\002 0:2:1:2:0: -%s\0022kbps\002- \002\0372[\037\002%s\002\0372]\037\002." % (track_title, track_artist, track_length, track_bitrate, track_genre)) return xchat.EAT_ALL xchat.prnt("Loaded \002%s\002:" % __module_name__) xchat.prnt("Use \002/mabout\002 to display a list of commands.") mabout_hook = xchat.hook_command("mabout", Commands().mabout) media_hook = xchat.hook_command("media", Commands().media) def munload(nil): xchat.unhook(mabout_hook) xchat.unhook(media_hook) xchat.prnt("* \002%s\002 successfully unloaded." % __module_name__) xchat.hook_unload(munload)