#!/usr/bin/env bash # Outputs current media status for hyprlock's label widget. # Format: Artist - Title [progress bar] m:ss/m:ss if ! command -v playerctl &>/dev/null; then exit 0 fi status=$(playerctl status 2>/dev/null) case "$status" in Playing) icon="⏵" ;; Paused) icon="⏸" ;; *) exit 0 ;; # nothing playing / no player -> blank label esac artist=$(playerctl metadata artist 2>/dev/null) title=$(playerctl metadata title 2>/dev/null) position=$(playerctl position 2>/dev/null | cut -d. -f1) length_us=$(playerctl metadata mpris:length 2>/dev/null) length=$((length_us / 1000000)) format_time() { printf '%d:%02d' $(($1 / 60)) $(($1 % 60)) } bar_width=20 if [[ -n "$length" && "$length" -gt 0 && -n "$position" ]]; then filled=$((position * bar_width / length)) ((filled > bar_width)) && filled=$bar_width empty=$((bar_width - filled)) bar="$(printf '█%.0s' $(seq 1 $filled 2>/dev/null))$(printf '░%.0s' $(seq 1 $empty 2>/dev/null))" time_str="$(format_time "$position")/$(format_time "$length")" else bar="" time_str="" fi echo "$icon $artist - $title $bar $time_str"