Advertisement
liliff

Untitled

Apr 5th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.85 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ -z "$1" ]; then
  4.   echo "Please give me the initial URI so I know where to start from."
  5.   exit 1
  6. fi
  7.  
  8. init=$1
  9.  
  10. album=$(echo $init | cut -d/ -f6 | cut -d- -f1)
  11. start=$(echo $init | cut -d/ -f6 | cut -d- -f2)
  12. baseurl=$(echo $init | cut -d/ -f3)
  13.                      
  14. mkdir -p $album/pages        
  15. wget -nc -P $album/pages $init    
  16. sed -i "s/>/>\n/g" $album/pages/$album-$start
  17. total=$(grep -B1 -m1 -P "http://.*org/img/l.png" $album/pages/$album-$start| grep -oP "(?<=href=\").*(?=\")" | cut -d/ -f6 | cut -d- -f2)
  18. nextpage=$(grep -m1 -oP "http://$baseurl/.*$album-$((start + 1))" $album/pages/$album-$start)
  19. wget -nc -P $album $(grep -oP "http://([0-9]{1,3}\.){3}[0-9]{1,3}.*\.(jpg|png|gif)" $album/pages/$album-$start | sed "s/\&amp;/\&/g")
  20.                              
  21. for i in $(seq $start $total)
  22. do                                  
  23.   wget -nc -P $album/pages $nextpage    
  24.   until [ $(grep 'You are opening pages too fast, thus placing a heavy load on the server.' $album/pages/$album-$i | wc -l) -eq 0 ]
  25. #  until [ $blocked -eq 0 ]
  26.   do                                    
  27.     echo "Received warning from server. Sleeping for 30 seconds."
  28.     sleep 30    
  29.     needrefresh=1
  30.   done                          
  31.   if [ ! -z $needrefresh ]; then
  32.     rm -vf $album/pages/$album-$i
  33.     wget -P $album/pages $nextpage
  34.     unset needrefresh
  35.   fi                                    
  36.   sed -i "s/>/>\n/g" $album/pages/$album-$i
  37.   nextpage=$(grep -m1 -oP "http://$baseurl/.*$album-$((i + 1))" $album/pages/$album-$i)
  38.   wget -nc -P $album $(grep -oP "http://([0-9]{1,3}\.){3}[0-9]{1,3}.*\.(jpg|png|gif)" $album/pages/$album-$i | sed "s/\&amp;/\&/g")
  39.   sleep 2
  40. #  echo image = $(grep -oP "http://([0-9]{1,3}\.){3}[0-9]{1,3}.*\.jpg" $album/pages/$album-$i)
  41. done
  42.  
  43. du -h $album
  44. echo $(find $album -maxdepth 1 -name "*.jpg" | wc -l) images exist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement