feat: emit duration + per-station history in liquidsoap
This commit is contained in:
parent
439ae3c9c0
commit
6bec95a563
1 changed files with 33 additions and 1 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue