Download torrent files automatically with flexget

Since I started renting a VPS, my goal has been to automate as much tasks as possible. I watch TV shows, and it had become a pain to manually download torrent files every week. In this post, I will explain how those torrent files are automatically downloaded on my VPS. Note that I’m only talking about the torrent files, not the actual files.

First off, you are going to need a RSS feed to download the torrent files from. If you don’t already know one, just head on to the EZTV RSS feed and search for your favorite TV show. You’ll be able to get the RSS feed from the “Search-based RSS Feed” link. For example, for Breaking Bad, the link look like this: http://www.ezrss.it/search/index.php?simple&show_name=Breaking+Bad&mode=rss. Don’t concern yourself with the ‘Date’ and ‘Quality’ fields, we’ll deal with that later.

Seconly, let’s install flexget, which will fetch the torrent files for us. Flexget is an automation tool, that you can install easily. (If you know what pip is, just run sudo pip install flexget and you’re done)

Now, we need to hook these two parts, by telling flexget what to do. In your home directory, create a .flexget directory and create an empty file in it called config.yml. This file is the configuration file flexget will read everytime it’s run. Here is an example config file:

tasks:
  GameOfThrones-torrents:
    rss: http://www.ezrss.it/search/index.php?show_name=Game+of+Thrones&date=&quality=&release_group=&mode=rss
    series:
      - Game of Thrones:
          begin: S04E01
          qualities: [hdtv+, 720p]
    download: /home/downloads/Watch/

  MadMen-torrents:
    rss: http://www.ezrss.it/search/index.php?show_name=Mad+Men&date=&quality=&release_group=&mode=rss
    series:
      - Mad Men:
          begin: S07E01
          quality: "<720p"
    download: /home/downloads/Watch/

When called, flexget runs every ‘task’. Here we have two tasks, fetching torrent files for Game of Thrones and Mad Men. In each task, put a rss field with the link you acquired in the first step. Then add a series field, put the name of the show (‘Game of Thrones’ for example). The begin field tells flexget to only download torrent starting from the specified episode (the specified episode is included), the quality or qualities fields are self explanatory. Lastly, the download field tells flexget where to put the downloaded file.
To test your configuration file, run flexget --test. If your config file is not properly formatted, you’ll instantly know. You can also check which torrent files are retrieved. Don’t hesitate to remove the begin field to confirm that flexget downloads files.

Once you made sure that flexget does what you expect him to, let’s automate the process by adding a cron. Run crontab -e and add the following line to your crontab:

0,30 * * * * /usr/local/bin/flexget --cron

This will create a cron entry that will run flexget every 30 minutes. You can choose another timeframe, don’t decrease it too much though, as some feeds won’t like you pinging them every five seconds.

Let’s recap: we installed flexget, told him to fetch torrent files from a RSS feed and made sure he does it regularly. All done!

Extra credit: Mail and customization.
You can further customize flexget, the flexget Wiki is really understandable and full of examples, I invite you to look into it. For example, using presets could make your config file more DRY.
As a final note, I customized flexget so that it sends me an email when a torrent file is fetched. If you want something like this, just add the following to your config file:

email:
  from: mybox@gmail.com
  to: pmourlanne@gmail.com
  smtp_host: smtp.gmail.com
  smtp_port: 587
  smtp_username: mybox
  smtp_password: qwerty
  smtp_tls: yes
  template: accepted

Edit: Scale better
If you put too much shows in your flexget config, you might start to have problems, such as torrents not downloading. I had this problem, it was because every time flexget was run, it would poll the rss feed for each show. Meaning that if I was waiting on 10 shows, I would make 10 requests to EZRSS every half-hour.
A better way to poll the website is to ask once for the rss feed and then find the shows in it. I did this and the torrents downloaded way better. Here is an excerpt of my config.yml:

tasks:
  Shows-torrents:
    rss: https://ezrss.it/feed/
    download: /home/downloads/Watch/
    series:
      - Game of Thrones:
          begin: S04E01
          qualities: [hdtv+, 720p]

      - Mad Men:
          begin: S07E01
          quality: "<720p"

This way I retrieve the “Latest torrent releases” feed once and try to find each of my shows in it.

Advertisements

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: