Skip to content

Instantly share code, notes, and snippets.

@ssz66666
Last active December 3, 2019 22:30
Show Gist options
  • Save ssz66666/d54447c06404cd8dda387b4eabd2ce63 to your computer and use it in GitHub Desktop.
Save ssz66666/d54447c06404cd8dda387b4eabd2ce63 to your computer and use it in GitHub Desktop.
Download http directory with aria2c
#!/bin/sh
if [ -z ${1+x} ]; then echo "URL must be specified!" && exit -1; fi
URL=$1
ARGS="${@:2}"
PARENT=$(dirname $URL)/
PARENT_ESCAPED="${PARENT//\//\\\/}"
wget -e robots=off -r -np -nH -nd --spider $ARGS $URL 2>&1 | \
grep -o "$URL\([^/]*/\)*[^/?][^/]*$" | \
sed 's/\(^'$PARENT_ESCAPED'\)\(.\+\)/\1\2\n\ \ out=\2/g' | \
python3 -c'import urllib.parse,sys;[print(" out="+urllib.parse.unquote(s[6:]), end="") if s.startswith(" out=") else print(s, end="") for s in sys.stdin]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment