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)