Created
May 13, 2018 04:38
-
-
Save seanpianka/e313772cc6c71d96d56043f7af4b9010 to your computer and use it in GitHub Desktop.
A Python script which can display information for the currently playing track on Spotify for Linux.
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
import dbus | |
import time | |
session_bus = dbus.SessionBus() | |
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify", | |
"/org/mpris/MediaPlayer2") | |
spotify_properties = dbus.Interface(spotify_bus, | |
"org.freedesktop.DBus.Properties") | |
def get_playing_now(): | |
metadata = spotify_properties.Get("org.mpris.MediaPlayer2.Player", "Metadata") | |
return {'title': str(metadata['xesam:title']), | |
'artist': str(metadata['xesam:artist'][0]), | |
'album': str(metadata['xesam:album'])} | |
def all_metadata(): | |
# The property Metadata behaves like a python dict | |
md = {} | |
for key, value in metadata.items(): | |
md[key] = value | |
return md | |
def _main(): | |
current_song = get_playing_now() | |
last_song = current_song | |
print(current_song) | |
while True: | |
current_song = get_playing_now() | |
if current_song != last_song: | |
last_song = current_song | |
print(current_song) | |
time.sleep(2) | |
if __name__ == '__main__': | |
_main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment