#!/bin/ash
targetdir='/tmp/HDD/Rapidshare/downloads/'
server='selected'
tmp=/tmp
retries=5
helpmsg()
{
echo "Aufruf: $0 [Option] [Datei|URL]"
echo "Datei(en) von rapidshare.com herunterladen"
echo
echo " -l liste - Alle Dateien aus der Textdatei <liste> (eine pro Zeile) herunterladen"
echo " -u url - Einzelne Datei herunterladen"
echo " -?, --help - Diese Hilfe anzeigen, dann beenden"
echo
}
listload() {
cat $1 | while read line; do download $line; done
}
cleanup(){
rm -f $tmp/getfile.txt $tmp/getcap.txt $tmp/form.txt $tmp/captcha.jpg
}
download() {
param=$(echo $1 |tr -d '\015')
filename=$(echo $param | sed -e 's/^.*\/files\/[0-9]*\/\(.*\)$/\1/;s/\(.*\)\.html$/\1/')
echo "===========================Download von $filename=============================="
try=0
while [ $try -lt $retries ]; do
cleanup
cat /tmp/HDD/Rapidshare/countlist.txt | while read countlist
do
echo "$countdl von $countlist geladen"
done
try=$(($try+1))
/opt/bin/wget -q -O $tmp/getfile.txt $param
url=$(sed -n 's/^.*action="\(http:\/\/rs[^"]*\)".*$/\1/p' $tmp/getfile.txt)
if [ -z "$url" ]; then
echo 'Datei gelöscht?'
continue
fi
/opt/bin/wget -q --post-data='dl.start=Free' -O $tmp/getcap.txt $url
starttime=$(date "+%s")
grep 'var c=' $tmp/getcap.txt>$tmp/form.txt
sed "1d" /tmp/form.txt>/tmp/form2.txt
waittime=$(sed -n 's/^.*var c=\([0-9]*\).*$/\1/p' /tmp/form2.txt)
echo "Warte $waitime Sekunden"
sleep $waittime
if [ $server = 'selected' ]; then
url=$(echo $(sed -n 's/^.*"\(http:\/\/rs[^"]*\)" m.*$/\1/p' $tmp/getcap.txt) | sed -n 's/^.*\(http:\/\/rs[^"]*\) h.*$/\1/p')
else
url=$(sed -n "s/^.*action=\\\'\\(http:\\/\\/rs[0-9].*$server[^'\"]*\\)\\\'.*$/\\1/p" $tmp/getcap.txt)
fi
if [ -z "$url" ]; then
echo 'Link nicht gefunden'
continue
fi
echo "Lade $filename herunter"
if /opt/bin/wget --output-file=/tmp/HDD/Rapidshare/logs/$dateiname.log -O$targetdir$filename -t 3 --progress=bar:force $url ; then
countdl=$(($countdl+1))
break
else
echo 'Fehler beim Download'
fi
done
echo >/dev/null
}
case "$1" in
-l)
if [ -n "$2" ]; then
listload $2
else
helpmsg >&2
exit 1
fi
;;
-?|--help)
helpmsg
exit 0
;;
*)
helpmsg >&2
exit 1
esac