Showing posts with label rtorrent. Show all posts
Showing posts with label rtorrent. Show all posts

Monday, June 1, 2009

RTorrent Remote Control

My preferred bittorrent client is rtorrent. I like it because the text user interface makes it convenient for running on server without X installed. rtorrent has a XML-RPC interface which offers some interesting possibilities for remote control from another application. XML-RPC is a moderately complex protocol and parsing XML is much easier in a high level language. Fortunately someone wrote an XML-RPC utility in Python specifically for rtorrent which makes tinkering a whole easier.

Enabling the XML-RPC interface only requires one line in the .rtorrent.rc config file:
scgi_local = /home/tlow/.rtorrent/socket
You can also enable the interface on a TCP socket but the rtorrent wiki advises against this because of the security implications.

The Python utility can be used on the command line. The following returns the hashes of all the .torrent files currently loaded into into rtorrent:
$ ./xmlrpc2scgi.py scgi:///home/tlow/.rtorrent/socket download_list ''
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param><value><array><data>
<value><string>D19075DB7A5BF5B0B9B89B30EE39CC132BF64F4A</string></value>
<value><string>B00F710FFC9FC09F019FEA2A4718CCFF794475F6</string></value>
<value><string>D7521742B5037E691EFB9CA33C24A29B73F5C68C</string></value>
<value><string>1B74111F0848AA7C056867AEB1A3FBAA744DB356</string></value>
</data></array></value></param>
</params>
</methodResponse>
Obviously you still need to pipe the output to another utility for further processing but the output sort of readable.

The utility can also be used a library module which is much more interesting:
$ ipython
Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45)
Type "copyright", "credits" or "license" for more information.

IPython 0.9.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import xmlrpc2scgi as xs

In [2]: rtc=xs.RTorrentXMLRPCClient('scgi:///home/tlow/.rtorrent/socket')

In [3]: rtc.download_list('')
Out[3]:
['D19075DB7A5BF5B0B9B89B30EE39CC132BF64F4A',
'B00F710FFC9FC09F019FEA2A4718CCFF794475F6',
'D7521742B5037E691EFB9CA33C24A29B73F5C68C',
'1B74111F0848AA7C056867AEB1A3FBAA744DB356']
Which is the same as the XML output above but as a Python list.

The main problem with rtorrent's XML-RPC interface is that very few of the commands are documented, so it requires some more digging to understand exactly what is possible. I already have an idea of how I want to use the interface, but I'll leave that for another time.

Sunday, May 10, 2009

RTorrent 0.8.4

The Debian rtorrent package was upgraded to version 0.8.4 which has a few incompatibilities with the previous package. Since I depend on rtorrent for all my entertainment downloads, I spent some time today making sure there were no problems.

The session file format changed but there is a script, fixSession080-d.py, which will update all the session files to the new version. I only have one session for an extremely large Babylon 5 torrent which I still haven't seeded 1:1 yet so I don't want to lose the current ratio. The script updated the session file without any complaints. You just pass the the session directory (.rtorrent in my case) as an argument:
python fixSession080-d.py .rtorrent

The new version of rtorrent changed the configuration for ratio handling so I also had to update my .rtorrent.rc. My old ratio configuration was:
schedule = ratio,60,60,"stop_on_ratio=100,100M,500"
The stop_on_ratio command no longer exists. The rtorrent wiki page on ratio handling isn't very clear but eventually I came up with this replacement:
ratio.enable=
ratio.min.set=100
ratio.max.set=500
ratio.upload.set=100M

The new rtorrent gives a warning about deprecated configuration commands:
Deprecated on_* commands, use 'system.method.set_key = event.download.{inserted, erased, ...}, , ' instead.
These lines are the culprits:
on_start = lock_torrents,"execute=touch,~/torrents/lock"
on_stop = unlock_torrents,"execute=rm,~/torrents/lock"
on_hash_queued = lock_torrents,"execute=touch,~/torrents/lock"
I haven't figured out the fix for this problem yet, so it is fortunate that it is only a warning for now. Rtorrent's documentation is not the reason I use it. ;-)