Skip to main content
  1. Projects/

TorrentLoad

For quite a long time, I’ve used rTorrent to download torrents on a server running in a cupboard, which works with a beautiful simplicity unmatched by a lot of torrent clients, and also has the advantage of letting me hog bandwidth by scheduling downloads to happen overnight, rather than competing during the day. I have a number of scripts that I’ve described elsewhere that automatically download torrents for me, but I quite often find myself wanting to torrent directly off a site, and hated having to resort to copy-pasting the magnet link into rTorrent manually. Being the lazy sod that I am, I went about creating an easier way to do this, and came up with TorrentLoad. This project consists of two parts - a server that accepts requests containing magnet link information and converts them into a .torrent file that rTorrent can read, and a Greasemonkey script that runs in your browser to convert all magnet: links to point at the web server running on your local machine.

Receiving Server #

There are two options for running a receiving server - either a Python script or PHP script running within a web server. If you already run Apache or something similar, the PHP script may be your best option, otherwise sticking with the Python self-contained server may be easier! Once up and running, the servers will take magnet links and convert them into a format that is readable by rTorrent. For both options, you will need to change the configuration options at the top of the script:

  • magnetPath - Should point at your rTorrent watch directory (make sure this is writeable from whatever user your server is running under)
  • secretKey - A unique password to your server that needs to be configured in the browser plugin, so only you can access it. As of version 1.3.1, this is read in from an external file called ‘secret’ kept in the same directory as the server script, rather than being hard-coded. You’ll need to create this file and put your password into it.

Option 1 - Python #

In order to download and run the receiving server on port 7500, you need to do the following:

$ git clone https://github.com/mattdy/torrentload.git .
$ cd torrentLoad
$ python server.py 7500

You may want to change the port the server runs on, and you will most likely need to re-configure your router to forward the required port to the machine this server is running on. Use your Google-fu to find how to do this for your particular router model! You may wish to run this server in screen or something similar to allow it to run in the background.

Option 2 - PHP #

Installation of the PHP script is very simple, simply move into the root directory of your web server (/var/www/ on Apache, for example), and run:

$ git clone https://github.com/mattdy/torrentload.git .

You’ll then be able to access the server endpoint at http://YOURADDRESS/torrentLoad/server.php

Browser Plugin #

The second part of this system is a userscript that runs in your browser, using GreaseMonkey/ TamperMonkey or similar. This can be downloaded from here, or found in the checkout from my project server above. When you first run this script, you will see a pop-up asking you to enter two configuration options. First is the address to redirect magnet links to - I would suggest using some sort of Dynamic DNS (such as DynDNS) service in order to keep a persistent link to where the receiving server is running. For instance, you may enter something like http://mycomputer.dyndns.org:7500 as the address. In the other box you should enter the secret key you configured on the server, as specified above. Once these options have been configured, all magnet: links on all websites will be updated to point at the specified endpoint. For example, the magnet link

magnet:?xt=urn:btih:ee42f2adb0ce00495bf87576977eb284f28a17ce&dn=+Ubuntu+12.04+LTS+x86&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80

…would become…

http://mycomputer.dyndns.org:7500?xt=urn:btih:ee42f2adb0ce00495bf87576977eb284f28a17ce&dn=+Ubuntu+12.04+LTS+x86&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&secret=YOUR-KEY-HERE

… and clicking on it would then redirect your browser to the receiving script set up on your server - which creates the .torrent file based off the magnet link, automagically starting the download in rTorrent for you!

Caveats #

First off - this is a very quick couple of little scripts I’ve knocked together and decided to share with the world - they are not particularly robust! As of version 1.3 (23/02/14), there is a “secret” key which makes this method of loading torrents slightly more secure, however please use with caution - you are opening a gateway through which anyone could queue torrents on your server! There isn’t currently any way of editing the address setting in the browser plugin - I’d be happy to accept any patches which add this option. If you do need to change the address, a simple uninstall and reinstall of the script should clear any stored settings and show the pop-up configuration box on first load. These two scripts are provided without any kind of warranty or support - I’ve hosted them here in the hope that someone may find them useful, and maybe even choose to improve them at some point. Please feel free to post any questions or comments below, but I can’t guarantee I’ll be able to help you out! Google is your friend, and a lot faster than contacting me! Finally - obviously only use this for legal torrents. Seriously.