Created
April 27, 2017 01:46
-
-
Save shaunhey/44b11c7dbf05671463fb1cc1c91a3fd3 to your computer and use it in GitHub Desktop.
Example on how to use python-dbus to receive notification of song changes
This file contains 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 gobject | |
import dbus | |
import dbus.service | |
import dbus.mainloop.glib | |
def on_properties_changed(interface, props, invalidated_props): | |
if "Metadata" in props: | |
metadata = props.get("Metadata") | |
artists = metadata.get("xesam:artist") | |
title = metadata.get("xesam:title") | |
album = metadata.get("xesam:album") | |
track_num = metadata.get("xesam:trackNumber") | |
print " Track: " + str(track_num) | |
print "Artist: " + artists[0] | |
print " Album: " + album | |
print " Title: " + title | |
print "" | |
if __name__ == "__main__": | |
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | |
player = dbus.SessionBus().get_object("org.mpris.MediaPlayer2.rhythmbox", "/org/mpris/MediaPlayer2") | |
player.connect_to_signal("PropertiesChanged", on_properties_changed) | |
loop = gobject.MainLoop() | |
loop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment