From 78a0572e0ebb7a8ec7c188fceda5a28043b75e83 Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Sat, 10 Apr 2021 14:08:45 +0200 Subject: [PATCH] * Improved kaoget.sh: - accept download URLs on command line - skip comment lines - better partial download handling --- kaoget.sh | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/kaoget.sh b/kaoget.sh index bff00db..b461f8f 100755 --- a/kaoget.sh +++ b/kaoget.sh @@ -20,9 +20,37 @@ POST_AUTH="--post-data=\'auth=$USER:$PASS\'" ## 3rd alternative: HTTP_AUTH="--user=$USER --password=$PASS" +case "$URL_FILE" in + https://* ) + # Got an URL for the file parameter. + TMP_FILE=$(mktemp kaoget_XXXX) + case "$URL_FILE" in + *"&q=1&m=0" ) + # If it appears to point to a generated directory listing, wget it. + echo "# If it appears to point to a generated directory listing, wget it." + wget -c --retry-connrefused \ + $POST_AUTH \ + $HTTP_AUTH --auth-no-challenge \ + -O "$TMP_FILE" \ + "$URL_FILE$GET_AUTH" + ;; + *) + # Otherwise, store the URL verbatim. + echo "echo $URL_FILE > $TMP_FILE" + echo "$URL_FILE" > $TMP_FILE + ;; + esac + # Either way, use the new file as the source for download URLs. + URL_FILE=$TMP_FILE + ;; +esac + while read URL; do case "$URL" in + "#"* ) + continue + ;; */dl.php*f=* ) NAME=${URL#*f=} NAME=${NAME%&*} @@ -44,12 +72,17 @@ while read URL; do if [ -n "$NAME" ] ; then mkdir -p "$(dirname "$NAME")" + PNAME="$NAME".part + mv "$NAME" "$PNAME" 2> /dev/null wget -c --retry-connrefused \ $POST_AUTH \ $HTTP_AUTH --auth-no-challenge \ $BWLIM \ - -O "$NAME" \ - "$URL$GET_AUTH" + -O "$PNAME" \ + "$URL$GET_AUTH" \ + && mv "$PNAME" "$NAME" fi done < "$URL_FILE" + +[ -n "$TMP_FILE" ] && rm -f $TMP_FILE -- 2.30.2