From a9b2a07a1c961d081f8e3fde8864e22ada6214ec Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Wed, 15 Feb 2023 23:41:12 +0100 Subject: [PATCH] api-helper: Use 'sed' to remove tracking parameters --- scripts/yt-api-helper.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/yt-api-helper.sh b/scripts/yt-api-helper.sh index 8cc3dec..af2ece1 100755 --- a/scripts/yt-api-helper.sh +++ b/scripts/yt-api-helper.sh @@ -483,8 +483,19 @@ fi hdr_ua="User-Agent: ${user_agent}" -# Default to STDOUT if no output file was given -if [ -z "$output" ]; then output='-'; fi # Run! -curl --compressed -o "$output" -H "$hdr_ct" -H "$hdr_ua" --data "$data" "$url" +result=$( + curl --compressed -H "$hdr_ct" -H "$hdr_ua" --data "$data" "$url" | \ + sed -E ' + /^\s+"(clickT|t)rackingParams.+,$/d + s/,?\n\s+"(clickT|t)rackingParams.+$// + ' +) + +# Default to STDOUT if no output file was given +if [ -z "$output" ]; then + echo "$result" +else + echo "$result" > "$output" +fi