* Improved kaoget.sh:
authorUrban Wallasch <urban.wallasch@freenet.de>
Sat, 10 Apr 2021 12:08:45 +0000 (14:08 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Sat, 10 Apr 2021 12:08:45 +0000 (14:08 +0200)
    - accept download URLs on command line
    - skip comment lines
    - better partial download handling

kaoget.sh

index bff00db1798df877fc26ad2dead28a8adc131ceb..b461f8f0ccbd2bb62e7ba9410ab759504850cf40 100755 (executable)
--- 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