feat: emit duration + per-station history in liquidsoap

This commit is contained in:
devilreef 2026-04-30 09:18:18 +06:00
parent 439ae3c9c0
commit 6bec95a563
Signed by: devilreef
SSH key fingerprint: SHA256:UZisRr4iuXx+IhkbZnR655L2RWAT6o2rgbGv5F/6m3Y

View file

@ -15,18 +15,50 @@ def emit_now_playing(station, m) =
payload.add("title", m["title"]) payload.add("title", m["title"])
payload.add("album", m["album"]) payload.add("album", m["album"])
payload.add("filename", filename) payload.add("filename", filename)
payload.add("duration", m["duration"])
payload.add("started_at", string(int_of_float(time()))) payload.add("started_at", string(int_of_float(time())))
file.write(data=payload.stringify(), atomic=true, temp_dir="/now-playing", "/now-playing/#{station}.json") file.write(data=payload.stringify(), atomic=true, temp_dir="/now-playing", "/now-playing/#{station}.json")
end end
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 === # === station: minecraft ===
minecraft = playlist( minecraft = playlist(
reload_mode="watch", reload_mode="watch",
mode="randomize", mode="randomize",
"/library/minecraft/tracks" "/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 = crossfade(minecraft)
minecraft = mksafe(minecraft) minecraft = mksafe(minecraft)