[HOW-TO] Automatically download your favourite TV Series

[HOW-TO] Automatically download your favourite TV Series

October 15, 2012 07:50 1 comment
 

24 Kudos

This blogpost explains how to setup an environment to automatically download TV series when they come up in the net. Probably it’s not the most legal thing in the world but I’m a scientist, you know.

It’s not easy, not trivial, not error-free and it requires you to have some *nix/scripting skills (besides you having a server, or generally speaking, a computer that stays up 24/7).

Prerequisites:

  • A Torrent client of your choice that supports monitoring a target directory
  • An account on IFTTT
  • A shell access with a Python environment available
  • Access to your network settings to NAT your computer to the outside
  • An account on Evernote

As you probably already understood, it’s more pain than gain for the majority of the people but I’m a scientist, you know.

The first you need is to join IFTTT. This people provide a way to access Internet stuff and to make it working with some other stuff. What we need from the service is to monitor a RSS feed and to trigger an action when something happens.
Once you’ve got an account on it, get another account this time on Evernote. My approach does not really need Evernote but it does need an account on it in order to enable IFTTT triggers. This is rather an exploit than a solution. In fact, IFTTT does not provide a “visit URL” trigger. In order to be able to create one, I need IFTTT to create a note on Evernote by taking the content from a given URL. If you are smart enough you already understood what I’m going to do: I’m going to trigger an action that will post something on Evernote with the content of a given URL. By doing this, the “given URL” will be visited and we can then ignore what happens on the Evernote side.

Once you’ve created these two accounts (or if you already had them it’s fine), log into IFTTT and create the following recipe:
IF RSS Feed Item matches Then Evernote.
In particular, the matching will be the name of your favourite TV Series and the feed URL will be http://feeds.feedburner.com/eztv-rss-atom-feeds?format=xml.
If you like Dexter, that will be your matching string.
The Evernote part is to Create a link note and the link URL will be the remote IP address from which you can access the Python script that I’m going to show you next, with attached the EntryUrl provided by IFTTT. You will need something like http://yourRemoteIp:34549/empty?torrent_url={{EntryUrl}}. The rest of the Evernote service settings are unused.

So, what’s the workflow? IFTTT recognises that there’s something new in the RSS feed I provided above. If the “something new” matches with the name of your favourite TV series, then it will add a new Evernote link note with the content of the target URL. Such URL is the remote address of your computer, to the port onto which a script is going to be listening to requests. Such requests will contain the EntryUrl provided by IFTTT. Since the feed provides a torrent URL, you can download it on your home computer.

The next step is to setup your Torrent client to monitor a directory on the local filesystem. Deluge, for instance, provides a setting called “Auto add .torrents from:”. Set this parameter to some folder accessible from the script.

Now it’s time to run the script. You can find it HERE.

The script is quite trivial to understand: it creates a socket connection to a specific port (use your network IP/fully qualified hostname in the script) and when a request comes in, it will validate it and, eventually, will download the torrent file to the watch_dir and the torrent client will manage the rest by itself.

There are some parameters to be changed in the script such as the hostname, the port and the watchdir. Feel free to modify the isValid method to tailor your needs.