Pass torrent label as an argument in a script?

General support for problems installing or using Deluge
deckoff
Member
Member
Posts: 18
Joined: Sat Feb 25, 2012 12:03 pm

Pass torrent label as an argument in a script?

Post by deckoff »

I want to add a script which executes on completion - copy to another folder.
I want the script to check the label of the torrent and do - nothing no label, copy to movies folder if label movie and copy to tvepisodes folder if tv show. I think it will be easy to be done if I can pass the torrent label to the script, but dont now the correct syntax.
It seems:
$1 $2 $3 stand for name , location and cant remember what else.
How to get the torrent label? I use the default label plugin.
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Pass torrent label as an argument in a script?

Post by Cas »

You can use a client script to retrieve torrent information, here's an example to retrieve a label:

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()

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()
deckoff
Member
Member
Posts: 18
Joined: Sat Feb 25, 2012 12:03 pm

Re: Pass torrent label as an argument in a script?

Post by deckoff »

Thank you. :)
Since my scripting power starts and ends with bash, could you link a bash script :)
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Pass torrent label as an argument in a script?

Post by Cas »

It is not possible in bash because we connect to Deluge using the python client library.

You can however call that script from your own bash script, passing the torrentid as arg with the output being the label.
deckoff
Member
Member
Posts: 18
Joined: Sat Feb 25, 2012 12:03 pm

Re: Pass torrent label as an argument in a script?

Post by deckoff »

OK, I will fiddle with it and see what comes out of it
If I get it right, running in terminal:

Code: Select all

theabovepytonscript $mytorrentid
will result in label

Thank you, will CRY :) for help if I need dome
deckoff
Member
Member
Posts: 18
Joined: Sat Feb 25, 2012 12:03 pm

Re: Pass torrent label as an argument in a script?

Post by deckoff »

I try the following script, to just to be sure I am getting the correct output

Code: Select all

#!/bin/bash
torrentid=$1

# python /home/deckoff/Desktop/getLabel.py $torrentid

#echo "torrent is done test 2" > ~/Desktop/label
echo $1 > ~/Desktop/label
The logged output I run directly in terminal

Code: Select all

python /home/deckoff/Desktop/getLabel.py 7fc870c44c81cd4acee8061e2377ef18bc364e30
I get the following output

Code: Select all

No handlers could be found for logger "deluge"
Any ideas what might be wrong?
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Pass torrent label as an argument in a script?

Post by Cas »

That output is because I didn't include any log handling for errors and I have updated the script in my original post to include that. However the issue you are seeing is due to Deluge running in classic mode and a client script will only work in daemon/thinclient mode.
deckoff
Member
Member
Posts: 18
Joined: Sat Feb 25, 2012 12:03 pm

Re: Pass torrent label as an argument in a script?

Post by deckoff »

Yes this way more or less it works :)
BUT, I come into some bugs.
Here is the script I came with:

Code: Select all

#!/bin/bash
torrentid=$1

LABEL=$(/home/deckoff/Desktop/getLabel.py $torrentid)

echo $torrentid >> /home/deckoff/Desktop/test
echo $LABEL >> /home/deckoff/Desktop/test
When I uncomment the LABEL= part. the script will not execute, and even worse, the GUI will freeze, when the torrent is at 99.8% or something. When I log in the torrent id only, the script will run OK(sometimes). The execuatbel plugin will not always execute...
Is it possible the problems I have are because I use Ubuntu 11.10. According to the ppa, natty is the latest distro supported. I have
Lazybones
Leecher
Leecher
Posts: 62
Joined: Sat Dec 31, 2011 11:00 pm

Re: Pass torrent label as an argument in a script?

Post by Lazybones »

Complete scripts are blocking, so try warping the content of the shell script and forking it. Then deluge should be released when when getlabee.py fires.

{
# shell script code
} &
deckoff
Member
Member
Posts: 18
Joined: Sat Feb 25, 2012 12:03 pm

Re: Pass torrent label as an argument in a script?

Post by deckoff »

Thank you, but I don't quite understand what to do - I am new to this.
Where should the code of the shell script go , and hwo exactly do I fork it.
Thank you for the help (both of you)!!!

Something like this:

Code: Select all

{
#!/bin/bash
torrentid=$1

LABEL=$(/home/deckoff/Desktop/getLabel.py $torrentid)

echo $torrentid >> /home/deckoff/Desktop/test
echo $LABEL >> /home/deckoff/Desktop/test
}&
Post Reply