Version 15 (modified by Cas, 12 years ago) (diff)



The Execute plugin is only supported from deluge versions 1.3RC2 and up. It gives you the option to run your own scripts (e.a. Bash, Python or any other shell) triggered with different events in Deluge. At this moment only the events added (when a torrent is added to deluge) and complete (when a torrent has finished downloading) are supported. More events whill be added in the future.

The script to be executed will be supplied with three Torrent variables:

  1. ID (Hash)
  2. Name
  3. Folder:
    • Torrent Added: 'Download'
    • Torrent Complete: 'Download' or 'Move Completed', if setup.


Enable the plugin in the Plugins menu in Preferences. For the webUI; reopen the Preferences menu for the Execute plugin to be available.

Note: After enabling this plugin Deluge may require restarted for it to work properly.

The events Torrent Complete and Torrent Added can be selected and the full path to the script entered (e.g. /home/user/

Make sure the script is set to executable:

chmod u+x /home/user/

Also ensure that it is accessible by the user used to run deluged.

Script Examples



The following scripts can be used for testing purposses. They can be run from command line like:

./ "var1" "var2" "var3"

The variables should show up in your syslog.

tail /var/log/syslog

Python Example script

import sys
import os
import syslog
syslog.syslog('deluge test: the script started running')
for arg in sys.argv[1:]:

Sendemail script

As a alternative to the notifications plugin you can send your e-mails through the execute script by using the program sendemail. I'll explain in short how to set this up.

We need to have script to run and the application sendemail installed. With sendemail it is possible to send e-mails to a smtp server all from one (command)-line. I'm using ubuntu 9.10. If sendemail is available in your repository sendemail can be installed with the command:

sudo apt-get install sendemail

The following command sends a e-mail:

sendemail -s -t -f -u "subject" -m "message"

Now where going to create the script that utilyzes the sendemail program. The script is named


subject="Started download new torrent!"
message="$torrentname to $torrentpath"

echo -e `date`"::Started download torrent:$2 in: $3" with id:$torrentid >> ~/scripts.log
echo -e `sendemail -s -t -f -u "Started downloading $torrentname!" -m "Downloading $torrentname to: $torrentpath"` >> ~/scripts.log

In line 2,3 and 4 the variables are assigned to more readable variables.

In line 6 and 7 the variables subject and message are filled.

In line 9 the message is being written to (in my case) /var/lib/deluge/scripts.log.

In line 10 the sendemail program is called. Output is also written to the /var/lib/deluge/scripts.log file.

Make sure that you substitute, myemail@… and fromemail@… with your own data!

the same script can be rewritten to be used with the complete event. This way you will get a e-mail when a torrent is started and finished.

The same can also be done with a single python script:

import sys 
import smtplib

torrent_id = sys.argv[1]
torrent_name = sys.argv[2]
save_path = sys.argv[3]

#You can change these
from_addr = ""
to_addr = ""
smtp_srv = ""

subject = "Some subject"
message = """Put your message here

It can span multiple lines. It can also contain information by specifying
%(torrent_id)s or %(torrent_name)s""" % { 
    'torrent_id': torrent_id,
    'torrent_name': torrent_name,
    'save_path': save_path

msg = "To:%s\nFrom:%s\nSubject: %s\n\n%s" % (to_addr, from_addr, subject, message)

smtp = smtplib.SMTP(smtp_srv)
smtp.sendmail(from_addr, to_addr, msg)

Extract archives script

This script will search for archives in downloaded content and extract them. Actions are logged as entries in syslog. This script can be easily extended to support more compression and archive formats.

formats=(zip rar)
commands=([zip]="unzip -u" [rar]="unrar -o- e")


    logger -t deluge-extractarchives "$@"

log "Torrent complete: $@"
cd "${torrentpath}"
for format in "${formats[@]}"; do
    while read file; do 
        log "Extracting \"$file\""
        cd "$(dirname "$file")"
        file=$(basename "$file")
        # if extraction_subdir is not empty, extract to subdirectory
        if [[ ! -z "$extraction_subdir" ]] ; then
            mkdir "$extraction_subdir"
            cd "$extraction_subdir"
        ${commands[$format]} "$file"
    done < <(find "$torrentpath/$torrentname" -iname "*.${format}" )