For some time I have wanted to play with the json-rpc interface of Transmission. Today I jumped into it.

I decided to make a program that would run on my local computer and should be called via cron every X minutes, and scan a directory for .torrent files. Any .torrent files found should be added to the download queue in transmission – running on my OpenWrt router.

First of, I installed some perl modules using cpan

sudo cpan -i JSON::RPC MIME::Base64::Perl

and then I started programming. Using JSON::RPC and json-rpc documentation for transmission it is pretty simple once you get a hold of it. One thing I had problems with was the fact that transmissions rpc interface is password protected. How one should deal with this was not documented in JSON::RPC’s documentation, so I downloaded the souce code for JSON::RPC::Client and started to read. It uses LWP::Simple, so there is support for basic authentication. This is a small example on how to configure it:

#!/usr/bin/perl
use JSON::RPC::Client;

my $client = new JSON::RPC::Client;
$client->ua->credentials("host:9091",'Transmission RPC Server','user','pass');
my $uri = 'http://www.example.com/jsonrpc/Test';
my $obj = {
	method  => 'sum',
	params  => [10, 20],
};
my $res = $client->call( $uri, $obj )
# do handling here...

The line in bold is the “important” line. ;-)

Other than that, it was pretty straightforward

This was the first time I used rpc over json, and some time since I last programmed in perl, so it was a bit of a challenge, but as with most challenges it was also very fun – and I will definitely play around with transmission/json-rpc in the future.

To make the program run every 5 minutes, add this line to /etc/crontab:

*/5 * * * * username /path/to/addtorrents.pl

Of course you have to adjust the path to the program and the username.

You can download the program here. If you like it, hate it, have a suggestion or question, or found a bug, please write a comment below.

Related posts:

Tags: , , ,

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This site uses KeywordLuv. Enter YourName@YourKeywords in the Name field to take advantage.