úterý 12. října 2010

Jak stahovat z Ulož.to pomocí asuse?

Nejprve je nutné nainstalovat tyto balíčky: bash 3.2-2 a wget 1.12-2
například takto:
opkg update
opkg install bash
opkg install wget
potom si stačí stáhnout tento skript ZDE
cd /opt/Download
wget http://svetylk0.masquerade.cz/wdownload.sh
chmod 777 wdownload.sh
no a nyní stačí zakomentovat řádek display captcha.png &, tedy #display captcha.png &
obrázek s captchou je nutné nejprve stáhnout pomocí ftp a potom zadat do příkazové řádky
Až bude čas, tak se pokusím o nějaké naroubování toho na webové rozhraní routeru.

Skript je potom možné spustit takto
/opt/Download/wdownload.sh <adresa na uloz.to>


#!/bin/bash

# Download files from uloz.to using wget
# Author: svetylk0 (svetylk0 at seznam dot cz)
# Version: 1.0.3

VER="1.0.3"
DESTDIR="downloads"

function captcha() {

echo "Downloading captcha image ..."
wget -q "$URL" -O captcha.htm
CAPTCHA_ID=`grep class=\"captcha_nb captcha.htm | head -n 1 | grep -Eo [0-9]+`
CAPTCHA_IMG=`grep -Eo "http.+$CAPTCHA_ID\.png" captcha.htm | head -n 1`

echo $CAPTCHA_ID > CAPTCHAID

wget -q "$CAPTCHA_IMG" -O captcha.png

#display it
#display captcha.png &

echo "Enter captcha text:"
read TEXT
echo $TEXT > TEXT

}

function notify() {
#notify page and also because of form_url update
echo "Notifying page for download ..."
wget -q "$URL" -O captcha.htm
}

if ! [ -e $DESTDIR ]; then

if ! mkdir $DESTDIR; then
echo "Failed to create destination directory: $DESTDIR"
exit
fi

fi

#parse parameters

LNUM="unlimited"
LIMIT=""

while [ -n "$1" ]; do

case $1 in

-l )
shift
LIMIT="--limit-rate="$1"k"
LNUM="$1 kB/s"
shift;;

*uloz* )
URL="$1"
shift;;

* )
shift;;

esac


done

FILE=`echo "$URL" | tr '/' '\n' | tail -n 1`
DESTDIR="downloads"

TIMEOUT=30

echo
echo "Wget uloz.to downloader version $VER"
echo
echo "URL: $URL"
echo "File: $FILE"
echo "Destination directory: $DESTDIR"
echo
echo "Download limit: $LNUM"

if [ -e TEXT ]; then

echo "Use last captcha? [Y/n]"
read IN

if [ "$IN" = n ]; then
captcha;
else

notify;

CAPTCHA_ID=`cat CAPTCHAID`
TEXT=`cat TEXT`

fi

else

captcha;

fi

DOWNLOAD="Ståhnout FREE"
FORM_URL=`grep name=\"dwn\" captcha.htm | grep -Eo "http.+\" " | sed s/"\" metho                                                                                                                                                             d=\"post\""/""/`
OUTPUT="$DESTDIR/$FILE"


#start download

while [ true ]; do

#downloaded size checking
if [ -e "$OUTPUT" ]; then

SIZE=`du -h "$OUTPUT" | grep -oE "^[0-9]+"`

else

SIZE=0

fi


if ! wget -c "$LIMIT" --timeout 30 --tries 0 --retry-connrefused --post-data "ca                                                                                                                                                             ptcha_nb=$CAPTCHA_ID&captcha_user=$TEXT&download=$DOWNLOAD" "$FORM_URL" -O "$OUT                                                                                                                                                             PUT"; then

echo "Error occured, retrying after $TIMEOUT""s"
sleep $TIMEOUT
continue

fi

echo "Verifying downloaded file ..."

#check if is HTML file
if [ -e "$OUTPUT" ]; then

if file "$OUTPUT" | grep -q HTML; then
echo "Something went wrong, trying again ... after $TIMEOUT""s"
rm "$OUTPUT"
sleep $TIMEOUT

notify;

continue

fi

#test size
NEWSIZE=`du -h "$OUTPUT" | grep -oE "^[0-9]+"`
if [ "$NEWSIZE" = "$SIZE" ]; then

echo "Size is same as before download. Which means that nothing has been downloa                                                                                                                                                             ded"
echo "(wrong CAPTCHA or no free slots?)."
echo
echo " Retrying after $TIMEOUT""s"
echo
echo "Note: If you see above wget saying that file is complete, you have to"
echo "terminate this process by pressing CTRL+c"

sleep $TIMEOUT

notify;

continue

fi


fi

break
done

echo "OK"

3 komentáře:

  1. Šlo by sem pastnout obsah wdownload.sh? Je nedostupný...

    OdpovědětSmazat
  2. Zdravím, soubor jsem přdal. Bohužel po změnách na ULOŽTu nebude asi příliš použitelný.

    OdpovědětSmazat