From 52c6750a51e9b0e06683000422ce06253859e6dd Mon Sep 17 00:00:00 2001 From: devilreef Date: Thu, 30 Apr 2026 11:22:50 +0600 Subject: [PATCH] fix(liquidsoap): switch append_history to let json.parse with typed record old json.parse(default=...) silently failed on every track change so recent-played always showed only one entry. modern let-form parses the existing history file correctly. --- config/liquidsoap.liq | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) 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