Files
dotfiles/waybar/scripts/nowplaying.sh
2026-02-25 01:35:25 +01:00

25 lines
603 B
Bash
Executable File

#!/bin/bash
CACHE="$HOME/.cache/waybar-cover.jpg"
TMP="$HOME/.cache/waybar-cover.tmp.jpg"
status=$(playerctl status 2>/dev/null)
if [ "$status" = "Playing" ]; then
artist=$(playerctl metadata artist)
title=$(playerctl metadata title)
url=$(playerctl metadata mpris:artUrl)
if [[ "$url" == file://* ]]; then
cp "${url#file://}" "$TMP"
else
curl -sL "$url" -o "$TMP"
fi
mv -f "$TMP" "$CACHE"
echo "{\"text\": \"$artist - $title\", \"tooltip\": \"$artist - $title\", \"class\": \"playing\", \"alt\": \"$CACHE\"}"
else
echo "{\"text\": \"󰐎 \", \"class\": \"stopped\"}"
fi