From 460b8973745397969a738ce7f0431940159342a4 Mon Sep 17 00:00:00 2001 From: Remy Date: Mon, 18 Jul 2011 13:30:22 -0700 Subject: [PATCH] Fixed: albums with no track info werent being sorted when target bitrate was selected --- headphones/helpers.py | 7 +++++-- headphones/searcher.py | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/headphones/helpers.py b/headphones/helpers.py index 6715d1bc..4b6ea043 100644 --- a/headphones/helpers.py +++ b/headphones/helpers.py @@ -105,8 +105,11 @@ def sortNZBList(resultlist, albumid): myDB = db.DBConnection() tracks = myDB.select('SELECT TrackDuration from tracks WHERE AlbumID=?', [albumid]) - # album length in milliseconds - albumlength = sum([pair[0] for pair in tracks]) + # album length in milliseconds - if there is no track info, return False + try: + albumlength = sum([pair[0] for pair in tracks]) + except TypeError: + return False # target size, in bytes targetsize = albumlength/1000 * bitrate * 128 diff --git a/headphones/searcher.py b/headphones/searcher.py index 8bbb0a67..2fd8bb29 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -92,7 +92,6 @@ def searchNZB(albumid=None): logger.info(u"Parsing results from "+searchURL) d = feedparser.parse(searchURL) - logger.debug('Parsing complete. Found %i results' % len(d.entries)) if not len(d.entries): @@ -173,6 +172,10 @@ def searchNZB(albumid=None): logger.debug('Sorting results list') bestqual = helpers.sortNZBList(resultlist, albumid) + + if not bestqual: + logger.info('No track information for %s - %s. Defaulting to highest quality' % (albums[0], albums[1])) + bestqual = sorted(resultlist, key=lambda title: title[1], reverse=True)[0] else: