dotfiles/scripts/spot-data

33 lines
1.0 KiB
Plaintext
Raw Normal View History

2022-01-18 01:25:46 -05:00
#!/usr/bin/env python
# vim: ft=python
import dbus
try:
sess = dbus.SessionBus()
spotify = sess.get_object('org.mpris.MediaPlayer2.spotify', '/org/mpris/MediaPlayer2')
properties = dbus.Interface(spotify, 'org.freedesktop.DBus.Properties')
metadata = properties.Get("org.mpris.MediaPlayer2.Player", "Metadata")
status = properties.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus")
artist = metadata['xesam:artist'][0] if metadata['xesam:artist'] else ''
song = metadata['xesam:title'] if metadata['xesam:title'] else ''
album = metadata['xesam:album'] if metadata['xesam:album'] else ''
pause_symbol = " "
play_symbol = " "
if (not song and not artist):
print("")
if (song == "Advertisement" or not artist):
print(pause_symbol + "Advertisement")
else:
symbol = pause_symbol
if status == "Playing":
symbol = play_symbol
print(f"{symbol} {song}: {artist}"[:25] + "...")
except dbus.exceptions.DBusException:
print("")