icytv-liq/liq/metadata.liq

38 lines
814 B
Plaintext

# send metadata to server and print the response
def send_metadata(m)
data = json_of(m)
# print("Sending metadata: "^data)
ignore(http.post(
data = data,
headers = [("Content-Type", "application/json; charset=utf-8")],
timeout = 10.0,
"http://#{confstr('api.host', 'localhost')}:#{confstr('api.port', '7005')}#{confstr('api.mount', 'api')}/internal/meta"
))
end
def update_nowplaying(m)
# Encode all text in UTF-8
recode = string.recode(out_enc="UTF-8")
def f(x)
(recode(fst(x)),recode(snd(x)))
end
m = list.map(f,m)
# Remove pictures from metadata
m = list.remove_assoc("cover", m)
m = list.remove_assoc("picture", m)
# Append start time to metadata
m = if m != [] then
list.append(
[("start", string_of(time()))]
, m)
else
m
end
# Publish to API
send_metadata(m)
end