From 6bec95a563a7916ec52b627e51a8856daf4dc40d Mon Sep 17 00:00:00 2001 From: devilreef Date: Thu, 30 Apr 2026 09:18:18 +0600 Subject: [PATCH] feat: emit duration + per-station history in liquidsoap --- config/liquidsoap.liq | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/config/liquidsoap.liq b/config/liquidsoap.liq index 7c96e5e..fab96fa 100644 --- a/config/liquidsoap.liq +++ b/config/liquidsoap.liq @@ -15,18 +15,50 @@ def emit_now_playing(station, m) = payload.add("title", m["title"]) payload.add("album", m["album"]) payload.add("filename", filename) + payload.add("duration", m["duration"]) payload.add("started_at", string(int_of_float(time()))) file.write(data=payload.stringify(), atomic=true, temp_dir="/now-playing", "/now-playing/#{station}.json") end end +def append_history(station, m) = + filename = m["filename"] + if filename != "" then + history_path = "/now-playing/#{station}.history.json" + existing = + if file.exists(history_path) then + file.contents(history_path) + else + "[]" + end + arr = + try + json.parse(default=([] : [json]), existing) + catch _ do + ([] : [json]) + end + entry = json() + entry.add("title", m["title"]) + entry.add("artist", m["artist"]) + entry.add("album", m["album"]) + entry.add("filename", filename) + entry.add("started_at", string(int_of_float(time()))) + new_arr = list.add(entry, list.prefix(50, arr)) + out_str = json.stringify(new_arr) + file.write(data=out_str, atomic=true, temp_dir="/now-playing", history_path) + end +end + # === station: minecraft === minecraft = playlist( reload_mode="watch", mode="randomize", "/library/minecraft/tracks" ) -minecraft.on_track(fun (m) -> emit_now_playing("minecraft", m)) +minecraft.on_track(fun (m) -> begin + emit_now_playing("minecraft", m) + append_history("minecraft", m) +end) minecraft = crossfade(minecraft) minecraft = mksafe(minecraft)