Created
February 22, 2013 12:30
-
-
Save JorenSix/5013099 to your computer and use it in GitHub Desktop.
Python script to fetch the meta data of the currently playing track in Spotify. Tested on Ubuntu.
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/python | |
# | |
# now_playing.py | |
# | |
# Python script to fetch the meta data of the currently playing | |
# track in Spotify. This is tested on Ubuntu. | |
import dbus | |
bus = dbus.SessionBus() | |
try: | |
spotify = bus.get_object('com.spotify.qt', '/') | |
iface = dbus.Interface(spotify, 'org.freedesktop.MediaPlayer2') | |
meta_data = iface.GetMetadata() | |
artistname = ",".join(meta_data['xesam:artist']) | |
trackname = meta_data['xesam:title'] | |
albumname = meta_data['xesam:album'] | |
#Other fields are: | |
# 'xesam:trackNumber', 'xesam:discNumber','mpris:trackid', | |
# 'mpris:length','mpris:artUrl','xesam:autoRating','xesam:contentCreated','xesam:url' | |
print str(trackname + " | " + artistname + " | " + albumname + " | Unknown") | |
except dbus.exceptions.DBusException: | |
print "Spotify is not running." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment