Skip to content

Instantly share code, notes, and snippets.

@devi
Created July 8, 2012 06:20
Show Gist options
  • Select an option

  • Save devi/3069632 to your computer and use it in GitHub Desktop.

Select an option

Save devi/3069632 to your computer and use it in GitHub Desktop.
banshee pidgin status
#!/usr/bin/env python
"""
np.py - NowPlaying (https://github.com/Devkill/NowPlaying/)
Copyright 2011, devkill, www.devkill.net
Licensed under the sukatoro n ycl Forum License 3.
http://sukatoro.com/
http://yogyacarderlink.web.id
#yogyacarderlink #1stlink #magelangcyber
"""
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
class BansheeStatusPlugin:
def __init__(self):
bus = dbus.SessionBus()
bus.add_signal_receiver(self.bansheeEventChanged,
dbus_interface="org.bansheeproject.Banshee.PlayerEngine",
signal_name="EventChanged")
self.pidgin = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
self.pidgin = dbus.Interface(self.pidgin, "im.pidgin.purple.PurpleInterface")
self.banshee = bus.get_object("org.bansheeproject.Banshee", "/org/bansheeproject/Banshee/PlayerEngine")
#post to pidgin
def __resetPidginStatusMessage(self, msg):
# Loop through all active accounts
for account in self.pidgin.PurpleAccountsGetAllActive():
# Set new status message for the currently playing song
status = self.pidgin.PurpleSavedstatusGetCurrent()
self.pidgin.PurpleSavedstatusSetMessage(status, msg.encode('utf-8'))
self.pidgin.PurpleSavedstatusActivate(status)
def bansheeEventChanged(self, event, message, bufferingPercent):
# Get currently playing song from banshee
currentTrack = self.banshee.GetCurrentTrack()
# New song was loaded, update status pidgin with current track information
if event == "startofstream" or event == "statechange":
if self.banshee.GetCurrentState() != "paused":
msg = self.__resetPidginStatusMessage(currentTrack['artist'] + " - " + currentTrack['name'])
if __name__ == "__main__":
# Setup dbus glib mainloop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
# Create new instance of our plugin class
BansheeStatusPlugin()
# Get main loop and run it
gobject.MainLoop().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment