Page 1 of 1

Need help with add_torrent_file method

Posted: Sun Jul 04, 2010 6:03 am
by gunit9690
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.

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

Re: Need help with add_torrent_file method

Posted: Sun Jul 04, 2010 1:01 pm
by johnnyg
What version of deluge are you using?

Re: Need help with add_torrent_file method

Posted: Sun Jul 04, 2010 5:40 pm
by gunit9690
I was using 1.1.9, i'm guessing I need 1.3.0rc1?
I tried installing 1.3.0rc1 but I can't get it to work at all now....I'm sure I messed up installing somewhere....
Deluge won't start in classic mode because it says I need libtorrent > 0.14.9. I tried installing the latest version of libtorrent using that svn thing but that didn't do anything...
Also now when I try and run my test program, it says it can't import aclient...


EDIT:

Okay I seem to have it working properly but i'm still getting that I can't import aclient? Is it in a different location for this new version? Or should I have stayed with 1.1.9 (lol)? Thanks.

Re: Need help with add_torrent_file method

Posted: Sun Jul 04, 2010 8:22 pm
by gunit9690
also this post is in the wrong forum isn't it, if someone could move it that would be appreciated.

Re: Need help with add_torrent_file method

Posted: Mon Jul 05, 2010 5:43 am
by johnnyg
In 1.2/1.3 there is no aclient/sclient just client: http://dev.deluge-torrent.org/wiki/Deve ... iClient1.2

It's probably better to use the new client API rather than the old.