Skip to content

Instantly share code, notes, and snippets.

@mollerse
Created August 15, 2013 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mollerse/6239948 to your computer and use it in GitHub Desktop.
Save mollerse/6239948 to your computer and use it in GitHub Desktop.
Pythonscript for track-change notifications in KDE
#!/usr/bin/env python
import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop
import time
class SpotifyNotifier(object):
def __init__(self):
bus_loop = DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus(mainloop=bus_loop)
loop = gobject.MainLoop()
self.spotify = bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
self.spotify.connect_to_signal("PropertiesChanged", self.track_changed)
self.notify_id = None
loop.run()
def track_changed(self, sender, metadata, signature):
if "Metadata" in metadata:
metadata = metadata["Metadata"]
title = metadata["xesam:title"]
album = metadata["xesam:album"]
artist = " ,".join(metadata["xesam:artist"])
knotify = dbus.SessionBus().get_object("org.kde.knotify", "/Notify")
id = knotify.event("warning", "kde", [], title, u"by %s from %s" % (artist, album), [], [], 10, 0, dbus_interface="org.kde.KNotify")
if __name__ == "__main__":
SpotifyNotifier()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment