#plugin: get direct link from http://letitbit.net
# by Serg0
#unofficial mod 05.03.2011
#Download Engine
TEMP_HTML="${TEMPDIR}dlengine.temp.html"
MAX_pTRY=5 # число попыток получить прямую ссылку
pTry=0
while [ $pTry -lt $MAX_pTRY ]; do
pTry=$(($pTry+1))
# --------------------------
log "-- Step.1: (try.$pTry)"
# скачаем 1-ю страницу
$WGETBIN "$1" -O "$TEMP_HTML" --save-cookies="$TEMP_HTML.cookies" --keep-session-cookies --quiet
error=$? # wget.error ?
if [ "$error" != "0" ] ; then log "FAILED: wget.error=$error"; return $RC_FAIL; fi
# Requested file is not found Smyvajsya.rar
if grep -iq "file is not found" "$TEMP_HTML" ; then log "FAILED: this file not found"; return $RC_FAIL; fi
# поищем url2
#
uid5=$( sed -n '/
uid=$( sed -n '/
name=$( sed -n '/
pin=$( sed -n '/
realuid=$( sed -n '/
realname=$( sed -n '/
host=$( sed -n '/
ssserver=$( sed -n '/
sssize=$( sed -n '/
dir=$( sed -n '/
optiondir=$( sed -n '/
#ref_rem=$( sed -n '/
lsarrserverra=$( sed -n '/
md5crypt=$( sed -n '/
url=$( sed -n 's/^.*60 seconds
wait=$( sed -n 's/^.*]*>\([0-9]*\)<.*$/\1/p' "$TEMP_HTML" )
# wait не нашли?
if [ "$wait" = "" ] ; then log "FAILED: Wait seconds - not found"; return $RC_FAIL; fi
log "waiting $wait sec : Wait your turn $wait seconds"
sleep $wait # ждем XX секунд
# составим url4 самостоятельно
# $.post("/ajax/download3.php",...
url="${cur_server}/ajax/download3.php"
# --------------------------
log "-- Step.4:"
# скачаем 4-ю страницу
$WGETBIN "$url" -O "$TEMP_HTML" --post-data="" --load-cookies="$TEMP_HTML.cookies" --quiet
error=$? # wget.error ?
if [ "$error" != "0" ] ; then log "FAILED: wget.error=$error"; return $RC_FAIL; fi
# здесь только сама прямая ссылка
url=$( head -n1 "$TEMP_HTML" )
# это http-ссылка?
if ! echo "$url" | grep -iq '^http://' ; then log "FAILED: Bad direct URL. Try again"; continue; fi
# ПРЯМАЯ ССЫЛКА ПОЛУЧЕНА
DLE_LINK=$url
rm "$TEMP_HTML.cookies" 2>/dev/null
return $RC_OK
done # while pTry