Install FlexGet on Ubuntu Focal Fossa 20.04LTS to add RSS functionality to Deluge

The classic way to download files using torrents is as follows:

  1. Go to your favourite torrent site
  2. Search for the torrent you want
  3. Once you’ve found it, download the torrent file manually
  4. Add the downloaded torrent file to your favourite torrent client
  5. Once it has finished downloading, manually move the file to its final location. (although some torrent clients can do this step for you)

There is a better way, a fully automated way, and that is to use RSS functionality. So for example, let’s say you’re a Doctor Who fan and you currently manually download each episode of Doctor Who as and when it becomes available. Using RSS you can automate this task meaning you can get Deluge to automatically download each episode for you as and when it becomes available. And then, once it’s downloaded it will automatically move the file to the location you specify. And this final location can be different for each and every series you download. And you can even get it to send you an email when it’s found a new episode to download.

There is a truly excellent tool called FlexGet which can do this, and indeed much more. However, FlexGet can be a little tricky to get up and running and so I’ve explained how I did it below:

IMPORTANT: Downloading TV shows and the like from the internet can have questionable legality in many countries. So, if you’re not familiar with the particular law in your part of the world then let your conscience be your guide as to what you do and do not download!

NOTE: These instructions have been written for Focal Fossa 20.04LTS, Trusty Tahr 14.04LTS, Precise Pangolin 12.04, Maverick Meerkat 10.10, Lucid Lynx 10.04 and Karmic Koala 9.10 and rely on Deluge being installed.

Install Python, pip and Flexget (for versions prior to Focal Fossa 20.04LTS)

First off we need to install Python and pip if they’re not installed already. So type or paste the following two commands into a Putty session or directly into the command line of your Ubuntu installation:

sudo apt-get update

sudo apt-get install python python-pip

Now let’s create the working area which FlexGet will use:

sudo -u deluge mkdir /var/lib/deluge/.flexget

We now want to download and install FlexGet itself. This is a LOT easier than it used to be. Now it’s just a single command:

sudo pip install flexget

Install pip3 and Flexget (for Focal Fossa 20.04LTS and beyond)

Python is already installed on Focal Fossa 20.04LTS so we just need pip:

sudo apt-get update

sudo apt-get install python3-pip python3-venv

Now let’s create the working area which FlexGet will use:

sudo -u deluge mkdir /var/lib/deluge/.flexget

We now want to download and install FlexGet itself. It is now recommended to install FlexGet in a virtual environment:

cd /var/lib/deluge/.flexget

sudo -u deluge python3 -m venv flexget

sudo pip3 install flexget deluge-client

Lastly we need to activate the new virtual environment:

source flexget/bin/activate

All versions

Now we have python, pip/pip3 and flexget installed let’s verify the installation worked properly by typing:

flexget -V

and it should return the version number. eg. 3.1.150. It will also tell you whether you’re on the latest release or not (which we are given we’ve just installed it!). See NOTE below.

When a new version of FlexGet is released and you want to upgrade to it, simply type the following:

sudo pip3 install --upgrade flexget

NOTE: At the time of writing there is a bug in the installation which can be solved by issuing the above command. Once you’ve run it confirm it’s working by issuing flexget -V once more.

Create the FlexGet working area

Often scripts and applications are run as the default Ubuntu User. However, I run FlexGet using the “deluge” user. The deluge user is the username the Deluge daemon runs under (assuming of course that you’ve installed Deluge following my guide). If we don’t do so then we will hit permission problems since the two parts of the setup (Deluge and FlexGet) will be creating files and folders using different usernames and thus will be using different file/folder permissions.

So we need to add the deluge user as a valid user for the deluge API. So:

sudo -u deluge vim /var/lib/deluge/.config/deluge/auth

This will open a file called auth which lives in the /var/lib/deluge/.config/deluge folder.

There is already one line in this file but we need to insert an extra line. So press the [Insert] key once (to go into “edit” mode) scroll to the end of the row that’s already there and insert a new blank line. Next type or paste the following string into this new blank line:

deluge:deluge:10

Now press the [Esc] key once and type the following:

:wq

This should save your changes and bring you back to the command line. If you make a mistake editing the file then issue :q! instead of :wq to abort your changes.

Running FlexGet in Daemon Mode

In older versions of FlexGet you’d run FlexGet perioidically using a cron job. Now you can simply run it as a Daemon which means it is constantly running. It will automatically start when the server boots up and will check for updated torrents according to the schedule you set in the configuration file. So, let’s do that now.

A note about the storing of configuration files

If you’re following my advice about storing configuration files separately then please note that with systemd scripts there has to be a copy stored directly on the Operating System partition. So, instead of linking to it we have to make a copy of it. That’s no big deal really since we’ll not need to edit the script once it’s created.

So, let’s create the first script we need by typing the following command:

sudo vim /media/WD40EFRX/RAIDMain/MyScripts/flexget.service

obviously substituting /media/WD40EFRX/RAIDMain/MyScripts with the location of your script files.

Next, assuming you’re using Putty, highlight the following commands, right-click on them and select Copy

[Unit]
Description=Fleget Daemon
After=network-online.target

[Service]
Type=simple
User=deluge
Group=deluge
UMask=000

WorkingDirectory=/var/lib/deluge/.flexget

ExecStart=/usr/local/bin/flexget daemon start
ExecStop=/usr/local/bin/flexget daemon stop

ExecReload=/usr/local/bin/flexget daemon reload

[Install]
WantedBy=multi-user.target

Toggle back to the Putty Session and press the [Insert] key once and add a couple of blank lines by pressing the [Enter] key. Next right click and the lines we’ve just copied above will be pasted into the file.

Now press the [Esc] key once and type :wq to save and quit out of the script. If you make a mistake editing the file then issue :q! instead of :wq to abort your changes.

Now let’s copy it to the location required as part of systemd:

sudo cp /media/WD40EFRX/RAIDMain/MyScripts/flexget.service /etc/systemd/system/flexget.service

Starting the FlexGet daemon:

When the daemon starts it looks for a Flexget configuration file. So, let’s create an empty one for now. We’ll create the real one later:

sudo touch /var/lib/deluge/.flexget/config.yml

sudo chown deluge:deluge /var/lib/deluge/.flexget/config.yml

Now let’s start the daemon and enable it so it launches on startup (by default it will not):

sudo systemctl start flexget

sudo systemctl enable flexget

Stopping the FlexGet daemon:

If at any time you want to stop the FlexGet daemon then you can do so by issuing the following command:

sudo systemctl stop flexget

To check the status of the daemon use status instead of stop in the above command. The status should look something like this:

Flexget Status

Configure FlexGet

Now we have FlexGet installed and configured to run on boot we need to configure it to suit our needs. See the Configure FlexGet guide.