I am trying to make an execute script that copies a torrent's files to a certain directory based on its label. I found this thread and tried to modify it for my purpose, but my bash and python-fu are a little bit weak:
http://forum.deluge-torrent.org/viewtop ... 3&start=10
Here is the Python script for getting the label:
getlabel.py
Code: Select all
#!/usr/bin/python
import sys
from deluge.ui.client import client
from twisted.internet import reactor
# Set up the logger to print out errors
from deluge.log import setupLogger
setupLogger()
d = client.connect(host='127.0.0.1',port=8112,username='myuser',password='mypass')
torrent_id = sys.argv[1]
def on_connect_success(result):
def on_get_torrent_status(torrent):
print torrent["label"]
client.disconnect()
reactor.stop()
client.core.get_torrent_status(torrent_id, ["label"]).addCallback(on_get_torrent_status)
d.addCallback(on_connect_success)
def on_connect_fail(result):
print result
reactor.stop()
d.addErrback(on_connect_fail)
reactor.run()
execute.sh
Code: Select all
#!/bin/bash
torrentid=$1
torrentpath=$3
torrentname=$2
{
LABEL=$(/var/deluge/getlabel.py $torrentid)
echo $torrentid >> /var/deluge/execute_script.log
echo $torrentpath >> /var/deluge/execute_script.log
echo $torrentname >> /var/deluge/execute_script.log
echo $LABEL >> /var/deluge/execute_script.log
if [ $LABEL == "movies" ]
then
mkdir /volume2/movies/$torrentname
cp -ar $torrentpath$torrentname /volume2/movies/$torrentname
echo "Copied $torrentname to movies directory." >> /var/deluge/execute_script.log
fi
if [ $LABEL == "tv" ]
then
mkdir /volume2/tv/$torrentname
cp -ar $torrentpath$torrentname /volume2/tv/$torrentname
echo "Copied $torrentname to TV directory." >> /var/deluge/execute_script.log
fi
}&
Code: Select all
/usr/local/deluge/env/bin/python getlabel.py <hash of currently labeled and seeding torrent here>
Thank you!