Display playing media information
This commit is contained in:
@@ -22,7 +22,7 @@ module-margin-right = 2
|
|||||||
|
|
||||||
modules-left = i3 pulseaudio xbacklight battery-custom
|
modules-left = i3 pulseaudio xbacklight battery-custom
|
||||||
modules-center = datetime
|
modules-center = datetime
|
||||||
modules-right = vpn wlan bluetooth powermenu
|
modules-right = media vpn wlan bluetooth powermenu
|
||||||
|
|
||||||
tray-position = ${env:TRAY_POS:right}
|
tray-position = ${env:TRAY_POS:right}
|
||||||
tray-detached = false
|
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]
|
[module/vpn]
|
||||||
type = custom/script
|
type = custom/script
|
||||||
exec = ~/.config/polybar/scripts/running-vpn.sh
|
exec = ~/.config/polybar/scripts/running-vpn.sh
|
||||||
|
|||||||
32
.config/polybar/scripts/media.sh
Executable file
32
.config/polybar/scripts/media.sh
Executable file
@@ -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"
|
||||||
Reference in New Issue
Block a user