1
uploader_tools/massdl.sh
2012-04-02 23:07:16 +04:00

115 lines
5.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# For NNM-Club Uploaders
# Copyright (c) 2012 Valdos Sine <fat0troll at yandex dot ru>
#
# Usage:
#
# ./massdl.sh [mode] [forum]
#
# For getting help, execute ./massdl.sh without params
TMPDIR=`mktemp -d`
CURDIR=`pwd`
LOG_FILE="`date +%s`-massdl.log"
# Heading log file
cat > $LOG_FILE << EOF
================================================================================
= Скрипт скачки раздела NNM-Club для Linux и Unix-like ОС. =
= Построен на технологиях GNU. =
Дата запуска: `date`.
================================================================================
EOF
wget_func () {
# Wget helper, which makes many wget usages more stable
# Usage wget_func [path_to_redirect] [anything (wget params, such as -O...)]
wget -t 99 --wait=1 --post-data="username=$USERNAME&password=$PASSWORD&autologin=on&login=%C2%F5%EE%E4&redirect=${1}" "http://nnm-club.me/forum/login.php" ${2} -a $CURDIR/$LOG_FILE
}
# Checking if we have parameter, otherwise show help in Russian
if [[ ${@} == "" ]] ; then
echo "massdl.sh — скрипт для пакетной загрузки торрент-файлов из разделов nnm-club.me."
echo "Использование:"
echo -ne "\n\t./massdl.sh [режим] [номер_раздела]\n\n"
echo "где [режим] это режим загрузки (от имени пользователя, указанного в конфигурации скрипта — значение user, или же от имени фрилич-пользователя — значение freeleech), аомерорума] — номер раздела на nnm-club.me (например, для форума '*Nix Игры' это 316)."
echo -ne "Примеры:\n\n\t./massdl.sh freeleech 316 — скачивание форума '*Nix Игры' от фрилич-пользователя\n\t./massdl.sh user 332 — скачивание форума 'Русский рок' от собственного, указанного в скрипте, имени\n\n"
echo "Автор: Valdos 'fat0troll' Sine."
echo "Основано на технологиях GNU."
echo "Версия 0.3"
exit 0
else
echo "Выполняется скрипт ${0}."
echo "Строка параметров работы: ${@}."
echo -ne "Проводим разбор строки..."
# Script configuration
case "x${1}" in
"xuser" )
# TYPE YOUR USERNAME AND PASSWORD HERE!
USERNAME=user
PASSWORD=password
echo -ne "пользователь $USERNAME"
;;
"xfreeleech" )
# Freeleech user credentials
USERNAME=freeleech_user
PASSWORD=freeleech_password
echo -ne "фрилич"
;;
* )
# ERROR!
echo -ne "ошибка, неправильный режим работы скрипта! Разрешённые режимы — freeleech или же user.\nЗавершение...\n"
exit 1
;;
esac
FORUM=${2}
echo -ne ", номер форума ${FORUM}.\n"
echo "Начинаем работу..."
fi
# Downloading main page of the selected forum
wget_func `echo 'viewforum.php?f='$FORUM` "-O $TMPDIR/page0.html"
FORUMNAME=`cat $TMPDIR/page0.html | iconv -f cp1251 -t utf-8 | grep maintitle | cut -d '>' -f 4 | cut -d '<' -f 1 | sed 's/\//_/g'`
echo "Скачиваем форум \"${FORUMNAME}\"..."
ITERATOR=0
THREADS=0
# Downloading all pages
while [ `cat $TMPDIR/page$ITERATOR.html | iconv -f cp1251 -t utf-8 | grep "След."| grep 'start' | wc -l` == "2" ]
do
iconv -f cp1251 -t utf-8 $TMPDIR/page$ITERATOR.html > $TMPDIR/page$ITERATOR.utf8.html
cat $TMPDIR/page$ITERATOR.utf8.html | grep topictitle | sed 's/.*<a href=\([^>]*\).*/\1/' | cut -d '"' -f 2 >> $TMPDIR/alllinkz.txt
THREADS=$(($THREADS + 50))
ITERATOR=$(($ITERATOR + 1))
START=$(($ITERATOR * 50))
echo "Скачиваем страницу $((${ITERATOR} + 1))..."
wget_func `echo 'viewforum.php?f='$FORUM'%26start='$START` "-O $TMPDIR/page$ITERATOR.html"
done
# Last loop ending :)
iconv -f cp1251 -t utf-8 $TMPDIR/page$ITERATOR.html > $TMPDIR/page$ITERATOR.utf8.html
cat $TMPDIR/page$ITERATOR.utf8.html | grep topictitle | sed 's/.*<a href=\([^>]*\).*/\1/' | cut -d '"' -f 2 >> $TMPDIR/alllinkz.txt
# You can use it as statistic :)
THREADS=$(($THREADS + `cat $TMPDIR/page$ITERATOR.html | grep topictitle | wc -l`))
echo -ne "Выявлено $THREADS топиков, содержащих торренты! Скачиваем...\n"
# And this is what we need -- getting threads and torrents!
# Torrents will be saved in folders like 100, 200, 300... Every folder contains
# 100 torrents (except the last one).
THREAD=0
mkdir "$FORUMNAME"
while read line
do
pushd "${FORUMNAME}" >> /dev/null
mkdir "$(($THREAD / 100))" 2>> /dev/null
THREAD=$(($THREAD + 1))
echo -ne "Скачиваем торрент $THREAD/$THREADS."
# Temporary solution until will be finded way to use cookie.txt...
wget_func $line "-O $TMPDIR/out_$THREAD.html"
echo -ne "."
wget_func `cat $TMPDIR/out_$THREAD.html | iconv -f cp1251 -t utf-8 | grep download.php | sed 's/.*<a href=\([^>]*\).*/\1/' | cut -d '"' -f 2` "-P "$(($THREAD / 100))/" --content-disposition"
echo -ne ".\n"
popd >> /dev/null
done < $TMPDIR/alllinkz.txt
# Cleaning up...
rm -r $TMPDIR