diff --git a/np.10s.py b/np.10s.py new file mode 100755 index 0000000..6841c7f --- /dev/null +++ b/np.10s.py @@ -0,0 +1,44 @@ +#!/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") diff --git a/np.10s.sh b/np.10s.sh deleted file mode 100755 index dd400c2..0000000 --- a/np.10s.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -MPRIS_ROOT='org.mpris.MediaPlayer2.*' -MPRIS_PATH='/org/mpris/MediaPlayer2' -DBUS_GET='org.freedesktop.DBus.Properties.Get' -MPRIS_PLAYER='org.mpris.MediaPlayer2.Player' -XESAM_ARTIST="xesam:albumArtist: " -XESAM_ARTIST2="xesam:artist: " -XESAM_TITLE="xesam:title: " - -for player in $(qdbus $MPRIS_ROOT); do - state=$(qdbus "$player" $MPRIS_PATH $DBUS_GET $MPRIS_PLAYER PlaybackStatus) - if [ "$state" == "Playing" ]; then - metadata=$(qdbus "$player" $MPRIS_PATH $DBUS_GET $MPRIS_PLAYER Metadata) - artist=$(echo "$metadata" | grep "$XESAM_ARTIST") - artist=${artist#"$XESAM_ARTIST"} - artist2=$(echo "$metadata" | grep "$XESAM_ARTIST2") - artist2=${artist2#"$XESAM_ARTIST2"} - title=$(echo "$metadata" | grep "$XESAM_TITLE") - title=${title#"$XESAM_TITLE"} - - title=$(echo "$title" | sed -e 's/&/&/g' -e 's//>/g' -e 's/|/\|/g') - artist=$(echo "$artist" | sed -e 's/&/&/g' -e 's//>/g' -e 's/|/\|/g') - artist2=$(echo "$artist2" | sed -e 's/&/&/g' -e 's//>/g' -e 's/|/\|/g') - - if [ "$title" != "" ]; then - if [ "$artist" == "" ]; then - if [ "$artist2" == "" ]; then - echo "$title | iconName=multimedia-audio-player-symbolic" - else - echo "$artist2 - $title | iconName=multimedia-audio-player-symbolic" - fi - else - echo "$artist - $title | iconName=multimedia-audio-player-symbolic" - fi - echo "---" - exit - fi - fi -done - -echo "---"