diff --git a/.config/polybar/config b/.config/polybar/config index 655e7bb..25e552f 100644 --- a/.config/polybar/config +++ b/.config/polybar/config @@ -22,7 +22,7 @@ module-margin-right = 2 modules-left = i3 pulseaudio xbacklight battery-custom modules-center = datetime -modules-right = vpn wlan bluetooth powermenu +modules-right = media vpn wlan bluetooth powermenu tray-position = ${env:TRAY_POS:right} tray-detached = false @@ -126,6 +126,13 @@ label = "%date% - %time%" ;################################################# ;################################################# +[module/media] +type=custom/script +exec = ~/.config/polybar/scripts/media.sh +interval = 1 + +;################################################# + [module/vpn] type = custom/script exec = ~/.config/polybar/scripts/running-vpn.sh diff --git a/.config/polybar/scripts/media.sh b/.config/polybar/scripts/media.sh new file mode 100755 index 0000000..a3efc5d --- /dev/null +++ b/.config/polybar/scripts/media.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +command -v playerctl >/dev/null 2>&1 || { printf "playerctl not found.\n" >&2; exit 1; } + +# metadata="$(playerctl metadata --format '{{status}} {{artist}} - {{title}} ({{duration(position)}}|{{duration(mpris:length)}})')" +metadata="$(playerctl metadata --format '{{status}} {{artist}}' 2>/dev/null)" +title="$(playerctl metadata --format '{{title}}' 2>/dev/null)" +duration="$(playerctl metadata --format '({{duration(position)}}|{{duration(mpris:length)}})' 2>/dev/null)" + + +if [ -n "$metadata" ] && [ "$metadata" != "No players found" ]; then + # Extract status (Playing|Paused) + status="${metadata%% *}" + artists="${metadata#* }" + + if [ "$status" = "Playing" ]; then + icon="" # \uf04b + else + icon="" # \uf04c + fi + + if [ ${#artists} -gt 15 ]; then + artists="$(echo "$artists" | cut -c -15)..." + fi + art_len=${#artists} + if [ ${#title} -gt $((30 + 15 - art_len)) ]; then + title="$(echo "$title" | cut -c -30)..." + fi + printf "$icon $artists - $title $duration" +fi + +printf "\n"