Python Script for specific variables?
Posted: Wed May 31, 2017 5:19 pm
I am looking to code a script to output the Label, Name, And the time the torrent was added to deluge but can't find a simple script to do that and the documentation is lacking.... Here is what I have playing with both seeding time and time added.
Any help is appreciated!
Code: Select all
#!/usr/bin/python
import os
import sys
import string
import syslog
# Import the client module
from deluge.ui.client import client
# Import the reactor module from Twisted - this is for our mainloop
from twisted.internet import reactor
from twisted.internet import defer
# Set up the logger to print out errors
from deluge.log import setupLogger
setupLogger()
syslog.syslog('deluge test: the script started running')
label=""
name=""
seeding_time=""
time_added=""
# Connect to a daemon running on the localhost
# We get a Deferred object from this method and we use this to know if and when
# the connection succeeded or failed.
d = client.connect()
# Torrent ID is passed from deluge execute plugin
torrent_id = sys.argv[1]
# We create a callback function to be called upon a successful connection
def on_connect_success(result):
#print "Connection was successful!"
def on_get_torrent(torrent):
global label
label=torrent["label"]
name=torrent["name"]
added=torrent["seeding_time"]
added=torrent["time_added"]
print label
print name
print seeding_time
print time_added
client.disconnect()
reactor.stop()
client.core.get_torrent_status(torrent_id, ["label","name","seeding_time","time_added"]).addCallback(on_get_torrent)
# We add the callback to the Deferred object we got from connect()
d.addCallback(on_connect_success)
# We create another callback function to be called when an error is encountered
def on_connect_fail(result):
print "Connection failed!"
print "result:", result
# We add the callback (in this case it's an errback, for error)
d.addErrback(on_connect_fail)
# Run the twisted main loop to make everything go
reactor.run()