fuck qdbus lol

This commit is contained in:
xenia 2021-06-26 00:31:18 -04:00
parent dce27613de
commit a716fbfec3
2 changed files with 44 additions and 42 deletions

44
np.10s.py Executable file
View File

@ -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")

View File

@ -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/&/&amp;/g' -e 's/</&lt;/g' -e 's/>/&gt;/g' -e 's/|/\&#124;/g')
artist=$(echo "$artist" | sed -e 's/&/&amp;/g' -e 's/</&lt;/g' -e 's/>/&gt;/g' -e 's/|/\&#124;/g')
artist2=$(echo "$artist2" | sed -e 's/&/&amp;/g' -e 's/</&lt;/g' -e 's/>/&gt;/g' -e 's/|/\&#124;/g')
if [ "$title" != "" ]; then
if [ "$artist" == "" ]; then
if [ "$artist2" == "" ]; then
echo "<span color='#ddccff'>$title</span> | iconName=multimedia-audio-player-symbolic"
else
echo "<span color='#ffffff'>$artist2</span> - <span color='#ddccff'>$title</span> | iconName=multimedia-audio-player-symbolic"
fi
else
echo "<span color='#ffffff'>$artist</span> - <span color='#ddccff'>$title</span> | iconName=multimedia-audio-player-symbolic"
fi
echo "---"
exit
fi
fi
done
echo "---"