From c7af18f0f40f467875bafa7eefc625d0f56e31dc Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Sat, 20 Apr 2024 11:00:12 +0100 Subject: [PATCH] feat: add web_redirect() --- quickget | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/quickget b/quickget index 74f4079..241465f 100755 --- a/quickget +++ b/quickget @@ -1517,6 +1517,18 @@ function web_get() { fi } +function web_redirect() { + local URL="${1}" + # Check for URL redirections + # Output to nonexistent directory so the download fails fast + local REDIRECT_URL=$(curl --silent --location --fail --write-out %{url_effective} --output /var/cache/${RANDOM}/${RANDOM} "${URL}") + if [ "${REDIRECT_URL}" != "${URL}" ]; then + echo "${REDIRECT_URL}" + else + echo "${URL}" + fi +} + function zsync_get() { local DIR="${2}" local FILE="${1##*/}"