#!/bin/sh
#
# Version 0.0.0 Sep 2007
# Version 0.0.1 Sep 2008
#
# Script to download files from esay-share.
# Requires application to display png files. Edit DISPLAYAPP
# Requires shell with job control (POSIX sh, bash, ksh)
# Requires wget with "--post-data" option (tested with wget 1.10.x)
# Requires "htd". Otherwise, uncomment htd() definition below
#
# Current status: not working (Mar 2011)
#
# Defaults:
#
PATH=/bin:/usr/bin:/bin:/usr/X11R6/bin:/sbin:/usr/sbin:/usr/etc:/usr/local/bin
PATH=$PATH:/usr/sfw/bin:/opt/sfw/bin
LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH
PATH=$PATH:/usr/local/bin/X11
export PATH
# DISPLAYAPP file.png
#DISPLAYAPP=xv
DISPLAYAPP=display
VERBOSE=-nv
if type $DISPLAYAPP > /dev/null 2>&1
then
:
else
DISPLAYAPP=display
fi
htd()
{
perl -pe 's/\%([A-Fa-f0-9]{2})/pack("C", hex($1))/seg;'
}
#
#
#
NODEBUG=echo
#NODEBUG=:
ECHO="echo"
case `uname` in
Darwin*|Linux*)
ECHO="echo -e"
;;
*)
[ -x /usr/ucb/echo ] && ECHO="/usr/ucb/echo"
;;
esac
SED=sed
if [ -x /usr/local/bin/sed ]
then
SED=/usr/local/bin/sed
fi
trap "on_exit" 1 2 3 15
TMPHTML=./foo.$$.html
TMPDECO=./foo.d.$$.html
TMPPNG=./foo.$$.png
COOKIES=./cookies.$$.txt
COOK="--keep-session-cookies --save-cookies $COOKIES --load-cookies $COOKIES"
on_exit()
{
rm -f $TMPHTML $TMPDECO $TMPPNG $COOKIES
date
exit
}
for f in $TMPHTML $TMPDECO $TMPPNG $COOKIES
do
test -f $f && (echo Please, delete $f first; exit 1)
done
touch $COOKIES
URL="$1"
if [ -z "$URL" ]
then
echo "Please, input URL"
read URL
fi
if [ -z "$URL" ]
then
echo use: $0 http://w14.easy-share.com/file.html
exit 1
fi
FILE=`basename $URL|$SED -e 's/\.html//'`
BASE=`echo "$URL" | $SED -e 's,/[^/]*$,,'`
seconds=""
tries="1"
while [ "_$seconds" = "_" -a $tries -lt 5 ]
do
wget $COOK $VERBOSE -O - "$URL" > $TMPHTML
seconds=`$SED -e '/^[ ]* w=/!d' -e '/^[ ]* w=/s/^[ ]* w=.//' -e "s/';$//" $TMPHTML`
echo "#### Seconds: $seconds"
uri=`$SED -e '/^[ ]* u=/!d' -e '/^[ ]* u=/s/^[ ]* u=.//' -e "s/';$//" $TMPHTML | htd`
echo "#### URI: $uri"
filename=`$SED -e '/
/!d' -e '//s/.*Download //' -e 's/, upload.*//' $TMPHTML | htd`
echo "#### filename: $filename"
tries=`expr $tries + 1`
done
if [ "_$seconds" = "_" ]
then
echo "Failed to get initial page"
exit 1
fi
echo "# Waiting $seconds seconds"
sleep 1
echo "--------------------|---------------------------------------"
SLEEP=`echo "$seconds 75 / 1 + p" | dc`
z=0
while [ $z -lt $seconds ]
do
sleep $SLEEP
$ECHO -n "."
z=`expr $z + $SLEEP`
done
echo
#uri="$uri""-A1-R0.50594834037"$$
HEADER="If-Modified-Since: Sat, 1 Jan 2000 00:00:00 GMT"
wget $COOK $VERBOSE -O - \
--user-agent=Mozilla/5.0 \
--header="$HEADER" \
"$BASE""$uri" | htd > $TMPHTML
#
#
png=`$SED -e '/kaptcha/!d' -e 's/^.*$//' $TMPHTML`
form=`$SED -e '/^[ ]* $TMPPNG
$DISPLAYAPP $TMPPNG &
JOB=$!
$ECHO -n "captcha? "
read captcha
kill $JOB
code_close="$captcha"
echo "#### code_close = \"$code_close\""
echo "#### form = \"$form\""
echo "#### referer = \"$referer\""
echo "#### filename = \"$filename\""
# cp $TMPHTML es-debug.html
echo "#### " wget $COOK $VERBOSE -O - \
--user-agent=Mozilla/5.0 \
--referer=$referer \
--post-data="captcha=$code_close&id=$id" \
"$form" \> "$filename"
wget $COOK $VERBOSE -O - \
--user-agent=Mozilla/5.0 \
--referer=$referer \
--post-data="captcha=$code_close&id=$id" \
"$form" > "$filename"
ls -ltr | tail
ls -l "$filename"
FILETYPE=`file "$filename"`
echo "#### FILETYPE = \"$FILETYPE\""
if echo "$FILETYPE" | fgrep -i html
then
NOTDONE=:
else
NOTDONE=false
fi
while $NOTDONE
do
mv "$filename" $TMPHTML
# cp $TMPHTML es-debug.html
png=`$SED -e '/kaptcha/!d' -e 's/^.*$//' $TMPHTML`
form=`$SED -e '/^[ ]* $TMPPNG
$DISPLAYAPP $TMPPNG &
JOB=$!
$ECHO -n "captcha? "
read captcha
kill $JOB
code_close="$captcha"
echo "#### code_close = \"$code_close\""
echo "#### form = \"$form\""
echo "#### referer = \"$referer\""
echo "#### filename = \"$filename\""
echo wget $COOK $VERBOSE -O - \
--user-agent=Mozilla/5.0 \
--referer=$referer \
--post-data="id=$id&captcha=$code_close" \
"$form" \> $filename
wget $COOK $VERBOSE -O - \
--user-agent=Mozilla/5.0 \
--referer=$referer \
--post-data="id=$id&captcha=$code_close" \
"$form" > $filename
ls -ltr | tail
ls -l "$filename"
FILETYPE=`file "$filename"`
echo "#### FILETYPE = \"$FILETYPE\""
if echo "$FILETYPE" | fgrep -i html
then
NOTDONE=:
else
NOTDONE=false
fi
done
on_exit
exit