How to setup magnet link in Rtorrent

rtorrent

Rtorrent – ncurses torrent client is one of the most powerful rtorrent clients, based on libtorrent library. LibTorrent is a BitTorrent library written in C++ for *nix, with a focus on high performance and good code. The library differentiates itself from other implementations by transferring directly from file pages to the network stack. Because it’s running in console demand very little resources, so it also ideal for use with older computers and also used with screen. There are two versions, the stable version and git version which has added option to move finished torrents to another folder.

The configuration is very simple and it’s done by editing rtorrent.rc file, which can be found in /usr/share/doc/rtorrent/rtorrent.rc or online.

If you have git or patched version you can add ‘moving completed torrents’ with adding this lines to your rtorrent.rc file (don’t forget to change paths!):

# location where new torrent data is placed, and where you should place your
# 'complete' data before you place your *.torrent file into the watch folder
directory = /home/user/torrents/incomplete

# schedule a timer event named 'watch_directory_1':
# 1) triggers 10 seconds after rtorrent starts
# 2) triggers at 10 second intervals thereafter
# 3) Upon trigger, attempt to load (and start) new *.torrent files found in /home/user/torrents/watch/
# 4) set a variable named 'custom1' with the value "/home/user/torrents/complete"
# NOTE: if you do not want it to automatically start the torrent, change 'load_start' to 'load'
schedule = watch_directory_1,10,10,"load_start=/home/user/torrents/watch/*.torrent,d.set_custom1=/home/user/torrents/complete"

# insert a method with the alias 'checkdirs1'
# 1) returns true if the current path of the torrent data is not equal to the value of custom1
# 2) otherwise, returns false
system.method.insert=checkdirs1,simple,"not="$equal={d.get_custom1=,d.get_base_path=}""

# insert a method with the alias 'movecheck1'
# 1) returns true if all 3 commands return true ('result of checkdirs1' && 'torrent is 100% done', 'custom1 variable is set')
# 2) otherwise, returns false
system.method.insert=movecheck1,simple,"and={checkdirs1=,d.get_complete=,d.get_custom1=}"

# insert a method with the alias 'movedir1'
# (a series of commands, separated by ';') 
# 1) "set path of torrent to equal the value of custom1";
# 2) "mv -u  ";
# 3) "clear custom1", "stop the torrent","resume the torrent"
# 4) stop the torrent
# 5) start the torrent (to get the torrent to update the 'base path')
system.method.insert=movedir1,simple,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.get_custom1=;d.set_custom1=;d.stop=;d.start="

# set a key with the name 'move_hashed1' that is triggered by the hash_done event.
# 1) When hashing of a torrent completes, this custom key will be triggered.
# 2) when triggered, execute the 'movecheck1' method and check the return value.
# 3) if the 'movecheck' method returns 'true', execute the 'movedir1' method we inserted above.
# NOTE-0: *Only* data that has had their hash checked manually with ^R [^R = Control r].
# Or on a rtorrent restart[which initiates a hash check]. Will the data move; ~/torrents/incomplete => ~/torrents/complete for example.
# NOTE-1: 'branch' is an 'if' conditional statement: if(movecheck1){movedir1}
system.method.set_key=event.download.hash_done,move_hashed1,"branch={$movecheck1=,movedir1=}"

If you wish to have magnet links automatically added to your watch folder, use following script:

#!/bin/bash
watch_folder=~/.rtorrent/watch
cd $watch_folder  
[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"

…save it, for instance as .rtorrent-magnet, give it execution permission, and place it somewhere under your $PATH, then change settings of your browser to link it to that script. Here are some examples for different web browsers:

-Dwb

First make following script, name it .dwb-scheme, give it execution permission and save it somewhere in your $PATH:

#!/bin/bash
case ${DWB_SCHEME} in
mailto) xterm -e alpine ${DWB_URI};;
magnet) /home/boris/.rtorrent-magnet ${DWB_URI};;
ftp) filezilla ${DWB_URI};;
esac

Then change the Dwb settings in ~/.config/dwb/settings in line:

scheme-handler=/path/to/.dwb_scheme

– Links

Go to Settings/Mail and Telnet programs/Magnet program and add following line:

/path to file/.rtorrent-magnet %

– Firefox

Type about:config into the Location Bar (address bar) and press Enter.

Right-click: New > Boolean > Name: network.protocol-handler.expose.magnet > Value > false.

And next time you click a magnet link you will be asked which application to open it with. Select the .rtorrent-magnet script and you’ll be done.

Aditional links:

Some web interfaces:

WTorrent is a web interface to rtorrent programmed in php using Smarty templates and XMLRPC for PHP library.

nTorrent is a graphical user interface client to rtorrent (a cli torrent client) written in Java.

rTWi is a simple rTorrent web interface written in PHP.

Rtgui is a web based front end for rTorrent written in PHP and uses XML-RPC to communicate with the rTorrent client.

rutorrent – a web-based front-end with an interface very similar to uTorrent which supports many plugins and advanced features.

Remeber, if you want to use web based scripts you must add following line to your .rtorrent.rc file:

scgi_port = localhost:5000

Help links: Rtorrent user guide, Rtorrent manual page, ArchWiki and of course:

$ man rtorrent

Happy hunting.

Advertisements

Comments are closed.