I am a complete noob with python as well as with the UI of deluge. I am trying to create a script in Python which could be called in the command line by a bash script to add a created torrent file and then change the tracker to another entry. I have started to play with the script but are unable to continue due to my lack of knowledge of python and deluge.
This is what I have done so far.
Code: Select all
#!/usr/bin/env python
# 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
import sys
import base64
import os
#Set variables
filetest = sys.argv[1]
print filetest
title = 'Test'
opts = {}
opts['download_location'] = '/mnt/raid5/Media/'
tracker = [ 'http://example.com/announce.php', '0']
# 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(host='127.0.0.1',port=58846,username='deluge',password='deluge')
# We create a callback function to be called upon a successful connection
def on_connect_success(result):
print "Connection was successful!"
print "result:", result
# Disconnect from the daemon once we successfully connect
file = sys.argv[1]
if not os.path.exists(file):
print 'file does not exist'
else:
print 'file does exist'
torrentid = client.core.add_torrent_file(title, file, opts)
client.core.set_torrent_trackers(torrentid, tracker)
print torrentid
client.disconnect()
# Stop the twisted main loop and exit
reactor.stop()
# 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()