Files
nixos/Droidnix/generated/.config/scripts/media.sh
T
2026-04-12 10:46:43 +02:00

64 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# --- This file has been auto-generated. For permanent changes alter the appropriate block in the README.org. ---
#!/usr/bin/env bash
player=$(playerctl -l 2>/dev/null | head -n1)
if [ -z "$player" ]; then
jq -c -n '{text: "", tooltip: "", class: "inactive"}'
exit 0
fi
status=$(playerctl --player="$player" status 2>/dev/null)
if [ "$status" != "Playing" ] && [ "$status" != "Paused" ]; then
jq -c -n '{text: "", tooltip: "", class: "inactive"}'
exit 0
fi
artist=$(playerctl --player="$player" metadata artist 2>/dev/null)
title=$(playerctl --player="$player" metadata title 2>/dev/null)
album=$(playerctl --player="$player" metadata album 2>/dev/null)
art=$(playerctl --player="$player" metadata mpris:artUrl 2>/dev/null)
length=$(playerctl --player="$player" metadata mpris:length 2>/dev/null)
position=$(playerctl --player="$player" position 2>/dev/null)
# Progress percentage
if [ -n "$length" ] && [ "$length" -gt 0 ] 2>/dev/null; then
progress=$(echo "scale=0; $position * 1000000 / $length * 100 / 100" | bc)
else
progress=0
fi
# Spotify device
device=""
if [[ "$player" == *"spotify"* ]]; then
device=$(playerctl --player="$player" metadata xesam:url 2>/dev/null | grep -o 'device=[^&]*' | cut -d= -f2)
fi
# Ticker text — truncate if long
text="${artist}${title}"
if [ ${#text} -gt 40 ]; then
text="${text:0:37}..."
fi
# Icon
if [ "$status" = "Paused" ]; then
icon="⏸ "
else
icon="▶ "
fi
# Build tooltip
tooltip="${artist}\n${title}\n${album}"
if [ -n "$device" ]; then
tooltip="${tooltip}\n󰓻 ${device}"
fi
tooltip="${tooltip}\n$(printf '%.0f' "$progress")%"
jq -c -n \
--arg text "${icon}${text}" \
--arg tooltip "$tooltip" \
--arg class "$player" \
--arg art "$art" \
'{text: $text, tooltip: $tooltip, class: $class, alt: $art}'