toplogo.png
up Home Computers TV Show Auto-Downloading
From http://craig.backfire.ca/pages/computers/tv

TV Show Auto-Downloading

With the following scripts, TV shows can be automatically downloaded using EZTV, Mininova, and rTorrent.


Mininova RSS Reader (getminirss.pl)

Download

This script reads the RSS feed for the user EZTV at Mininova.org, and checks each entry to see if it matches a list of strings stored in a separate file.

Configuration

There is no config file for this script. Instead, the config is done by manually editing the variables at the top of the getminirss.pl script.

my $emailnotify=0; # Email the addition of new torrents.
my $email="root\@localhost"; # Email to who
my $logfile="/home/boss/.torrentlog"; # Log file, must be readable and writeable.
my $wantfile="/home/boss/.torrentshows"; # File with list of strings to search.
my $torrentdir="/home/boss/eztv/"; # Directory to place new .torrent files for rTorrent.

The $wantfile contains a list of strings to search for in the TV show titles. For example, to get Top Gear, Fifth Gear, The Boondocks and Scrubs, the file would look like this:

gear
boondocks
scrubs

rTorrent

rTorrent must be configured to watch the $torrentdir for new torrents. The best way to do this is to make a new config file for rTorrent, and run it all day, every day so it can get torrents as soon as possible. Below is my config file, named .rtorrent.eztv.

upload_rate = 250
port_random = yes
check_hash = yes
# directory must be the same as $torrentdir in getminirss.pl
directory = /home/boss/eztv/
umask = 0002
schedule = ratio,60,60,"stop_on_ratio=300,500M,310"
schedule = watch_directory,10,10,"load_start=/home/boss/eztv/*.torrent"
# line below moves the finished torrents to a new directory
# to avoid trying to watch files before they're done.
on_finished = move_complete,"execute=mv,-u,$d.get_base_path=,/fs/local/torrents/eztv/ ;d.set_directory=/fs/local/torrents/eztv/"

rTorrent must then be told to load the new config file with the following command:

rtorrent -n -o import=/home/boss/.rtorrent.eztv

Execution

A separate script must be made to pass the RSS feed to the script. The one I use is seen below:

#!/bin/sh
wget -q -O /tmp/minirss.xml "http://www.mininova.org/rss.xml?user=EZTV" || exit
cat /tmp/minirss.xml | perl /path/to/getminirss.pl
rm /tmp/minirss.xml

This script must be run repeatedly to get new show listings. It can be called from cron, or run in a while loop on the command line, as seen below.

# Run from cron, every 30 minutes.
# Add this to /etc/crontab:
*/30 * * * * boss /bin/sh /fs/cron/torrent.sh

# Run in the shell, every 30 minutes.
while true ; do /bin/sh /fs/cron/torrent.sh ; sleep $((30*60)) ; done

Notes and Warnings

By default, the script ignores x264 copies. To change this, comment out the line: next if ($tshow =~ /x264/i);.

The script has basically no error handling. It should not be able to wipe out any data other than $logfile, but anything is possible. Be careful and make backups!


Notes for All Scripts

You can run the scripts without any options to see what options are available. If there are none, nothing will be displayed.

Installing Perl Modules

If you get errors about not being able to run a script due to missing Perl modules, you can look at the top few lines of the script for lines in the form: use Foo::Bar; and install them, using the following command:

perl -MCPAN -e 'install Foo::Bar'

In FreeBSD, Perl modules can often be installed via the ports tree:

portinstall p5-Foo-Bar

No Warranty

NOTE THAT WHILE I HAVE TAKEN CARE TO MAKE SURE THAT THESE SCRIPTS ARE SAFE, I CANNOT GUARANTEE THAT THEY WON'T CAUSE PROBLEMS, INCLUDING DATA LOSS. USE AT YOUR OWN RISK. If you see errors about uninitialised variables, or similar, that is a bug. It may or may not be harmless. It is best to only run these scripts on directories whose contents are "pristine," that is, ones whose contents all have the necessary permissions, and no special files such as pipes or character devices.

Please contact me if you have problems or patches.

Rate This Page

Mouse over the nuts to rate. ZERO NutsOne NutTwo NutsThree NutsFour NutsFive Nuts 

Page last modified on December 30, 2009 14:14:32. (ID=71)