Created
August 15, 2013 10:46
-
-
Save mollerse/6239948 to your computer and use it in GitHub Desktop.
Pythonscript for track-change notifications in KDE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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