Advertisement
Guest User

4chan grabber script

a guest
Dec 21st, 2010
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.93 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. if [ "$1" = "" ]; then
  4.         echo "Usage: `basename $0` <4chan thread url>"
  5.         exit 1
  6. fi
  7.  
  8. echo "4chan downloader"
  9. echo "Downloading until canceled or 404'd"
  10. LOC=$( echo "$1" | egrep -o '([0-9]*)$' | sed 's/\.html//g' )
  11. echo "Downloading to $LOC"
  12.  
  13. if [ ! -d $LOC ]; then
  14.         mkdir $LOC
  15. fi
  16.  
  17. cd $LOC
  18.  
  19. while [ true ]; do
  20.         TMP=`mktemp /tmp/4chan.XXXXXX`
  21.         TMP2=`mktemp /tmp/4chanm.XXXXXX`
  22.         WGET_CMD='wget -nv -nc'
  23.  
  24.         wget -O "$TMP" "$1"
  25.         if [ "$?" != "0" ]; then
  26.                 rm $TMP $TMP2
  27.                 exit 1
  28.         fi
  29.  
  30.         egrep 'http://images.4chan.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' "$TMP" -o | uniq > "$TMP2"
  31.         #cat "$TMP2" | sed 's!/cb-nws!!g' > "$TMP"
  32.  
  33.         #wget -nc -i $TMP2
  34.  
  35.         cat $TMP2 | xargs -P 5 -I _URL_ $WGET_CMD _URL_
  36.  
  37.         rm $TMP $TMP2
  38.  
  39.         echo "Waiting 30 seconds befor next run"
  40.         sleep 30
  41. done;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement