From 7371d8e93a6b136d14e13a03a1ca40521b5005d0 Mon Sep 17 00:00:00 2001 From: silly Date: Tue, 31 Mar 2026 00:54:48 +0200 Subject: Update media.sh --- .config/scripts/media.sh | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/.config/scripts/media.sh b/.config/scripts/media.sh index a9c1acb..84c673b 100644 --- a/.config/scripts/media.sh +++ b/.config/scripts/media.sh @@ -1,10 +1,43 @@ #!/bin/bash -playerctl metadata --format '{{title}} - {{artist}}' --follow | while read -r line; do - if playerctl status >/dev/null 2>&1; then - art_url=$(playerctl metadata mpris:artUrl 2>/dev/null) - notify-send -i "$art_url" \ +prev_track="" + +while true; do + status=$(playerctl status 2>/dev/null | tr '[:upper:]' '[:lower:]') + + if [ "$status" = "playing" ]; then + title=$(playerctl metadata title 2>/dev/null | tr '[:upper:]' '[:lower:]') + artist=$(playerctl metadata artist 2>/dev/null | tr '[:upper:]' '[:lower:]') + track="${title}${artist}" + + if [ "$track" != "$prev_track" ] && [ -n "$title" ]; then + prev_track="$track" + player=$(playerctl metadata --format '{{playerName}}' 2>/dev/null | tr '[:upper:]' '[:lower:]') + player_label="${player} [hifi]" + art_url="" + for i in $(seq 1 10); do + art_url=$(playerctl metadata mpris:artUrl 2>/dev/null) + [ -n "$art_url" ] && break + sleep 0.2 + done + + if [ -n "$art_url" ]; then + ext="${art_url##*.}" + ext="${ext%%\?*}" + art_cache="/tmp/art.${ext}" + curl -sL --max-time 5 "$art_url" -o "$art_cache" + notify-send \ + -i "$art_cache" \ + -h string:x-canonical-private-synchronous:media \ + "${title} • ${artist}" \ + "$player_label" + else + notify-send \ + -i "audio-x-generic" \ -h string:x-canonical-private-synchronous:media \ - "playing" "$line" + "${title} • ${artist}" \ + "$player_label" + fi + fi fi done -- cgit v1.3.1