Wednesday 7 March 2012

Magnet links in Arch Linux with rTorrent and Firefox

Here's a summary of how one goes about to have magnet links automagically appear in rTorrent by clicking on said magnet link in Firefox.

1st of all, assert your .rtorrent.rc has something like the following line:

schedule = watch_directory,5,5,load_start=$HOME/downloads/*.torrent # this is where rTorrent looks for torrent files to add.


2nd, create a file (name it something like maglink-rtorrent.sh) and add the following script:

#!/bin/bash

cd $HOME/downloads # set your watch directory here (where rTorrent looks for torrent files)
[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"

The above script is from Gonzih's dev blog

Don't forget to make it executable

chmod +x maglink-rtorrent.sh


3rd, there's the matter of associating the links with the script. In Firefox, enter

about:config

in the address bar (click OK or whatever).

Right click and choose New->boolean. Enter, as a name for the new key:

network.protocol-handler.expose.magnet

and choose false.
Taken from the Arch Wiki

Click on a magnet link and choose the script we created in the first step.

Next time you run rTorrent, there should be a long hash and stuff, which will later be renamed to the name of the torrent you clicked the respective magnet link when the metadata has been downloaded.

kthxbye
/pax

EDIT: forgot links to sources that are rightfully credited.

No comments:

Post a Comment