Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import dbus, gobject, dbus.glib
- # A function to change the status Message on Pidgin without changing the status itself.
- def set_message(message):
- # Get current status type (Available/Away/etc.)
- current = pidgin.PurpleSavedstatusGetType(pidgin.PurpleSavedstatusGetCurrent())
- # Create new transient status and activate it
- status = pidgin.PurpleSavedstatusNew("", current)
- pidgin.PurpleSavedstatusSetMessage(status, message)
- pidgin.PurpleSavedstatusActivate(status)
- # A callback for when the song changes.
- def status_changer_func(*args, **kwargs):
- mydict = rhythmshell.getSongProperties(rhythm.getPlayingUri())
- set_message("Now Playing: " + mydict['artist-folded'] + " - " + mydict['title'])
- # Don't need the system bus for this. Connect to the per-Session Bus
- bus = dbus.SessionBus()
- # Associate Pidgin's dbus interface with Python objects
- obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
- pidgin = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
- # Associate Rhythmbox's dbus player and shell interface(s) with Python objects
- # Shell is needed for getting info about the song being played - the Artist, etc.
- rhythm_obj = bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Player")
- rhythmshell_obj = bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell")
- rhythm = dbus.Interface(rhythm_obj, "org.gnome.Rhythmbox.Player")
- rhythmshell= dbus.Interface(rhythmshell_obj, "org.gnome.Rhythmbox.Shell")
- # Add handler for when the song changes.
- bus.add_signal_receiver(status_changer_func,dbus_interface="org.gnome.Rhythmbox.Player",signal_name="playingChanged")
- #begin the loop that checks for signals being generated and calls the registered callbacks.
- loop = gobject.MainLoop()
- loop.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement