diff --git a/headphones/searcher.py b/headphones/searcher.py index 286296fe..bb7fadda 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -114,23 +114,26 @@ def searchforalbum(albumid=None, new=False, lossless=False): myDB = db.DBConnection() - results = myDB.select('SELECT AlbumID, Status from albums WHERE Status="Wanted" OR Status="Wanted Lossless"') + results = myDB.select('SELECT AlbumID, AlbumTitle, ArtistName, Status from albums WHERE Status="Wanted" OR Status="Wanted Lossless"') new = True - + for result in results: foundNZB = "none" - if (headphones.HEADPHONES_INDEXER or headphones.NEWZNAB or headphones.NZBSORG or headphones.NZBSRUS or headphones.OMGWTFNZBS) and (headphones.SAB_HOST or headphones.BLACKHOLE_DIR or headphones.NZBGET_HOST): - if result['Status'] == "Wanted Lossless": - foundNZB = searchNZB(result['AlbumID'], new, losslessOnly=True) - else: - foundNZB = searchNZB(result['AlbumID'], new) - - if (headphones.KAT or headphones.PIRATEBAY or headphones.ISOHUNT or headphones.MININOVA or headphones.WAFFLES or headphones.RUTRACKER or headphones.WHATCD) and foundNZB == "none": - - if result['Status'] == "Wanted Lossless": - searchTorrent(result['AlbumID'], new, losslessOnly=True) - else: - searchTorrent(result['AlbumID'], new) + if not result['AlbumTitle'] or not result['ArtistName']: + logger.warn('Skipping release %s. No title available' % result['AlbumID']) + else: + if (headphones.HEADPHONES_INDEXER or headphones.NEWZNAB or headphones.NZBSORG or headphones.NZBSRUS or headphones.OMGWTFNZBS) and (headphones.SAB_HOST or headphones.BLACKHOLE_DIR or headphones.NZBGET_HOST): + if result['Status'] == "Wanted Lossless": + foundNZB = searchNZB(result['AlbumID'], new, losslessOnly=True) + else: + foundNZB = searchNZB(result['AlbumID'], new) + + if (headphones.KAT or headphones.PIRATEBAY or headphones.ISOHUNT or headphones.MININOVA or headphones.WAFFLES or headphones.RUTRACKER or headphones.WHATCD) and foundNZB == "none": + + if result['Status'] == "Wanted Lossless": + searchTorrent(result['AlbumID'], new, losslessOnly=True) + else: + searchTorrent(result['AlbumID'], new) else: @@ -1523,7 +1526,11 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): return torrent_folder_name = transmission.getTorrentFolder(torrentid) - logger.info('Torrent folder name: %s' % torrent_folder_name) + if torrent_folder_name: + logger.info('Torrent folder name: %s' % torrent_folder_name) + else: + logger.error('Torrent folder name could not be determined') + return # remove temp .torrent file created above if bestqual[3] == 'rutracker.org': diff --git a/headphones/transmission.py b/headphones/transmission.py index 5f54ec67..92073683 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") @@ -53,7 +62,7 @@ def addTorrent(link): twitter = notifiers.TwitterNotifier() twitter.notify_snatch(nzb.name) 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) if headphones.PUSHALOT_ENABLED and headphones.PUSHALOT_ONSNATCH: @@ -61,7 +70,11 @@ def addTorrent(link): pushalot = notifiers.PUSHALOT() pushalot.notify(name,"Download started") - 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' @@ -71,7 +84,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'] diff --git a/headphones/webserve.py b/headphones/webserve.py index a6bab744..2721d8bb 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -110,7 +110,14 @@ class WebInterface(object): album = myDB.action('SELECT * from albums WHERE AlbumID=?', [AlbumID]).fetchone() tracks = myDB.select('SELECT * from tracks WHERE AlbumID=? ORDER BY CAST(TrackNumber AS INTEGER)', [AlbumID]) description = myDB.action('SELECT * from descriptions WHERE ReleaseGroupID=?', [AlbumID]).fetchone() - title = album['ArtistName'] + ' - ' + album['AlbumTitle'] + if not album['ArtistName']: + title = ' - ' + else: + title = album['ArtistName'] + ' - ' + if not album['AlbumTitle']: + title = title + "" + else: + title = title + album['AlbumTitle'] return serve_template(templatename="album.html", title=title, album=album, tracks=tracks, description=description) albumPage.exposed = True