rTorrent : Probing downloads status through XML-RPC

October 10th, 2009 by Stephane Kattoor

rTorrent is a very efficient BitTorrent client for linux. It has a very small memory footprint, a very customizable configuration file, and exposes it’s internals through XML-RPC. This is convenient to implement 3rd party GUI or web interfaces.
Let’s see how to setup and use XML-RPC to probe rTorrent downloads.

Installation and configuration or rTorrent and Lighttpd

Installation of rTorrent and setup for XML-RPC access is pretty well covered on other sites, so I won’t go in the details but for further reference here is my .rtorrent.rc file (the important directive regarding XML-RPC is sgi_port ) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ cat .rtorrent.rc
# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 40
 
session = ~/.rtorrent.session
directory = ~/active
 
schedule = watch_directory,5,5,load_start=~/active/*.torrent
# */
schedule = untied_directory,5,5,remove_untied= 
 
on_finished = rm_torrent,"execute=mv,$d.get_tied_to_file=,~/archives"
on_finished = move_complete,"execute=mv,-u,$d.get_base_path=,~/finished;d.set_directory=~/finished" 
 
port_range = 16881-16999
 
peer_exchange = yes
 
dht = on
dht_port = 17000
enable_trackers = no
 
#access allowed only from the localhost
scgi_port = 127.0.0.1:5000

and here is my lighttpd config file :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
$ cat /etc/lighttpd/lighttpd.conf | egrep -v '^#|^$'
var.basedir  = "/var/www/localhost"
var.logdir   = "/var/log/lighttpd"
var.statedir = "/var/lib/lighttpd"
server.modules = (
    "mod_access",
    "mod_accesslog",
		"mod_scgi"
)
include "mime-types.conf"
server.username      = "lighttpd"
server.groupname     = "lighttpd"
server.document-root = var.basedir + "/htdocs"
server.pid-file      = "/var/run/lighttpd.pid"
server.errorlog      = var.logdir  + "/error.log"
server.indexfiles    = ("index.php", "index.html",
						"index.htm", "default.htm")
server.follow-symlink = "enable"
static-file.exclude-extensions = (".php", ".pl", ".cgi", ".fcgi")
accesslog.filename   = var.logdir + "/access.log"
url.access-deny = ("~", ".inc")
scgi.server = (
	"/RPC2" =>
		( "127.0.0.1" =>
			(
				"host" => "127.0.0.1",
				"port" => "5000",
				"check-local" => "disable",
				"disable-time" => 0,  # don't disable scgi if connection fails
			)
		)
)

You need lighttpd (or any other web server supporting SCGI) to expose the XML-RPC service provided by rTorrent throught HTTP.

A first shot

Here is a first snippet which will let you collect some informations from the torrents being downloaded by rTorrent :

1
2
3
4
5
6
7
8
9
10
$ xmlrpc spaghetti d.multicall "main" "d.get_base_filename=" "to_mb=\$d.get_bytes_done=" "to_mb=\$d.get_left_bytes=" "to_mb=\$d.get_size_bytes="
Result:
 
Array of 1 items:
  Index  0 Array of 4 items:
             Index  0 String: 'slackware64-13.0-iso'
             Index  1 String: '  1658.4'
             Index  2 String: '  2166.0'
             Index  3 String: '  3762.5'
$

The properties we are fetching a pretty self explanatory, the syntax not so (that’s why I feel the urge to document it now that I got it working …).

The reference about the methods rTorrent exposes can be found here, here and here.

This can be very useful if you plan to code a GUI/web interface around rTorrent, but also if you simply want to have a script shell pulling these information and display them on your desktop via Conky for example. I’m just saying. ;-)


Tagged with:

Related Post

One Response to “rTorrent : Probing downloads status through XML-RPC”

  1. conky : integrating rTorrent downloads monitoring - Tech@Sakana – A sysadmin’s blog Says:

    [...] rTorrent is a great BitTorrent client which offers an XML-RPC interface to its core functions, making it easy to get the downloads status through scripting. You can read more about that in this previous post. [...]

Leave a Reply