refactor: update web_get() to use web_redirect()

This commit is contained in:
Martin Wimpress 2024-04-20 11:02:12 +01:00 committed by Martin Wimpress
parent 592b838db6
commit 86cb0cdf04
1 changed files with 2 additions and 8 deletions

View File

@ -1446,9 +1446,10 @@ function web_pipe() {
} }
function web_get() { function web_get() {
local URL=""
URL=$(web_redirect "${1}")
local DIR="${2}" local DIR="${2}"
local FILE="" local FILE=""
local URL="${1}"
local USER_AGENT="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" local USER_AGENT="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
if [ -n "${3}" ]; then if [ -n "${3}" ]; then
@ -1487,13 +1488,6 @@ function web_get() {
fi fi
if command -v curl &>/dev/null; then if command -v curl &>/dev/null; then
# Check for URL redirections
# Output to nonexistent directory so the download fails fast
local REDIRECT_URL=$(curl --silent --location --fail "${URL}" --write-out %{url_effective} --output /var/cache/${RANDOM}/${RANDOM})
if [ "${REDIRECT_URL}" != "${URL}" ]; then
echo "- Redirected: ${REDIRECT_URL}"
URL="${REDIRECT_URL}"
fi
if ! curl --progress-bar --location --output "${DIR}/${FILE}" --continue-at - --user-agent "${USER_AGENT}" "${HEADERS[@]}" -- "${URL}"; then if ! curl --progress-bar --location --output "${DIR}/${FILE}" --continue-at - --user-agent "${USER_AGENT}" "${HEADERS[@]}" -- "${URL}"; then
echo "ERROR! Failed to download ${URL} with curl." echo "ERROR! Failed to download ${URL} with curl."
echo " Try deleting '${DIR}/${FILE}' running 'quickget' again." echo " Try deleting '${DIR}/${FILE}' running 'quickget' again."