echo "test"
in=input.txt
timer()
{
TIME=${1:-960}
/bin/echo -ne "${2:-""}\033[s"
for i in `seq $TIME -1 1`; do
/bin/echo -ne "\033[u $(printf "%02d" `expr $i / 60`)m$(printf "%02d" `expr $i % 60`)s ${3:-""}"
sleep 1
done
/bin/echo -ne "\033[u 00m00s"
echo
}
while [ `wc -l $in | cut -d " " -f 1` != 0 ]; do
read line < $in
URL=$(wget -q -O - $line | grep "<form id=\"ff\" action=\"" | grep -o 'http://[^"]*');
output=$(wget -q -O - --post-data "dl.start=Free" "$URL");
serverbusy=$(echo "$output" | egrep "Currently a lot of users are downloading files. Please try again in.*minutes" | grep -o "[0-9]*")
if [ "$serverbusy" != "" ]; then
timer `expr $serverbusy '*' 60` "Сервер занят. Ожидаем." "перед переподключением..."
continue;
fi
longtime=$(echo "$output" | egrep "Or try again in about.*minutes" | egrep -o "[0-9]*")
if [ "$longtime" != "" ]; then
timer `expr '(' $longtime + 1 ')' '*' 60` "Подождём." "(лимит для бесплатного пользователя) ..."
URL=$(wget -q -O - $line | grep "<form id=\"ff\" action=\"" | grep -o 'http://[^"]*');
output=$(wget -q -O - --post-data "dl.start=Free" "$URL");
fi
time=$(echo "$output" | grep "var c=[0-9]*;" | grep -o "[0-9]\{1,3\}");
time=$(echo "$time" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [ "$time" = "" ]; then
echo "Загрузка \"`basename "$line"`\" не удалась".
echo $line >> fail.txt
sed -i '1 d' $in;
continue
fi
ourfile=$(echo "$output" | grep "document.dlf.action=" | grep checked | grep -o "http://[^\\]*");
timer $time "Ожидание" "загрузки файла `basename "$ourfile"`";
if ! wget -c $ourfile; then
echo 'Загрузка не удалась. Похоже на проблемы со стороны сервера.'
else
sed -i '1 d' $in;
fi
done
if [ -e fail.txt ]; then
mv fail.txt $in
fi