Skip to content

January 30, 2012

Automagically organising your bittorrent downloads with deluge

I, as most people, like to have my video files ordered. After I’ve finished downloading a torrent I manually move it to my media dir, under a directory for the series it belongs to, or no directory at all, but it’s a hard and unnecesary process.

I’ll explain here (and provide an script for it) how to make deluge automagically handle our files.

I’ve chosen deluge bittorrent client for this guide (blame it on enver555), but you should be able to use my script (with maybe, a few modifications about the argument handling) anywhere.

Getting the script

First, you will need to download the shorting script, it’s a single 5-liner bash script, with lots of magic and power, for that reason, I’ve called it the torrent shorting hat.

1 2 3 4 5
#!/bin/bash
id=$1; name=$2; path=$3; source ~/.torrent-aliases
type=$(file -b --mime-type $path |cut -d/ -f1)
for dest_dir in ${!regexes[@]}; do mkdir -p ~/Media/$type/$dest_dir; [[ $path =~ ${regexes[$dest_dir]} ]] && { mv $path ~/Media/$type/$dest_dir/; exit; }; done
mv $path ~/Media/$type/$dest_dir # Fallback
view raw gistfile1.sh This Gist brought to you by GitHub.

Installing it system-wide or locally

You might want all your users to have access to this script, for that, as with any other linux program, you should copy it to path and give it executable permissions, that’s, as root:

wget https://raw.github.com/gist/1705151/540fd4445ca4e0f540ddf82decba3ffc421c46ab/gistfile1.sh -O /usr/local/bin/torrent_shorting_hat
chmod +x /usr/local/bin/torrent_shorting_hat

I personally recoment this method, but if you prefer, you can get it at your local home, you could, for example, do something like this:

wget https://raw.github.com/gist/1705151/540fd4445ca4e0f540ddf82decba3ffc421c46ab/gistfile1.sh -O .torrent_shorting_hat
chmod +x .torrent_shorting_hat

Configuring deluge

We enable the execute plugin

Enable execute plugin

Then, we add an execute action for a “finished torrent download” handler. If you’ve added your script locally, you had to reference it as its full path, otherwise you have just to use “torrent_shorting_hat” as scrpit:

 

Adding the complete script call.

 

Configuring the sorting hat

The sorting hat will read a file in your home called .torrent-aliases, more exactly its regexes variable, it’s basically a shell script with associative arrays, like this:

regexes[''hitchicker']="(.*)42(.*)"

This will get everything containing “42″ to a folder in ~/Media/(mimetype)/hitchicker, being mimetype the file’s mimetype. Wich, by the way, means that even if you don’t have anything configured, the script will organize files by its type.

 

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments