Skip to content

Instantly share code, notes, and snippets.

@JorenSix
Created February 22, 2013 12:30
Show Gist options
  • Save JorenSix/5013099 to your computer and use it in GitHub Desktop.
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.
#!/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