commit cbc773b157b46faaf81387c77282926aeeb7c87b parent 730caa67601b713dbbfa5b57e2a52ba29dc7ab6b Author: sin <sin@2f30.org> Date: Sat, 6 Jul 2013 15:17:04 +0100 Add multiple thread support Diffstat:
M | 4chandownload.sh | | | 29 | ++++++++++++++++++----------- |
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/4chandownload.sh b/4chandownload.sh @@ -1,18 +1,11 @@ #!/bin/sh -if [ ! $# -eq 1 ]; then - echo "Usage: $(basename $0) <4chan thread url>" +if [ $# -lt 1 ]; then + echo "Usage: $(basename $0) <4chan-thread-url...> " exit 1 fi -echo "4chan downloader" -echo "Downloading until canceled or 404'd" -loc=$(echo "$1" | egrep -o '([0-9]*)$' | sed 's/\.html//g') -mkdir -p ${loc} -cd ${loc} - -echo "Downloading to $loc" -while :; do +pullthread() { trap 'rm -f ${tmp} ${tmp2}; exit 0' 2 tmp=$(mktemp /tmp/4chan.XXXXXX) @@ -32,7 +25,21 @@ while :; do cat ${tmp} | xargs -P 5 -I _URL_ ${wget_cmd} _URL_ rm ${tmp} ${tmp2} +} +echo "4chan downloader" +echo "Downloading until canceled or 404'd" + +while :; do + for arg in "$@"; do + loc=$(echo "$arg" | egrep -o '([0-9]*)$' | sed 's/\.html//g') + mkdir -p ${loc} + cd ${loc} + + echo "Downloading to $loc" + pullthread "$arg" + cd - &>/dev/null + done echo "Waiting 30 seconds before next run" sleep 30 -done; +done