#!/bin/bash
# first known torrent
first=31630
# last known torrent
last=300000
i=$first
while [ $i -le $last ] 
do  
wget -T 10 --retry-connrefused --random-wait -U "Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" -O "work.html" "http://www.nyaa.eu/?page=torrentinfo&tid=$i"
id=$i
seed=`cat work.html | grep -o -m1 -E 'tinfosn">[^[:space:]]*</span' | sed -e 's/tinfosn">//' | sed -e 's/<\/span//'`
leech=`cat work.html | grep -o -m1 -E 'tinfoln">[^[:space:]]*</span' | sed -e 's/tinfoln">//' | sed -e 's/<\/span//'`
name=`cat work.html | grep -o -E '<title>[^[:space:]].*</title>' | sed -e 's/<title>NyaaTorrents &gt;&gt; Torrent Information &gt;&gt; //' | sed -e 's/ | Anime, manga, and music - Just say the word<\/title>//' | sed -e "s/\"/”/" | sed -e "s/'/”/" | sed -e "s/&/ and /" | sed -e "s/amp;//"`
if [ "$seed" = "0" ]; then
# comment this 2 lines to deactivate indexing of torrents without seeds
 wget -O work.html --spider "http://www.yoursite.com/magnetik/add.php?p=password&id=$id&s=$seed&l=$leech&n=$name"
 echo "$i" >> id.txt
# uncomment this line to put torrent ids without seeds in separate file
# echo "$i" >> id_noseed.txt
else
 wget -O work.html --spider "http://www.yoursite.com/magnetik/add.php?p=password&id=$id&s=$seed&l=$leech&n=$name"
 echo "$i" >> id.txt
fi
rm "work.html"
let i=1+$i
done
