#!/bin/sh # # Copyleft 2006 - Jani Ollikainen # # Version: 20060120 1406 # # Settings: BASEURL="http://tracker.hnsk.net/" RSSURL="rss.php" TORRENTDIR="<--WHERE TO PUT TORRENTS IN WATCH LIST-->" KEEPOLD="yes" TORRENTARCHIVE="<--TEMPDIR (AND ARCHIVE IF KEEPOLD IS YES)-->" MKTEMPPROG="mktemp" MKTEMPARGS="-t yhteisobt.XXXXXXXXXX" # # Auth: USER="<--USERNAME-->" PASS="<--PASSWORD-->" # # Torrent Watch List: (regexp - separated with space) TORRENTWATCHLIST="Family.Guy Invasion ^Lost Prison.Break SG-1 Simpsons" # # Torrent Ignore List: (regexp - separated with space) # (If torrent matches Watch List it is processed trought # this list and if it matches ignore list it isn't downloaded.) TORRENTIGNORELIST="\.HR\. AC3" # # Config file which overrides previous settings: if [ -f ~/.yhteiso-bt.conf ]; then . ~/.yhteiso-bt.conf; fi # # The CODE: # # Check that TORRENTDIR and TORRENTARCHIVE DIR exists if [ ! -d "$TORRENTDIR" ]; then echo "ERROR! $TORRENTDIR is not a directory!"; exit; fi if [ ! -d "$TORRENTARCHIVE" ]; then echo "ERROR! $TORRENTARCHIVE is not a directory!"; exit; fi # XSLT Inside if [ "z$1" = "zXSLT" ]; then cat < EOF exit; fi # Check for mktemp (or similar)? if [ "z`which $MKTEMPPROG 2>/dev/null`" = "z" ]; then echo "You need mktemp or similar program!"; exit; fi # Check for wget? if [ "z`which wget 2>/dev/null`" != "z" ]; then DLPROG="wget -U 'YhteisoTorrentGet/1.0' -q --http-user=$USER --http-passwd=$PASS"; fi # Check for curl? if [ "z`which curl 2>/dev/null`" != "z" ]; then DLPROG="curl -A 'YhteisoTorrentGet/1.0' -s -O -u $USER:$PASS"; fi # Didn't found wget or curl? if [ "z$DLPROG" = "z" ];then echo "You need wget or curl in your \$PATH!"; exit; fi # Check for sablotron? if [ "z`which sabcmd 2>/dev/null`" != "z" ]; then XSLTPROG="sabcmd"; fi # Check for xsltproc? if [ "z`which xsltproc 2>/dev/null`" != "z" ]; then XSLTPROG="xsltproc"; fi # Date variables YEAR=`date +%Y` MON=`date +%m` DAY=`date +%d` # If with XSLT - Make XSLT tempfile if [ "z$XSLTPROG" != "z" ];then XSLTFILE=`$MKTEMPPROG $MKTEMPARGS` $0 XSLT >$XSLTFILE; fi # Use archive dir as tempdir OLDDIR=`pwd` cd $TORRENTARCHIVE # Delete old RSS (is exists), get new RSS /bin/rm -f $RSSURL $DLPROG ${BASEURL}/$RSSURL # If we didn't get any file - duck and cover! if [ ! -f $RSSURL ]; then exit; fi # Parse RSS RSSPARSED=`$MKTEMPPROG $MKTEMPARGS` # With XSLT: if [ "z$XSLTPROG" != "z" ];then # Parse $XSLTPROG $XSLTFILE $RSSURL >$RSSPARSED 2>/dev/null && PARSEOK=1 || PARSEOK=0 # Remove temp XSLT /bin/rm -f $XSLTFILE; fi # Didn't found sablotron or xsltproc? Or parse failed? Parse Manually :( if [ "z$XSLTPROG" = "z" -o $PARSEOK -eq 0 ];then grep '' $RSSURL | sed -e "s/.*link>\(.*\)<.*/\1/;s#$BASEURL##"| grep torrent$ >$RSSPARSED; fi # Process RSS - Get new torrent, Autodownload torrents on Watch List while read torurl; do # Possible directory away.. torfile=`basename "$torurl"` # Is torrent new? grep -F "$torfile" ${TORRENTARCHIVE}/seentorrents.log 2>/dev/null 1>&2 && FOUND=1 || FOUND=0 # New torrent if [ $FOUND -eq 0 ]; then # On Watch List? WANT=0; for torwatch in $TORRENTWATCHLIST;do echo "$torfile"|egrep -i "$torwatch" 2>/dev/null 1>&2 && WANT=1; done # On Watch List, but should be ignored? if [ $WANT -eq 1 ]; then for torignore in $TORRENTIGNORELIST;do echo "$torfile"|egrep -i "$torignore" 2>/dev/null 1>&2 && WANT=0; done; fi # Get new torrent, if needed if [ $WANT -eq 1 -o $KEEPOLD = "yes" ]; then $DLPROG "${BASEURL}$torurl"; fi # Add to seen torrents list echo "$torfile" >> ${TORRENTARCHIVE}/seentorrents.log # If on Watch List - Send to torrent client if [ $WANT -eq 1 ];then /bin/cp -a "$torfile" $TORRENTDIR; fi; # Keep olds? if [ $KEEPOLD = "yes" ];then # Check that directories exists if [ ! -d ${TORRENTARCHIVE}/$YEAR ]; then mkdir ${TORRENTARCHIVE}/$YEAR; fi if [ ! -d ${TORRENTARCHIVE}/$YEAR/$MON ]; then mkdir ${TORRENTARCHIVE}/$YEAR/$MON; fi if [ ! -d ${TORRENTARCHIVE}/$YEAR/$MON/$DAY ]; then mkdir ${TORRENTARCHIVE}/$YEAR/$MON/$DAY; fi /bin/cp -a "$torfile" ${TORRENTARCHIVE}/$YEAR/$MON/$DAY; fi; # Remove new torrent, if needed if [ $WANT -eq 1 -o $KEEPOLD = "yes" ]; then /bin/rm -f "$torfile"; fi; fi; done <$RSSPARSED # Remove parsed rss tempfile /bin/rm -f $RSSPARSED # Remove $RSSURL /bin/rm -f $RSSURL # Go to old dir cd $OLDDIR