From a67ba8b1c2724dd0c1fd6714c2c6b7146e6e49c3 Mon Sep 17 00:00:00 2001 From: David Trattnig <david@subsquare.at> Date: Fri, 10 Jun 2022 11:05:27 +0200 Subject: [PATCH] Refact: Use new JSON builder --- src/engine.liq | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/engine.liq b/src/engine.liq index 23efbf3..f02ca0e 100644 --- a/src/engine.liq +++ b/src/engine.liq @@ -38,13 +38,19 @@ inputs = ref ([]) def on_metadata_notification(meta) = filename = meta["filename"] track_duration = request.duration(filename) - json_data = json.stringify(meta, compact=true) - json_data = url.encode(json_data) - json_data = '{ "action": "on_metadata", "meta": "#{json_data}", "track_duration": "#{track_duration}" }' - # There's currently an issue with Liquidsoap http.post requests (should be gone with Liquidsoap 2): - #headers = [("Content-Type","application/json; charset=utf-8")] - #ignore(http.post(headers=headers, data="#{json_data}", "localhost:1337")) - ignore(process.run("curl -X POST -H 'Content-Type: application/json' --data '#{json_data}' #{engine_control}")) + + # TODO Post playlog to engine-api directly. This requires some additional show state handling. + json_data = json() + json_data.add("action", "on_metadata") + json_data.add("meta", meta) + json_data.add("track_duration", track_duration) + playlog = url.encode(json.stringify(json_data)) + + log(level=3, "Posting playlog: #{playlog}") + # headers = [("Content-Type","application/json; charset=utf-8")] + # result = http.post(http_version="1.1", headers=headers, data="#{playlog}", "#{engine_control}") + ignore(process.run("curl -X POST -H 'Content-Type: application/json' --data '#{playlog}' #{engine_control}")) + end ##################################### -- GitLab