Pass torrent label as an argument in a script?
Pass torrent label as an argument in a script?
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.
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.
Re: Pass torrent label as an argument in a script?
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()
Re: Pass torrent label as an argument in a script?
Thank you. 
Since my scripting power starts and ends with bash, could you link a bash script

Since my scripting power starts and ends with bash, could you link a bash script

Re: Pass torrent label as an argument in a script?
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.
You can however call that script from your own bash script, passing the torrentid as arg with the output being the label.
Re: Pass torrent label as an argument in a script?
OK, I will fiddle with it and see what comes out of it
If I get it right, running in terminal:
will result in label
Thank you, will CRY
for help if I need dome
If I get it right, running in terminal:
Code: Select all
theabovepytonscript $mytorrentid
Thank you, will CRY

Re: Pass torrent label as an argument in a script?
I try the following script, to just to be sure I am getting the correct output
The logged output I run directly in terminal
I get the following output
Any ideas what might be wrong?
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
Code: Select all
python /home/deckoff/Desktop/getLabel.py 7fc870c44c81cd4acee8061e2377ef18bc364e30
Code: Select all
No handlers could be found for logger "deluge"
Re: Pass torrent label as an argument in a script?
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.
Re: Pass torrent label as an argument in a script?
Yes this way more or less it works
BUT, I come into some bugs.
Here is the script I came with:
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

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
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
Re: Pass torrent label as an argument in a script?
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
} &
{
# shell script code
} &
Re: Pass torrent label as an argument in a script?
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:
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
}&