[SOLVED] Copy completed torrent based on label

General support for problems installing or using Deluge
Post Reply
toastee
New User
New User
Posts: 5
Joined: Fri Apr 29, 2016 3:38 am

[SOLVED] Copy completed torrent based on label

Post by toastee »

Hey all,

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()
And the execute script which is supposed to handle everything:

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

}&
I haven't even gotten to testing the execute.sh yet, but when I run

Code: Select all

/usr/local/deluge/env/bin/python getlabel.py <hash of currently labeled and seeding torrent here>
The script hangs and never executes. I'm really bad at debugging this kind of stuff and I imagine it's something simple. If someone could give me a hand I would really appreciate it.

Thank you!
Last edited by toastee on Fri Apr 29, 2016 5:01 pm, edited 1 time in total.
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: [Execute Script] Copy completed torrent based on label

Post by Cas »

Does the get_label script work? I don't think you need to fork in excecute.sh as I think that was fixed in the plugin.
toastee
New User
New User
Posts: 5
Joined: Fri Apr 29, 2016 3:38 am

Re: [Execute Script] Copy completed torrent based on label

Post by toastee »

Cas wrote:Does the get_label script work? I don't think you need to fork in excecute.sh as I think that was fixed in the plugin.
No it doesn't. I've tried executing it on its own and nothing happens except a hang. I was previously getting an auth error before I added the pass to the connection string so I know it's doing *something* but I can't figure out how to diagnose it.

Also something occurred to me after I posted this - is Deluge going to lock files that it's seeding? If so, should I create a symlink instead of a copy and then create another script that fires on torrent removal (once seeding is complete) that deletes the symlink and does a copy at that point (since it wouldn't be locker anymore)? Hope that makes sense.
toastee
New User
New User
Posts: 5
Joined: Fri Apr 29, 2016 3:38 am

Re: [Execute Script] Copy completed torrent based on label

Post by toastee »

Okay so someone has informed me I'm trying to reinvent the wheel here - I didn't know you could change completed download directory by label already within the UI, so I believe this script is largely redundant for what I was trying to accomplish.

Thanks anyway for your help :)
Varming
New User
New User
Posts: 9
Joined: Fri May 12, 2017 10:35 pm

Re: [SOLVED] Copy completed torrent based on label

Post by Varming »

How do you change the completed download directory by label within the UI..?
Post Reply