From 96ec93fd02f44eb90f081343ba0b35964b8345e6 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Thu, 19 Dec 2024 19:37:10 +0100 Subject: [PATCH] Fix: create correct json for status file and validate it --- build.sh | 12 +++++++++--- docs/db/index/status.min.json | 13 ++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 644b9921..b4415005 100755 --- a/build.sh +++ b/build.sh @@ -1316,7 +1316,7 @@ check_stream_all_json() { local rc=0 exec 3<> "${STATUSFILE}.tmp" printf "{" >&3 - local ENTRY_COUNT=0 + local PRINT_COMMA=0 local F for F in "$PLS_DIR/"* do @@ -1348,7 +1348,7 @@ check_stream_all_json() { then if [ $RETRY_COUNT -eq 5 ] then - [ "$ENTRY_COUNT" -gt 0 ] && printf "," >&3 + [ "$PRINT_COMMA" -eq 1 ] && printf "," >&3 OUT=$(jq -n --arg value "$OUT" '$value') local DATE DATE=$(date +%Y-%m-%d) @@ -1359,9 +1359,10 @@ check_stream_all_json() { echo "" echo "Error count too high, removing $M3U_NAME" delete_radio_by_m3u "$M3U_NAME" + PRINT_COMMA=0 else printf "\"%s\":{\"date\":\"%s\",\"count\":%s,\"error\":%s}" "$M3U" "$DATE" "$ERROR_COUNT" "$OUT" >&3 - ENTRY_COUNT=$((ENTRY_COUNT+1)) + PRINT_COMMA=1 fi echo "" echo "Error getting streaminfo for \"$F\" ($ERROR_COUNT): $OUT" @@ -1379,6 +1380,11 @@ check_stream_all_json() { done printf "}" >&3 exec 3>&- + if ! jq < "${STATUSFILE}" > /dev/null + then + echo "Invalid statusfile: ${STATUSFILE}" + exit 1 + fi if move_compress_changed "${STATUSFILE}" then echo "Streamstatus updated" diff --git a/docs/db/index/status.min.json b/docs/db/index/status.min.json index a96b7292..c4102b88 100644 --- a/docs/db/index/status.min.json +++ b/docs/db/index/status.min.json @@ -1 +1,12 @@ -{"https___82722d_ha_azioncdn_net_ebc_radionacionalriodejaneiro_chunks_m3u8.m3u":{"date":"2024-12-19","count":8,"error":"https://82722d.ha.azioncdn.net/ebc/radionacionalriodejaneiro/chunks.m3u8: Server returned 404 Not Found"},,,,"https___edge56_live-sm_absolutradio_de_absolut-relax_stream_mp3.m3u":{"date":"2024-12-19","count":8,"error":"https://edge56.live-sm.absolutradio.de/absolut-relax/stream/mp3: Server returned 404 Not Found"},} \ No newline at end of file +{ + "https___82722d_ha_azioncdn_net_ebc_radionacionalriodejaneiro_chunks_m3u8.m3u": { + "date": "2024-12-19", + "count": 8, + "error": "https://82722d.ha.azioncdn.net/ebc/radionacionalriodejaneiro/chunks.m3u8: Server returned 404 Not Found" + }, + "https___edge56_live-sm_absolutradio_de_absolut-relax_stream_mp3.m3u": { + "date": "2024-12-19", + "count": 8, + "error": "https://edge56.live-sm.absolutradio.de/absolut-relax/stream/mp3: Server returned 404 Not Found" + } +} \ No newline at end of file