Logging downloads with rTorrent

rTorrent has got to be one of the best torrent clients out there, especially for linux. It’s flexibility really shows when you get down to the nitty gritty in .rtorrent.rc.  I for example wrote a script that logs every download that has been completed to a text file, so that I can review all what I’ve downloaded instead of trying to remember. I shall explain how I did this in this post.
I assume that you have prior knowledge of rTorrent and it’s workings. It’s not as easy as other bittorrent clients but it really pays off to learn this one.

It is possible to execute certain actions upon the completion of a torrent, this can be done with the action on_finished. It also allows you to take certain variables from the torrent that has finished and use it in commands. My on finished line looks like this:

system.method.set_key = event.download.finished,writer,”execute=/opt/flx/.rtorrent/writecomplete.sh,$d.get_directory_base=,$d.get_name=”

It executes a bash file (writecomplete.sh) with 2 arguments:

$d.get_directory_base (e.g /home/flx/downloads/apps/Ubuntu_9.10RC.iso)

$d.get_name (Ubuntu_9.10RC.iso)

You can use these arguments to write them to a text file. My bash file (writecomplete.sh) looks like this:

#!/bin/bash
dldate=`date '+%A %d %B %H:%M%P'`
echo -ne "$2 completed on $dldate\r\n" >> /home/flx/downloaded.txt
exit 0

It takes the second argument (the torrent name) and outputs it to a text file with the date. The output looks like this:
Ubuntu_9.10RC.iso completed on Monday 26 October 12:53pm

I personally don’t like to log everything that I download. Lets say I only want to log downloads made to /home/flx/downloads/apps/ but not to any other folder, we can make this conditional by using:

#!/bin/bash
dldate=`date '+%A %d %B %H:%M%P'`
if [ `dirname $1` == "/home/flx/downloads/apps" ] ; then
echo -ne "$2 completed on $dldate\r\n" >> /home/flx/downloaded.txt
fi
exit 0

This script will only log downloads if torrents are downloaded to /home/flx/downloads/apps

Other directories will be ignored.

You can also deliver notifications to your iPhone using rTorrent completed trigger and Prowl4Linux, you can read more on that here:

rTorrent notifications on your iPhone with Prowl