diff --git a/config/liquidsoap.liq b/config/liquidsoap.liq index 52e7d88..3141443 100644 --- a/config/liquidsoap.liq +++ b/config/liquidsoap.liq @@ -36,25 +36,32 @@ 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 + entry = { + title = m["title"], + artist = m["artist"], + album = m["album"], + filename = filename, + started_at = string(int_of_float(time())) + } arr = - try - json.parse(default=([] : [json]), existing) - catch _ do - ([] : [json]) + if file.exists(history_path) then + existing = file.contents(history_path) + try + let json.parse (parsed : [{ + title: string, + artist: string, + album: string, + filename: string, + started_at: string + }]) = existing + parsed + catch _ do + [] + end + else + [] 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)) + new_arr = list.add(entry, list.prefix(49, arr)) out_str = json.stringify(new_arr) file.write(data=out_str, atomic=true, temp_dir="/now-playing", history_path) end