gnome-now-playing/np.10s.py

45 lines
1.6 KiB
Python
Raw Normal View History

2021-06-26 04:31:18 +00:00
#!/usr/bin/env python3
from pydbus import SessionBus
import sys
bus = SessionBus()
all_names = bus.get("org.freedesktop.DBus", "/org/freedesktop/DBus").ListNames()
for name in all_names:
if name.startswith("org.mpris.MediaPlayer2."):
mpris = bus.get(name, "/org/mpris/MediaPlayer2")
status = mpris.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus")
metadata = mpris.Get("org.mpris.MediaPlayer2.Player", "Metadata")
if status == "Playing":
title = metadata.get("xesam:title", None)
artist = metadata.get("xesam:artist", None)
if artist is None:
artist = metadata.get("xesam:albumArtist", None)
if artist is not None:
artist = ", ".join(artist)
album = metadata.get("xesam:album", None)
if len(artist.strip()) == 0:
artist = None
if len(title.strip()) == 0:
title = None
if len(album.strip()) == 0:
album = None
if artist is not None:
sys.stdout.write(artist)
if title is not None:
if artist is not None:
sys.stdout.write(" - ")
sys.stdout.write(title)
if album is not None:
if artist is not None or title is not None:
sys.stdout.write(" / ")
sys.stdout.write(album)
if artist is not None or album is not None or title is not None:
sys.stdout.write(" | iconName=multimedia-audio-player-symbolic\n")
break
sys.stdout.write("---\n")