Need help with add_torrent_file method
Posted: Sun Jul 04, 2010 6:03 am
Hi, recently my utorrent lost all of it's settings so all my torrents lost their save path data
So now i'm trying to write a script for deluge because I have all my .torrent files and all of my data, but the data could be in one of 3 locations.
Basically I would like to write something that could add a .torrent file to a torrent client, tell it to download it to location 1, and then check if the data was found in that location by finding out the status of the torrent (see if it is being downloaded, rechecked or seeded) . If it is being downloaded (instead of rechecked or seeded), it would remove that newly added torrent, then add it again but this time tell it to download to location 2, and then if that didn't work, to download to location 3.
This is a test script I've written but I can't seem to get the add_torrent_file method working. Any help would be appreciated. I'm running ubuntu linux. Thanks.
So now i'm trying to write a script for deluge because I have all my .torrent files and all of my data, but the data could be in one of 3 locations.
Basically I would like to write something that could add a .torrent file to a torrent client, tell it to download it to location 1, and then check if the data was found in that location by finding out the status of the torrent (see if it is being downloaded, rechecked or seeded) . If it is being downloaded (instead of rechecked or seeded), it would remove that newly added torrent, then add it again but this time tell it to download to location 2, and then if that didn't work, to download to location 3.
This is a test script I've written but I can't seem to get the add_torrent_file method working. Any help would be appreciated. I'm running ubuntu linux. Thanks.
Code: Select all
#get list of torrents
from deluge.ui.client import aclient
import time
download_locations = ["/home/gaurav/Videos", "/home/gaurav/Documents", "/home/gaurav/Downloads"]
torrent_locations = ["/home/gaurav/torrents/Blue.Velvet.1986.iNTERNAL.DVDRip.XViD-iLS.torrent","/home/gaurav/torrents/Aqua Teen Hunger Force - Season 4.torrent"]
torrent_files = []
PRIO_NORMAL = 1
maxnum = -1
max_download_speed = maxnum
max_upload_speed = maxnum
max_connections = maxnum
max_upload_slots = maxnum
class TestClient:
def __init__(self):
self.torrent_ids = []
self.torrent_ids_old = []
self.torrent_status = []
self.new_torrent_status = 0
#open torrent files
for t in torrent_locations:
f = open(t)
torrent_files.append(f)
def cb_session_state(self, torrent_ids):
self.torrent_ids = torrent_ids
def cb_session_state_old(self, torrent_ids):
self.torrent_ids_old = torrent_ids
def cb_torrent_status(self, status):
self.torrent_status.append(status)
def cb_new_torrent_status(self, status):
self.new_torrent_status = status
def make_dict(self, location):
alist = [PRIO_NORMAL]
d = dict({"max_download_speed": max_download_speed,
"max_upload_speed": max_upload_speed,
"max_connections": max_connections,
"max_upload_slots": max_upload_slots,
"prioritize_first_last_pieces": True,
"auto_managed": True,
"file_priorities": alist, #list of integers.
"download_location": location})
return d
def find_diff(self):
new_id = 0
for id in self.torrent_ids:
if((id in self.torrent_ids_old) == False):
new_id = id
break
return new_id
def run(self):
aclient.get_session_state(self.cb_session_state)
aclient.force_call(block=True)
print self.torrent_ids
dlist = []
for l in download_locations:
dlist.append(self.make_dict(l))
#aclient.add_torrent_binary(torrent_locations[0], "", dlist[2])
for torrent in torrent_files:
for d in dlist:
aclient.get_session_state(self.cb_session_state_old)
aclient.add_torrent_file(torrent, d) #Does nothing
time.sleep(35) #is this necessary?
aclient.get_session_state(self.cb_session_state)
id = self.find_diff()
print id
aclient.get_torrent_status(self.cb_torrent_status, id, ['progress'])
if(self.new_torrent_status == 100.0):
break
else:
aclient.remove_torrent(id, True, True)
torrent.close()
for id in self.torrent_ids:
aclient.get_torrent_status(self.cb_torrent_status, id , [])
aclient.force_call(block=True)
for status in self.torrent_status:
print status
aclient.set_core_uri()
t = TestClient()
t.run()