Kodi server part 5: Transmission torrent client

Powered by Drupal
Submitted by Sam Hobbs on

This is the fifth part of a multi-part tutorial describing how to configure the "perfect" Kodi media centre running on top of ubuntu server. Other parts of the tutorial may be found here:

This section covers Transmission daemon's installation and configuration, and some tips for controlling it using the commandline as well as enabling administration on the local network using the web interface.

Commandline torrent client (transmission)

I chose Transmission as the torrent client for my kodi box because it is lightweight, can be run as a headless daemon, and it comes bundled with a set of tools like transmission-remote that allow the daemon to be controlled from the commandline. This makes it very easy to log in via SSH and add a torrent when you are out and about. First, install transmission:

sudo apt-get update
sudo apt-get install transmission-daemon transmission-cli

Make sure the daemon is enabled and start it:

sudo systemctl enable transmission-daemon
sudo systemctl start transmission-daemon

Transmission runs as the user debian-transmission, which has a home directory at /var/lib/transmission-daemon. By default, all of the files are downloaded into the downloads directory within this home directory. The package installer automatically creates a symlink for the transmission settings file from /var/lib/transmission-daemon/.config/transmission-daemon/settings.json to /etc/transmission-daemon/settings.json for convenience. To enable kodi to see and edit files downloaded by transmission, we need to add kodi to the debian-transmission group, which we can do with this command:

sudo usermod -a -G debian-transmission kodi

Something to be wary of is that Transmission overwrites the settings file with the current config when it stops (or is restarted). This is because a lot of the settings can be changed using transmission-remote when the daemon is running, and if the current config wasn't written to the file when the program exited then these changes would be lost. However, it is possible to change settings manually in the file and then reload the daemon without losing any modifications. I've noticed that due to a packaging error, the directory /var/lib/transmission-daemon/downloads is created ready for downloaded files, but the default settings file specifies Downloads (capital D) for complete and incomplete torrents. Open the settings file /etc/transmission-daemon/settings.json and correct the following lines:

{
...
    "download-dir": "/var/lib/transmission-daemon/downloads",
    "incomplete-dir": "/var/lib/transmission-daemon/downloads",
...
}

Now reload transmission:

sudo service transmission-daemon reload

Controlling Transmission with transmission-remote

By default, transmission requires authentication using the username and password stored in the settings file before it will accept commands from transmisison-remote. If you try and connect now, you should see something like:

kodi@kodi:~$ transmission-remote -l
Unexpected response: <h1>401: Unauthorized</h1>Unauthorized User-www-form-urlencoded

You can send the username and password every time you connect using the -n option (i.e. transmission-remote -n username:password -l) but this is tedious, so instead let's turn off authentication. Open /etc/transmission-daemon/settings.json and set:

"rpc-authentication-required": false,

Now reload (not restart, or the changes will be lost) the daemon:

sudo service transmission-daemon reload

You should now get a normal response like this:

kodi@kodi:~$ transmission-remote -l
ID     Done       Have  ETA           Up    Down  Ratio  Status       Name
Sum:              None               0.0     0.0

Worried about removing authentication? There are two other lines in the config that should look like this:

    "rpc-whitelist": "127.0.0.1", 
    "rpc-whitelist-enabled": true,

This "whitelist" isn't a list of hosts that don't have to authenticate, it's a list of hosts that are allowed to connect. So in the default configuration, only clients on the local machine can give commands to transmission, which is secure enough for me. In part 7 of the tutorial we will enforce this restriction using a firewall. Here is a selection of useful commands for controlling the daemon with transmission-remote: List torrents:

transmission-remote -l

Start all torrents:

transmission-remote -s

Stop all torrents:

transmission-remote -S

Statistics:

transmission-remote -st

Add a torrent from a .torrent file:

transmission-remote -a ~/foo.torrent

Add a torrent from a magnet link:

transmission-remote -a magnet:?xt=urn...

Remove a torrent:

transmission-remote -t ID -r

Where ID is the ID of the torrent you want to remove (visible in the output of transmission-remote -l). Use a capital R if you would like to delete data as well.

Using the web interface

If you would like to use the web interface from your LAN, you can reach this on port 9091, e.g. type 1.2.3.4:9091 into your browser (where 1.2.3.4 is the IP address of transmission). If you are using a browser on a different machine, this should result in a 403 forbidden error, because of the rpc-whitelist (which only contains localhost). If you want to allow clients on your LAN, you can change this option to:

    "rpc-whitelist": "127.0.0.1,192.168.1.*",

(which you should edit to suit your LAN IP address range, the command above allows any 192.168.1.X address). Then reload transmission:

sudo service transmission reload

If you visit the same address you should then be able to see the web UI. Be careful you aren't too loose with the whitelist, as we are going to configure an always on VPN client connection and you don't want people on the internet to be able to control transmission! In part 7, we will also configure a firewall to prevent unauthorised access. Feel free to ask any questions in the comments below. If you're done, continue to the next part of the tutorial.

Add new comment

The content of this field is kept private and will not be shown publicly.

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.