Improve eww
update.yml (push) Invalid workflow file

This commit is contained in:
sora committed 2026-10-30 16:01:01 +01:00
1 parent 6e2601a39c
commit 208e7cb2b2
5 files changed
+154 -4

No files matched your search

@@ -15,8 +15,9 @@ api="https://www.radiorecord.ru/api"
unit=eww-radio
state_dir=${XDG_STATE_HOME:-$HOME/.local/state}/eww
cache_dir=${XDG_CACHE_HOME:-$HOME/.cache}/eww
img_dir=$cache_dir/radio-img
id_file=$state_dir/radio-station
mkdir -p "$state_dir" "$cache_dir"
mkdir -p "$state_dir" "$cache_dir" "$img_dir"
station_ids='[507,522,523,536,537,42532,42602]'
# Extra stations: {id (unique integer >= 1000000), title, stream_hls, icon_fill_white ("" for none)}
@@ -47,6 +48,32 @@ stations() {
printf '%s\n' "$out"
}
# GTK loads CSS url() images synchronously on the UI thread: a remote URL
# freezes the whole daemon until the download finishes (or times out). eww
# only ever gets file:// URIs of cached copies.
local_img() { # URL → file:// URI, "" if unavailable
local url=$1 f
case $url in
file://*) printf '%s' "$url"; return ;;
/*) printf 'file://%s' "$url"; return ;;
http://* | https://*) ;;
*) return ;;
esac
f=$img_dir/$(cksum <<<"$url" | cut -d' ' -f1)
if [[ ! -s $f ]]; then
curl -sfL --max-time 5 -o "$f.tmp" "$url" 2>/dev/null && mv "$f.tmp" "$f" || { rm -f "$f.tmp"; return; }
fi
printf 'file://%s' "$f"
}
localize_stations() {
local url map='{}'
while IFS= read -r url; do
map=$(jq -c --arg k "$url" --arg v "$(local_img "$url")" '.[$k] = $v' <<<"$map")
done < <(jq -r '.[].icon_fill_white // empty' <<<"$STATIONS" | sort -u)
STATIONS=$(jq -c --argjson m "$map" 'map(.icon_fill_white = ($m[.icon_fill_white // ""] // ""))' <<<"$STATIONS")
}
station() { # ID FIELD
jq -r --argjson id "${1:-0}" --arg f "$2" 'first(.[] | select(.id == $id) | .[$f]) // empty' <<<"$STATIONS"
}
@@ -141,7 +168,8 @@ song_playing() { # ID → SONG from the station history (radiorecord) or the tit
if [[ $(station "$id" radiorecord) == true ]]; then
fetched=$(curl -sf --compressed --max-time 8 "$api/station/history/?id=$id" 2>/dev/null \
| jq -c '.result.history[0] | {artist: (.artist // ""), song: (.song // ""), image600: (.image600 // "")}' 2>/dev/null)
[[ -n $fetched && $fetched != null ]] && SONG=$fetched
[[ -n $fetched && $fetched != null ]] \
&& SONG=$(jq -c --arg i "$(local_img "$(jq -r .image600 <<<"$fetched")")" '.image600 = $i' <<<"$fetched")
else
SONG=$(jq -cn --arg t "$(station "$id" title)" '{artist: "", song: $t, image600: ""}')
fi
@@ -159,7 +187,7 @@ media_event() {
if [[ -z $player ]]; then
MEDIA=$default_media MEDIA_PLAYER=""
elif [[ $player != mpv* ]]; then # the radio and jellyfin are mpv, not "external"
MEDIA=$(media_json "$player" "$status" "$artist" "$title" "$art")
MEDIA=$(media_json "$player" "$status" "$artist" "$title" "$(local_img "$art")")
MEDIA_PLAYER=$player
fi
}
@@ -206,7 +234,9 @@ refresh() {
}
status_loop() {
find "$img_dir" -type f -mtime +7 -delete 2>/dev/null
STATIONS=$(stations)
localize_stations
SONG=$default_song MEDIA=$default_media MEDIA_PLAYER="" PLAYING="" LAST_SONG=0 LAST_VOL=""
refresh
mux_init