* Replaced all sed invocations in kaoget.sh using only bash built-ins.
authorUrban Wallasch <urban.wallasch@freenet.de>
Fri, 30 Apr 2021 13:59:02 +0000 (15:59 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Fri, 30 Apr 2021 13:59:02 +0000 (15:59 +0200)
kaoget.sh

index daf437139163112fdac25e5c562a63417a5c87a3..2d45085ec46e1186186c7a8cbc8ccfdcb87e032c 100755 (executable)
--- a/kaoget.sh
+++ b/kaoget.sh
@@ -61,9 +61,13 @@ case $(basename $GETTER) in
 esac
 #[ -n "$USER" ] && [ -n "$PASS" ] && GET_AUTH="&auth=$USER:$PASS"
 
+function rawurldecode() {
+  local s="${1//+/ }"
+  printf '%b' "${s//%/\\x}"
+}
 
 function make_kix {
-  KIX="$1"
+  local KIX="$1"
   case "$KIX" in
    */dl.php*f=* )
     KIX=${KIX#*f=}
@@ -72,11 +76,11 @@ function make_kix {
    */leech/*~*/ )
     KIX=${KIX##*~}
     KIX=${KIX%/}
-    KIX="$(echo $KIX | sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b")"
+    KIX="$(rawurldecode "$KIX")"
     ;;
    */leech/*~* )
     KIX=${KIX##*~}
-    KIX="$(echo $KIX | sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b")"
+    KIX="$(rawurldecode "$KIX")"
     ;;
    */leech* )
     KIX=${KIX#*p=}
@@ -86,7 +90,7 @@ function make_kix {
     KIX=$(mktemp --dry-run kaoget_XXXX)
     ;;
   esac
-  KIX="$(echo $KIX | sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b")"
+  KIX="$(rawurldecode "$KIX")"
   KIX="${KIX##*/}.kix"
   echo "$KIX"
 }
@@ -117,8 +121,8 @@ case "$URL_FILE" in
     ;;
 esac
 
-sed -e 's/[[:space:]]*#.*// ; /^[[:space:]]*$/d' "$URL_FILE" |
 while read URL; do
+  URL="${URL%%#*}"
   case "$URL" in
      */dl.php*f=* )
       NAME=${URL#*f=}
@@ -126,13 +130,13 @@ while read URL; do
       ;;
      */leech/*~* )
       NAME=${URL##*~}
-      NAME=$(echo $NAME | sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b")
+      NAME="$(rawurldecode "$NAME")"
       ;;
      * )
       continue
       ;;
   esac
-  NAME=$(echo $NAME | sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b")
+  NAME="$(rawurldecode "$NAME")"
   NAME=${NAME#*/}
   NAME=${NAME#*/}
   NAME=${NAME#*/}
@@ -147,7 +151,7 @@ while read URL; do
   $GETTER $GENOPT $HTTP_AUTH $BWLIM $OUTOPT "$PNAME" "$URL$GET_AUTH"
   [ $? -ne 0 ] && exit 3
   mv "$PNAME" "$NAME"
-done
+done < "$URL_FILE"
 
 [ -n "$TMP_FILE" ] && rm -f "$TMP_FILE"
 exit 0