__module_name__ = "Multiplayer Music Script" __module_version__ = "0.1" __module_description__ = "Display current playing song" import xchat import commands import os import dbus bus = dbus.SessionBus() def music_cb(word, word_eol, userdata): uid = os.geteuid() if len(commands.getoutput('pgrep -U %d rhythmbox' % uid)): rhythmbox_cb(word, word_eol, userdata) return xchat.EAT_ALL elif len(commands.getoutput('pgrep -U %d banshee' % uid)): banshee_cb(word, word_eol, userdata) return xchat.EAT_ALL elif len(commands.getoutput('pgrep -U %d amarok' % uid)): amarok_cb(word, word_eol, userdata) return xchat.EAT_ALL else: xchat.command('say Now Playing: Silence') return xchat.EAT_ALL def rhythmbox_cb(word, word_eol, userdata): try: rbplayerobj = bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player') rbshellobj = bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Shell') rbplayer = dbus.Interface(rbplayerobj, 'org.gnome.Rhythmbox.Player') rbshell = dbus.Interface(rbshellobj, 'org.gnome.Rhythmbox.Shell') playing = int(rbplayer.getPlaying()) except: playing = 0 if len(word) > 1 and word[1] == 'next' and playing: rbplayer.next() return xchat.EAT_ALL if playing: data = rbshell.getSongProperties(rbplayer.getPlayingUri()) title = data['title'].encode('utf-8') artist = data['artist'].encode('utf-8') album = data['album'].encode('utf-8') rating = int(data['rating']) if rating == 0: rating = 3 rating_str = '\xe2\x9c\xae' * rating + '\xe2\x9c\xa9' * (5-rating) output = 'is listening to \x0304%s\x03' % (title) if len(artist): output += ' by \x0303%s\x03' % (artist) if len(album): output += ' from \x0313%s\x03' % (album) output += ' (%s)' % (rating_str) else: output = 'is listening to Silence' xchat.command('me %s' % (output)) return xchat.EAT_ALL def banshee_cb(word, word_eol, userdata): try: bansheeobj = bus.get_object('org.gnome.Banshee', '/org/gnome/Banshee/Player') banshee = dbus.Interface(bansheeobj, 'org.gnome.Banshee.Core') playing = banshee.GetPlayingStatus() except: playing = 0 if len(word) > 1 and word[1] == 'next' and playing > 0: banshee.Next() return xchat.EAT_ALL if playing > 0: title = banshee.GetPlayingTitle().encode('utf-8') artist = banshee.GetPlayingArtist().encode('utf-8') album = banshee.GetPlayingAlbum().encode('utf-8') rating = int(banshee.GetPlayingRating()) if rating == 0: rating = 3 rating_str = '\xe2\x9c\xae' * rating + '\xe2\x9c\xa9' * (5-rating) output = 'is listening to \x0304%s\x03' % (title) if len(artist): output += ' by \x0303%s\x03' % (artist) if len(album): output += ' from \x0313%s\x03' % (album) output += ' (%s)' % (rating_str) else: output = 'is listening to Silence' xchat.command('me %s' % (output)) return xchat.EAT_ALL def amarok_cb(word, word_eol, userdata): try: if commands.getstatusoutput('dcop amarok player')[0] == 0 and len(commands.getstatusoutput('dcop amarok player title')[1]): playing = 1 else: playing = 0 except: playing = 0 if len(word) > 1 and word[1] == 'next' and playing > 0: commands.getstatusoutput('dcop amarok player next') return xchat.EAT_ALL if playing > 0: title = commands.getstatusoutput('dcop amarok player title')[1] artist = commands.getstatusoutput('dcop amarok player artist')[1] album = commands.getstatusoutput('dcop amarok player album')[1] rating = int(commands.getstatusoutput('dcop amarok player rating')[1]) if rating == 0: rating = 3 rating_str = '\xe2\x9c\xae' * rating + '\xe2\x9c\xa9' * (5-rating) output = 'is listening to \x0304%s\x03' % (title) if len(artist): output += ' by \x0303%s\x03' % (artist) if len(album): output += ' from \x0313%s\x03' % (album) output += ' (%s)' % (rating_str) else: output = 'is listening to Silence' xchat.command('me %s' % (output)) return xchat.EAT_ALL xchat.hook_command('rbox', rhythmbox_cb, help='/rbox Sends playing song info to channel') xchat.hook_command('banshee', banshee_cb, help='/banshee Sends playing song info to channel') xchat.hook_command('amarok', amarok_cb, help='/amarok Sends playing song info to channel') xchat.hook_command('music', music_cb, help='/music Sends playing song info to channel')