scripts

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

4chanfetch (835B)


      1 #!/bin/sh
      2 
      3 if [ $# -lt 1 ]; then
      4 	echo "Usage: $(basename $0) <4chan-thread-url...> "
      5 	exit 1
      6 fi
      7 
      8 pullthread() {
      9 	trap 'rm -f ${tmp} ${tmp2}; exit 0' 2
     10 
     11 	tmp=$(mktemp /tmp/4chan.XXXXXX)
     12 	tmp2=$(mktemp /tmp/4chanm.XXXXXX)
     13 	wget_cmd='wget -nv -nc'
     14 
     15 	wget -O ${tmp} "$1"
     16 	if [ ! $? -eq 0 ]; then
     17 		rm ${tmp} ${tmp2}
     18 		return 1
     19 	fi
     20 
     21 	egrep '//i.4cdn.org/[a-z0-9]+/([0-9]*).(jpg|png|gif|webm)' ${tmp} -o | uniq > ${tmp2}
     22 
     23 	sed 's|//i|http://i|g' ${tmp2} > ${tmp}
     24 
     25 	cat ${tmp} | xargs -P 5 -I _URL_ ${wget_cmd} _URL_
     26 
     27 	rm ${tmp} ${tmp2}
     28 
     29 	return 0
     30 }
     31 
     32 echo "4chan downloader"
     33 
     34 while :; do
     35 done=1
     36 
     37 for arg in "$@"; do
     38 	path=$(basename "$arg")
     39 	mkdir -p ${path}
     40 	cd ${path}
     41 
     42 	pullthread "$arg"
     43 	if [ $? -eq 0 ]; then
     44 done=0
     45 fi
     46 
     47 cd - &>/dev/null
     48 done
     49 
     50 if [ $done -eq 1 ]; then
     51 	exit 1
     52 fi
     53 
     54 echo "Waiting 30 seconds before next run"
     55 sleep 30
     56 done