Files
.dotfiles/bin/waybar-custom-cider.sh
2026-02-02 18:29:39 +01:00

35 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
url="http://localhost:10767/api/v1/playback"
status_raw=$(curl -s --max-time 2 "$url/is-playing")
# CASE 1: API is totally unreachable (App closed)
if [[ -z "$status_raw" ]]; then
echo '{"text": "offline", "class": "offline", "alt": "offline"}'
exit 0
fi
# Extract playing status, defaulting to false if null
is_playing=$(echo "$status_raw" | jq -r '.is_playing // false')
# 2. Get song info
info_raw=$(curl -s --max-time 2 "$url/now-playing")
# CASE 2 & 3: Handle empty metadata vs. active metadata
echo "$info_raw" | jq -c \
--argjson is_playing "$is_playing" \
'
# Helper function to escape & for Pango
def pango_escape: sub("&"; "&"; "g");
if (.info.name == null or .info.name == "") then
{text: "idle", class: "paused"}
else
{
text: "\(.info.name | pango_escape) - \(.info.artistName | pango_escape)",
tooltip: "\(.info.albumName | pango_escape // "Unknown")",
class: (if $is_playing then "playing" else "paused" end)
}
end'