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']