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 ) :
$ 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 :
$ 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 :
$ 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. 😉
One thought on “rTorrent : Probing downloads status through XML-RPC”
Comments are closed.