Saturday, 10 September 2011

Get your episodes automatically with Flexget and Deluge

Hello!

As the next TV show season is about to start, I'm documenting here how to configure your computer to automatically find and download your favourite episodes. In a nutshell, we will configure FlexGet to monitor a RSS feed, find interesting torrents, and add them to a torrent client called Deluge. Let's get started!

Step 1: Install FlexGet


In the official site, you can find a really detailed tutorial on how to install this program. I'll describe here a straightforward guide to get it running:

1.1. Ensure that you have Python available.


Open a terminal and execute the following command:

$ python -V
Python 2.6.6
$

In this example, you can see that version 2.6.6 of Python is currently installed. According to the documentation, you must have a version between 2.5 and 2.7. So, in this case, we're good to go.

It is highly unlikely that Python is not installed. If that is the case, you can install it (in a Debian-based distribution such as Ubuntu) with the command:

$ sudo apt-get install python2.6

1.2. Ensure that you have the easy_install installed.


Execute the following command on the terminal:

$ easy_install -h

Global options:
  --verbose (-v)  run verbosely (default)
...

usage: easy_install [options] requirement_or_url ...
   or: easy_install --help
$

In this case, we can see that easy_install is installed and proudly displaying its help information. If that's not your case, execute the following command:

$ sudo apt-get install python-setuptools

1.3. Install FlexGet using easy_install.


Run the following command:

$ sudo easy_install flexget

Then check that FlexGet is installed and working with the following command:

$ flexget -V
1.0r2195
$

Step 2: Install Deluge

Run the following command to install Deluge:

$ sudo apt-get install deluge deluged

I find it very useful to install Deluge's web interface because have this setup set on my home server. This way, I can easily access deluge remotely. Install the web interface with the following command:

$ sudo apt-get install deluge-web

Now, ensure that the Deluge daemon (deluged) is running with the command:

$ deluged
$

When you restart the computer, the Deluge deamon will automatically start.


Step 3: Configure FlexGet

Now that all software is installed, we just need to set it up.

3.1. Set up Deluge to allow remote connections


Start by opening Deluge's web interface. Type the following address on a browser on the computer which is running Deluge:

http://localhost:8112/

The password is set to "deluge" by default.

Now find the button "Preferences" on the top horizontal bar. Then, choose "Daemon" from the categories panel and make sure that "Allow Remote Connections" is checked.

3.2. Find Deluge's password


To set up FlexGet to connect to Deluge, we must find the password that Deluge is expecting on the remote connection. Run the following command to discover your password:

$ cat ~/.config/deluge/auth
localclient:dd620e1a11d525e6cbb5962a05f2f01d525e6cfe:10
$

Now we know that Deluge is expecting user "localclient" with password "dd620e1a11d525e6cbb5962a05f2f01d525e6cfe" on the remote connection.

3.3. Write your FlexGet configuration file



It's time to tell FlexGet which shows we want it to download, where to save them, and how it must connect to Deluge.

The configuration file that FlexGet uses is located in:

~/.flexget/config.yml

Here is my config file, slight modified.

01
02
03
04
05
06
07
08
09
10
11
12
13
14

15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  presets:
    tv:
      manipulate:
        - title:
            replace:
              regexp: '^HD 720p: '
              format: ''
      series:
        settings:
         720p:
           timeframe: 12 hours
           quality: 720p
           set:
             movedone: "/home/myself/media/series/%(series_name)s/Season %(series_season)s/"

         HDTV:
           quality: hdtv
           set:
             movedone: "/home/myself/media/series/%(series_name)s/Season %(series_season)s/"

       HDTV:
         - "A TV Show"

       720p:
         - "Another TV Show"
         - "Yet Another TV Show"
 
     deluge:
       path: "/home/myself/incoming/"
       host: "localhost"
       port: 58846
       ratio: 1.0
       removeatratio: true
       user: "localclient"
       pass: "dd620e1a11d525e6cbb5962a05f2f01d525e6cfe"

 feeds:
   EZRSS:
     rss: "http://ezrss.it/feed/"
     preset: tv

Let me explain it, by importance order:
  • Lines 10-19: Setting up two quality presets, one for HDTV and another for 720p. It also specifies where to save each downloaded episode;
  • Line 11: Tells FlexGet to wait 12 hours for a 720p episode is available. When that timeframe expires, it downloads the best quality it has seen so far;
  • Lines 21-26: Describing the names of the TV shows that I am interested in and which quality I want them;
  • Lines 3-7: In EZRSS, some episodes' names start with the quality. These lines remove that from the episode name so that FlexGet correctly recognizes them;
  • Lines 28-35: Configure how FlexGet connects to Deluge. We must now use the username and password that  we got previously;
  • Lines 37-40: Tell FlexGet to monitor the EZRSS feed for our precious TV shows.
Important: Do not use tabs for formatting, you MUST use two spaces per each indentation level.

3.5. Schedule FlexGet to execute using cron.


First, we must know where the flexget binary is. You can know this with the following command:

$ which flexget
/usr/local/bin/flexget
$

Now, we must add an entry to the crontab to execute FlexGet periodically. To run FlexGet every hour (which is a good enough period), edit the crontab with the command:

$ crontab -e

Then, add the following line to run FlexGet every hour. Use the location that the we found out previously:

@hourly /usr/local/bin/flexget --cron

Limitations of this approach


I have personally been using this setup for quite a while now. The most annoying limitations that I've found are:
  • EZRSS reliability: Sometimes it goes down and it misses a few episodes. When it comes back up again, you find gaps in the episode's order. As a workaround, I created an account on MyTVRSS with my TV shows and added it to my feed reader
  • EZRSS lack of 720p: Not all TV shows (almost none that I watch) have episodes with 720p quality on EZRSS
I have been working on a new version of this tutorial using Yahoo Pipes instead of EZRSS. I shall describe it on a post someday soon.

5 comments:

  1. Have to take a look at FlexGet! I'm using "unlicenced" software to download feeds and I think it would be a really decent substitute for a whole bunch of steps on my setup!

    I use TVTorrents for it… it's reliable, has 720p, has loads of options including RSS filters… love it!
    I use Transmission for the downloads and then files get copied to the TV Shows folder where a auto file manager app sorts them into folders, calls this bad motherfucker https://github.com/meermanr/TVSeriesRenamer to rename them to a pretty name with ep title and uses HandBrakeCLI to convert to iPhone format and add to iTunes where another script sets its TV properties. In the morning I sync the iPhone with iTunes and all TV Shows are copied over for me to watch!

    ReplyDelete
  2. okay… i've changed a bunch of stuff… had some troubles with flexget not even trying to open transmission but i figured out another way…
    Also changed the way files are sorted so I don't have to add new rules for each show's season… hopefully, now I just add a show to TVTorrents and thats it… everything eles is automatic.

    ReplyDelete
  3. I did not know about TVTorrents. I'll give it a try and report back. Thanks for the tip :)

    ReplyDelete
  4. any updates for this? i have everything working independently but not together

    ReplyDelete