scripts

misc scripts and tools
git clone git://git.2f30.org/scripts.git
Log | Files | Refs

commit 730caa67601b713dbbfa5b57e2a52ba29dc7ab6b
parent 43fe523e8973b53459b1710da07b725b7e51fba0
Author: sin <sin@2f30.org>
Date:   Sat Jul  6 15:09:09 +0100

Cleanup 4chandownload.sh

Diffstat:
4chandownload.sh | 32++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/4chandownload.sh b/4chandownload.sh @@ -7,31 +7,31 @@ fi echo "4chan downloader" echo "Downloading until canceled or 404'd" -LOC=$( echo "$1" | egrep -o '([0-9]*)$' | sed 's/\.html//g' ) -echo "Downloading to $LOC" +loc=$(echo "$1" | egrep -o '([0-9]*)$' | sed 's/\.html//g') +mkdir -p ${loc} +cd ${loc} -mkdir -p $LOC +echo "Downloading to $loc" +while :; do + trap 'rm -f ${tmp} ${tmp2}; exit 0' 2 -cd $LOC + tmp=$(mktemp /tmp/4chan.XXXXXX) + tmp2=$(mktemp /tmp/4chanm.XXXXXX) + wget_cmd='wget -nv -nc' -while [ true ]; do - TMP=`mktemp /tmp/4chan.XXXXXX` - TMP2=`mktemp /tmp/4chanm.XXXXXX` - WGET_CMD='wget -nv -nc' - - wget -O "$TMP" "$1" - if [ "$?" != "0" ]; then - rm $TMP $TMP2 + wget -O ${tmp} "$1" + if [ ! $? -eq 0 ]; then + rm ${tmp} ${tmp2} exit 1 fi - egrep '//images.4chan.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' "$TMP" -o | uniq > "$TMP2" + egrep '//images.4chan.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' ${tmp} -o | uniq > ${tmp2} - sed 's|//images|http://images|g' $TMP2 > $TMP + sed 's|//images|http://images|g' ${tmp2} > ${tmp} - cat $TMP | xargs -P 5 -I _URL_ $WGET_CMD _URL_ + cat ${tmp} | xargs -P 5 -I _URL_ ${wget_cmd} _URL_ - rm $TMP $TMP2 + rm ${tmp} ${tmp2} echo "Waiting 30 seconds before next run" sleep 30