paganpaul: (Linux)
Warning. Linux bash-scripting ahead.

I check for torrents of some tv series. Not daily, so I often forget and then, when I look, I find a whole load of them.

Got sick of forgetting and running behind on episodes, so this morning I wrote a bash script to look things up for me.

It's called TorrentChecker (gosh, where did that name come from). I can provide 2 parameters (torrent description and the episode). If there are no parameters, the script will look for a configfile where rows with the same info for 1 or more torrents.
-The script checks for torrents on Isohunt.com.
-The location of the configfile is defined in $cfg

Here's the script:

#TorrentChecker for isohunt
#
# parm1 torrent to search (opt)
# parm2 episode (opt)
#

Check()
{

tijd="$HOME/tmp/TorrentChecker.tmp"
lynx -dump http://isohunt.com/torrents/?ihq=$1 > $tijd
grep -i $2 $tijd
if [ $? -ne 0 ]
then echo "  No torrent found."
	  echo
	  return
fi

# Found something: get the link

lnknr=`grep -i $2 $tijd | awk -F] '{print $1}' | awk -F[ '{print $2}'`
grep $lnknr\\. $tijd
echo

rm $tijd

}

cfg="$HOME/div/TorrentChecker.cfg"

# Any parms?

if [ ! "x$1y$2" == "xy" ]
then Check $1 $2
     exit
fi

# No parms. Config file?

if [ -f $cfg ]
then
	echo "Configfile $cfg found - processing."
	echo
	cat $cfg | while read titel episode
	do echo "Query $titel $episode..."
		Check $titel $episode
	done
else
	echo "No config-file, no parameters."
	echo "End."
fi



Here is the format for the configfile:

stargate+universe s01e05
eastwick s01e05
eastwick s01e06

  • Isohunt can search for multiple words in a torrent. Connect them with + signs. Put one or more spaces between search-string and episode you want to find.

  • You can enter "s01e" if you want, but that is not good enough. The script will attempt to hand you back the url for the torrent if the episode is found. It won't crash, but output will be slightly overwhelming. Believe me, you don't want that.

  • The search-strings and episode string are case insensitive.

  • The check on parameters is not perfect. Forget one of them and the script dies. This is good enough for me though, feel free to improve if you want to.

  • I am quite certain that the script will die if you stick single or double quotes in a search-string.


Here is an example of the output with the above configfile in place:
[paul@localhost bin]$ TorrentChecker
Configfile /home/paul/div/TorrentChecker.cfg found - processing.

Query stargate+universe s01e05...
No torrent found.

Query eastwick s01e05...
[62]Eastwick S01E05 HDTV XviD-Caph.avi 350 MB 5766 182
62. http://isohunt.com/torrent_details/137150357/eastwick?tab=summary

Query eastwick s01e06...
No torrent found.


Written in GNU bash, version 3.2.19(2)-release (i586-mandriva-linux-gnu)
Also requires lynx (textbased webbrowser) to be installed.

April 2012

S M T W T F S
1234567
891011121314
1516 1718 192021
22 232425262728
2930     

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 20th, 2017 06:44 pm
Powered by Dreamwidth Studios