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.
This commit is contained in:
parent
abca97b4ac
commit
52c6750a51
1 changed files with 24 additions and 17 deletions
|
|
@ -36,25 +36,32 @@ def append_history(station, m) =
|
||||||
filename = m["filename"]
|
filename = m["filename"]
|
||||||
if filename != "" then
|
if filename != "" then
|
||||||
history_path = "/now-playing/#{station}.history.json"
|
history_path = "/now-playing/#{station}.history.json"
|
||||||
existing =
|
entry = {
|
||||||
if file.exists(history_path) then
|
title = m["title"],
|
||||||
file.contents(history_path)
|
artist = m["artist"],
|
||||||
else
|
album = m["album"],
|
||||||
"[]"
|
filename = filename,
|
||||||
end
|
started_at = string(int_of_float(time()))
|
||||||
|
}
|
||||||
arr =
|
arr =
|
||||||
try
|
if file.exists(history_path) then
|
||||||
json.parse(default=([] : [json]), existing)
|
existing = file.contents(history_path)
|
||||||
catch _ do
|
try
|
||||||
([] : [json])
|
let json.parse (parsed : [{
|
||||||
|
title: string,
|
||||||
|
artist: string,
|
||||||
|
album: string,
|
||||||
|
filename: string,
|
||||||
|
started_at: string
|
||||||
|
}]) = existing
|
||||||
|
parsed
|
||||||
|
catch _ do
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
[]
|
||||||
end
|
end
|
||||||
entry = json()
|
new_arr = list.add(entry, list.prefix(49, arr))
|
||||||
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)
|
out_str = json.stringify(new_arr)
|
||||||
file.write(data=out_str, atomic=true, temp_dir="/now-playing", history_path)
|
file.write(data=out_str, atomic=true, temp_dir="/now-playing", history_path)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue