fix: music player script

This commit is contained in:
Ahwx 2025-06-03 16:14:31 +02:00
parent 59678dc58a
commit 6dc8ddcfc9

View file

@ -155,27 +155,24 @@
"/home/${username}/.local/bin/waybar-music" = { "/home/${username}/.local/bin/waybar-music" = {
executable = true; executable = true;
text = '' text = ''
#!/usr/bin/env bash #!/usr/bin/env sh
class=$(playerctl metadata --player=ncspot --format '{{lc(status)}}') META="{{ trunc(artist,17) }} - {{ trunc(title,17) }}"
PLAYERS="spotify ncspot mpv mpd"
if [[ $class == "playing" ]]; then for PLAYER in $PLAYERS; do
info=$(playerctl metadata --player=ncspot --format '{{artist}} - {{title}}') # if the player is not playing, continue to the next player, until we find one that is playing
if [[ $\{#info} > 40 ]]; then [ "$(playerctl --player=$PLAYER status 2>/dev/null)" != "Playing" ] && continue
info=$(echo $info | cut -c1-40)"..." text=$(playerctl metadata --player $PLAYER --format "$META")
fi echo -e "{\"text\":\""$text"\", \"class\":\"Playing\"}"
text="$info" exit 0
elif [[ $class == "paused" ]]; then done
info=$(playerctl metadata --player=ncspot --format '{{artist}} - {{title}}')
if [[ $\{#info} > 40 ]]; then
info=$(echo $info | cut -c1-40)"..."
fi
text=" $info"
elif [[ $class == "stopped" ]]; then
text=""
fi
echo -e "{\"text\":\""$text"\", \"class\":\""$class"\"}" ICON=" "
PAUSERS="spotify ncspot mpd"
for PAUSER in $PAUSERS; do
[ "$(playerctl --player=$PAUSER status 2>/dev/null)" == "Paused" ] || [ "$(playerctl --player=$PAUSER status 2>/dev/null)" == "Stopped" ] && text="$ICON"$(playerctl metadata --player $PAUSER --format "$META") && echo -e "{\"text\":\""$text"\", \"class\":\""paused"\"}" && exit 0
done
''; '';
}; };
"/home/${username}/.local/bin/waybar-devices" = { "/home/${username}/.local/bin/waybar-devices" = {