#!/bin/bash
#Ripping of UseMyComputer.com
#set -x
#Rip UseMyComputer.com {{{
BASE_URL=http://usemycomputer.com
URL=$BASE_URL/archive					# The start URL
DIR=/home/houghi/Pictures/to_work_on/download/rip	# Where to put it all
YEAR=`date -d yesterday +%G`				# Yesterday's year
MONTH=`date -d yesterday +%m|bc`			# Yesterday's month
DAY=`date -d yesterday +%d|bc`				# Yesterday
DATE=$YEAR-$MONTH-$DAY.html				# All together with the URL
COUNTER=0
TMP=/tmp/UseMyComputer.com

lynx -source $URL/$DATE > $TMP
perl -p -i -e "s/>/>\n/g;" $TMP
# /* }}} */
#Get pics from the first page {{{
GET_PAGE ()
{
	lynx -dump $URL/$DATE|grep \.jpg|awk '{print $2}' > $TMP
	for PIC in `cat $TMP|sed 's#show.html?.*=/##'|grep http`
	do
		EXTRA="`date +%Y%m%d`_`printf %04d $COUNTER`"
		NAME=`basename $PIC`
		wget -q -O $DIR/$NAME $PIC
		let COUNTER=COUNTER+1
	done
}
# }}}
#Get the dictory pics {{{
GET_INDEX ()
{
for FILE in `grep href=\"/indeximages/women $TMP|awk -F\" '{print $2}'`
do
        PERSON=`basename $FILE |sed -e 's/\./_/g'`
        for PIC in `lynx -dump $BASE_URL$FILE |grep \.jpg|awk '{print $NF}'|sed 's#show.html?.*=/##'`
        do
                NAME="${PERSON}_`date +%Y%m%d`_`printf %04d $COUNTER`.jpg"
                wget -q -O $DIR/$NAME $PIC
                let COUNTER=COUNTER+1
        done
done
}
#}}}
#Get the pictures {{{
GET_PICS ()
{
for FILE in `grep jpg $TMP|awk -F\" '{print $6}'|grep show.html|awk -F= '{print $NF}'`
do
	NAME=`basename $FILE`				# The filename
	wget -q -O $DIR/$NAME $BASE_URL$FILE		# Get the file
#	echo $NAME					# Show what it got
	let COUNTER=COUNTER+1
done
}
#}}}
#Imagehaven {{{
IMAGEHAVEN ()
{
        for URL_LINK in `grep imagehaven.net $TMP|awk '{print $NF}'`
        do
		IMAGE1=`echo $URL_LINK|awk -F\/ '{print $3}'`
		IMAGE2=`lynx -source $URL_LINK|grep skalieren|grep images|awk -F\. '{print $2}'`
		IMAGE="http://${IMAGE1}/${IMAGE2}"
                NAME="${PERSON}_`date +%Y%m%d`_`printf %04d $COUNTER`.jpg"
                wget -q -O $DIR/$NAME $IMAGE
                let COUNTER=COUNTER+1
        done
}
#}}}za
#Imagevenue {{{
IMAGEVENUE ()
{
        for URL_LINK in `grep imagevenue.com $TMP|awk '{print $NF}'`
        do
                SITE=`echo "$URL_LINK"|awk -F\/ '{print "http://" $3}'`
                LINK=`lynx -source "$URL_LINK"|grep SRC|grep -i .jpg|awk -F\" '{print $8}'`
                FILE=$SITE/$LINK
                NAME="${PERSON}_`date +%Y%m%d`_`printf %04d $COUNTER`.jpg"
                wget -q -O $DIR/$NAME $FILE
                let COUNTER=COUNTER+1
        done
}
#}}}
#imagepal.info {{{
IMAGEPAL ()
{
        for URL_LINK in `grep imagepal.info $TMP|awk '{print $NF}'|sed -e "s/.jpg.php/.jpg/g"`
        do
                NAME="${PERSON}_`date +%Y%m%d`_`printf %04d $COUNTER`.jpg"
                wget -q -O $DIR/$NAME $URL_LINK
                let COUNTER=COUNTER+1
        done
}
# /* }}} */
#Usemycomputer {{{
USE_MY_COMPUTER ()
{
        for URL_LINK in `grep http://usemycomputer.com/show.html $TMP|awk -F= '{print $NF}'`
        do
                PERSON=`echo $URL_LINK|awk -F\/ '{print $4}'|sed -e 's/\./_/g'`
                NAME="${PERSON}_`date +%Y%m%d`_`printf %04d $COUNTER`.jpg"
                wget -q -O $DIR/$NAME http://usemycomputer.com/$URL_LINK
                let COUNTER=COUNTER+1
        done
}
# /* }}} */
#Uppix {{{
UPPIX ()
{
	for URL_LINK  in `lynx -dump ${URL}${COUNT}.0|grep uppix|awk '{print $NF}'|awk -F= '{print $NF}'`
	do
		NAME="${PERSON}_`date +%Y%m%d`_`printf %04d $COUNTER`.jpg"
		wget -q -O $DIR/$NAME http://www.uppix.info/Pics/${URL_LINK}
		let COUNTER=COUNTER+1
	done
}
#}}}
#Uploadpix {{{
UPLOADPICS ()
{
	for URL_LINK in `grep uploadpics.info $TMP|awk '{print $NF}'|sed -e "s#.php?id=#/#g"`
	do
		NAME="${PERSON}_`date +%Y%m%d`_`printf %04d $COUNTER`.jpg"
		wget -q -O $DIR/$NAME $URL_LINK
		let COUNTER=COUNTER+1
	done
} #}}}
#Get the forum pics {{{
GET_FORUM ()
{
	DIR=/home/houghi/Pictures/to_work_on/download/umc_forum
	. ~/.usemycomputer.com
BASE="http://forum.usemycomputer.com/index.php?board=6.0"
URL="http://forum.usemycomputer.com/index.php?topic="
MAX=`lynx -dump $BASE|grep topic|grep -v new|awk -F= '{print $NF}'|awk -F. '{print $1}'|sort -n|tail -n 1`
for COUNT in `seq $MIN $MAX`
do
	lynx -dump ${URL}${COUNT}.0 > $TMP
	PERSON=`grep "Author Topic:" $TMP| awk -F": " '{print $NF}'| \
	awk -F- '{print $1}'| \
	awk -F"|" '{print $1}'| \
	awk -F"(" '{print $1}'| \
	perl -p -i -e 's/ /_/g'`
	#The image sites
	IMAGEHAVEN
	IMAGEVENUE
	IMAGEPAL
	USE_MY_COMPUTER
	UPPIX
	#UPLOADPICS
done
cat > ~/.usemycomputer.com <<-ENDOFMESSAGE
MIN=$MAX
ENDOFMESSAGE
cd $DIR

/usr/local/bin/blank-rename.sh
/usr/local/bin/lowercase
}
#}}}
GET_PAGE
GET_INDEX
GET_PICS
#GET_FORUM

echo "$COUNTER pics downloaded from UseMyComputer.com with `basename $0`"

