###################################################################### # Downloads webshots.com user created photo albums. Requires cookie # information of the user saved by webshots.com. The cookie files are # stored in browser's configuration directory. Only albums marked for # private viewing are possible to download. if required, otherwise, # change the script accordingly # # Copyright (C) 2007 Srivatsa Kanchi, R # License: GPL # ##################################################################### if (( $# != 2 )); then echo -e "Usage: \n \t/bin/bash $0 \n" exit 1 fi user="$1" cookie_file="$2" tmpfile1=`mktemp /tmp/temp.XXXXXXXXXX` || exit 1 tmpfile2=`mktemp /tmp/temp.XXXXXXXXXX` || exit 1 i=1 wget -o /dev/null -O- --load-cookies "$cookie_file" \ "http://community.webshots.com/user/${user}/albums/most-recent" | \ grep -iE -A1 "" | \ grep -ioE "" | \ sed -re 's/^\s*<\s*a\s+href="([^"]+)"\s+title="([^"]+)".*<\/a>/\1 \2/i' \ -e 's/^\s*<\s*a\s+href="([^"]+)".*>(.+)<\/a>/\1 \2/i' \ -e "s/'/'/" > $tmpfile1 echo -e "\nInput an album number; 0 to exit" cat $tmpfile1 | cut -d ' ' -f2- | while read; do echo " $((i++)) $REPLY" done read -p "? " i if [[ $i < 1 || $i > `wc -l "$tmpfile1"` ]]; then if (( $i != 0 )); then echo "Invalid album number entered"; fi rm -f "$tmpfile1" "$tmpfile2" exit 0 fi album=`head -n $i $tmpfile1 | tail -n 1 | cut -d ' ' -f2-` temp=`head -n $i $tmpfile1 | tail -n 1 | cut -d ' ' -f1` base_url=`echo $temp | grep -ioE "http://.+\.com"` url=`echo $temp | sed -re 's/.+\.com(.+)/\1/i'` echo -e "\nCollecting photos for album: \"${album}\"" echo -n "Searching in page:" i=1 while (( !$? )); do echo " $((i++)) : ${url}" wget -o /dev/null -O "$tmpfile1" --load-cookies "$cookie_file" \ "${base_url}${url}" grep -iE "^\s*" "$tmpfile1" | \ grep -ioE "http[^\"]+" | while read; do wget -o /dev/null -O- --load-cookies "$cookie_file" "$REPLY" | \ grep -m 1 -iE \ "^\s*
  • > "$tmpfile2" done url=`grep -m 1 -iE "rel=\"next\"\s+class=\"next\">next" $tmpfile1 | \ grep -ioE "/album[^\"]+"` done cat "$tmpfile2" | sort | uniq > "$tmpfile1" if (( `du -b "$tmpfile1" | cut -f1` )); then echo -e "\nDownloading `wc -l \"$tmpfile1\" | cut -d ' ' -f1` photos" wget -nv -N -P "./${album}" -i "$tmpfile1" --load-cookies "$cookie_file" else echo -e "\nAborted!" fi rm -f "$tmpfile1" "$tmpfile2"