rendered paste body__module_name__ = "Multiplayer Music Script"
__module_version__ = "0.1"
__module_description__ = "Display current playing song"
import xchat
import commands
import dbus
bus = dbus.SessionBus()
#rhythmbox dbus interfaces
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')
#banshee dbus interface
bansheeobj = bus.get_object('org.gnome.Banshee', '/org/gnome/Banshee/Player')
banshee = dbus.Interface(bansheeobj, 'org.gnome.Banshee.Core')
def rhythmbox_cb(word, word_eol, userdata):
try:
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')
duration = data['duration']
minute = 0
while duration > 60:
minute += 1
duration -= 60
duration_show = '%d:' % minute
if duration < 10:
duration_show += '0' + str(duration)
else:
duration_show += str(duration)
elapsed = rbplayer.getElapsed()
orig = elapsed
minute = 0
while elapsed > 60:
minute += 1
elapsed -= 60
elapsed_show = '%d:' % minute
if elapsed < 10:
elapsed_show += '0' + str(elapsed)
else:
elapsed_show += str(elapsed)
output = 'Now Playing: \x0304%s\x03 by \x0303%s\x03 from \x0302%s\x03 (\x0307%s/%s\x03)' % (title, artist, album, elapsed_show, duration_show)
else:
output = 'Now Playing: Silence'
xchat.command('say %s' % (output))
return xchat.EAT_ALL
def banshee_cb(word, word_eol, userdata):
try:
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')
duration = banshee.GetPlayingDuration()
minute = 0
while duration > 60:
minute += 1
duration -= 60
duration_show = '%d:' % minute
if duration < 10:
duration_show += '0' + str(duration)
else:
duration_show += str(duration)
elapsed = banshee.GetPlayingPosition()
minute = 0
while elapsed > 60:
minute += 1
elapsed -= 60
elapsed_show = '%d:' % minute
if elapsed < 10:
elapsed_show += '0' + str(elapsed)
else:
elapsed_show += str(elapsed)
output = 'Now Playing: \x0304%s\x03 by \x0303%s\x03 from \x0302%s\x03 (\x0307%s/%s\x03)' % (title, artist, album, elapsed_show, duration_show)
else:
output = 'Now Playing: Silence'
xchat.command('say %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]
duration_show = commands.getstatusoutput('dcop amarok player totalTime')[1]
elapsed_show = commands.getstatusoutput('dcop amarok player currentTime')[1]
output = 'Now Playing: \x0304%s\x03 by \x0303%s\x03 from \x0302%s\x03 (\x0307%s/%s\x03)' % (title, artist, album, elapsed_show, duration_show)
else:
output = 'Now Playing: Silence'
xchat.command('say %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')