From e972a86233fc9a72ef4b9ca7ac482dd600c85511 Mon Sep 17 00:00:00 2001 From: delphiactual Date: Sun, 11 May 2014 21:26:58 -0600 Subject: [PATCH] Easier to follow logic for uTorrent --- headphones/utorrent.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/headphones/utorrent.py b/headphones/utorrent.py index 848cf6f9..b03acdf2 100644 --- a/headphones/utorrent.py +++ b/headphones/utorrent.py @@ -136,16 +136,31 @@ class utorrentclient(object): logger.debug('URL: ' + str(url)) logger.debug('uTorrent webUI raised the following error: ' + str(err)) -def addTorrent(link, hash): +def labelTorrent(hash): label = headphones.UTORRENT_LABEL uTorrentClient = utorrentclient() - uTorrentClient.add_url(link) - time.sleep(1) #ensure file is loaded in uTorrent... - uTorrentClient.setprops(hash,'label',label) + settinglabel = True + while settinglabel: + torrentList = uTorrentClient.list() + for torrent in torrentList[1].get('torrents'): + if (torrent[0].lower() == hash): + uTorrentClient.setprops(hash,'label',label) + settinglabel = False + return True + + +def dirTorrent(hash): + uTorrentClient = utorrentclient() torrentList = uTorrentClient.list() for torrent in torrentList[1].get('torrents'): - if (torrent[0].lower()==hash): + if (torrent[0].lower() == hash): return torrent[26] + return False - return False \ No newline at end of file + +def addTorrent(link, hash): + uTorrentClient = utorrentclient() + uTorrentClient.add_url(link) + labelTorrent(hash) + return dirTorrent(hash)