From 8a0f7ba92731c340b4a6d57b9cd5ad37db943b34 Mon Sep 17 00:00:00 2001 From: rxsegrxup Date: Tue, 11 Mar 2014 12:39:11 -0400 Subject: [PATCH] Fix infinite sleep, duplicate torrent fix If a duplicate torrent is added return proper information. When retrieving the folder name only try 10 times --- headphones/transmission.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/headphones/transmission.py b/headphones/transmission.py index 3cbb021f..6b140580 100644 --- a/headphones/transmission.py +++ b/headphones/transmission.py @@ -38,7 +38,16 @@ def addTorrent(link): return False if response['result'] == 'success': - name = response['arguments']['torrent-added']['name'] + if 'torrent-added' in response['arguments']: + name = response['arguments']['torrent-added']['name'] + retid = response['arguments']['torrent-added']['id'] + elif 'torrent-duplicate' in response['arguments']: + name = response['arguments']['torrent-duplicate']['name'] + retid = response['arguments']['torrent-duplicate']['id'] + else: + name = link + retid = False + logger.info(u"Torrent sent to Transmission successfully") if headphones.PROWL_ENABLED and headphones.PROWL_ONSNATCH: logger.info(u"Sending Prowl notification") @@ -49,11 +58,13 @@ def addTorrent(link): prowl = notifiers.PUSHOVER() prowl.notify(name,"Download started") if headphones.NMA_ENABLED and headphones.NMA_ONSNATCH: - logger.debug(u"Sending NMA notification") + logger.info(u"Sending NMA notification") nma = notifiers.NMA() nma.notify(snatched_nzb=name) - - return response['arguments']['torrent-added']['id'] + return retid + else: + logger.info('Transmission returned status %s' % response['result']) + return False def getTorrentFolder(torrentid): method = 'torrent-get' @@ -63,7 +74,10 @@ def getTorrentFolder(torrentid): percentdone = response['arguments']['torrents'][0]['percentDone'] torrent_folder_name = response['arguments']['torrents'][0]['name'] - while percentdone == 0: + tries = 1 + + while percentdone == 0 and tries <10: + tries+=1 time.sleep(5) response = torrentAction(method, arguments) percentdone = response['arguments']['torrents'][0]['percentDone']