mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-20 16:03:59 +01:00
Added code for preferred words sorting
This commit is contained in:
+24
-10
@@ -416,13 +416,27 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
|
|||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error(u"An unknown error occurred trying to parse the feed: %s" % e)
|
logger.error(u"An unknown error occurred trying to parse the feed: %s" % e)
|
||||||
|
|
||||||
#attempt to verify that this isn't a substring result
|
# attempt to verify that this isn't a substring result
|
||||||
#when looking for "Foo - Foo" we don't want "Foobar"
|
# when looking for "Foo - Foo" we don't want "Foobar"
|
||||||
#this should be less of an issue when it isn't a self-titled album so we'll only check vs artist
|
# this should be less of an issue when it isn't a self-titled album so we'll only check vs artist
|
||||||
|
#
|
||||||
|
# Also will filter flac & remix albums if not specifically looking for it
|
||||||
|
# This code also checks the ignored words and required words
|
||||||
|
|
||||||
if len(resultlist):
|
if len(resultlist):
|
||||||
resultlist[:] = [result for result in resultlist if verifyresult(result[0], artistterm, term, losslessOnly)]
|
resultlist[:] = [result for result in resultlist if verifyresult(result[0], artistterm, term, losslessOnly)]
|
||||||
|
|
||||||
if len(resultlist):
|
if len(resultlist):
|
||||||
|
|
||||||
|
# Add a priority if it has any of the preferred words
|
||||||
|
temp_list = []
|
||||||
|
for result in resultlist:
|
||||||
|
if any(word.lower() in result[0].lower() for word in helpers.split_string(headphones.PREFERRED_WORDS)):
|
||||||
|
temp_list.append((result[0],result[1],result[2],result[3],1))
|
||||||
|
else:
|
||||||
|
temp_list.append((result[0],result[1],result[2],result[3],0))
|
||||||
|
|
||||||
|
resultlist = temp_list
|
||||||
|
|
||||||
if headphones.PREFERRED_QUALITY == 2 and headphones.PREFERRED_BITRATE:
|
if headphones.PREFERRED_QUALITY == 2 and headphones.PREFERRED_BITRATE:
|
||||||
|
|
||||||
@@ -437,7 +451,7 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
|
|||||||
|
|
||||||
if not targetsize:
|
if not targetsize:
|
||||||
logger.info('No track information for %s - %s. Defaulting to highest quality' % (albums[0], albums[1]))
|
logger.info('No track information for %s - %s. Defaulting to highest quality' % (albums[0], albums[1]))
|
||||||
nzblist = sorted(resultlist, key=lambda title: title[1], reverse=True)
|
nzblist = sorted(resultlist, key=lambda title: (-title[4] , -title[1]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.info('Target size: %s' % helpers.bytes_to_mb(targetsize))
|
logger.info('Target size: %s' % helpers.bytes_to_mb(targetsize))
|
||||||
@@ -460,7 +474,7 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
|
|||||||
|
|
||||||
# Add lossless nzbs to the "flac list" which we can use if there are no good lossy matches
|
# Add lossless nzbs to the "flac list" which we can use if there are no good lossy matches
|
||||||
if 'flac' in result[0].lower():
|
if 'flac' in result[0].lower():
|
||||||
flac_list.append((result[0], result[1], result[2], result[3]))
|
flac_list.append((result[0], result[1], result[2], result[3], results[4]))
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -469,24 +483,24 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
delta = abs(targetsize - result[1])
|
delta = abs(targetsize - result[1])
|
||||||
newlist.append((result[0], result[1], result[2], result[3], delta))
|
newlist.append((result[0], result[1], result[2], result[3], results[4], delta))
|
||||||
|
|
||||||
nzblist = sorted(newlist, key=lambda title: title[4])
|
nzblist = sorted(newlist, key=lambda title: (-title[4], title[5]))
|
||||||
|
|
||||||
if not len(nzblist) and len(flac_list) and headphones.PREFERRED_BITRATE_ALLOW_LOSSLESS:
|
if not len(nzblist) and len(flac_list) and headphones.PREFERRED_BITRATE_ALLOW_LOSSLESS:
|
||||||
logger.info("Since there were no appropriate lossy matches (and at least one lossless match), going to use lossless instead")
|
logger.info("Since there were no appropriate lossy matches (and at least one lossless match), going to use lossless instead")
|
||||||
nzblist = sorted(flac_list, key=lambda title: title[1], reverse=True)
|
nzblist = sorted(flac_list, key=lambda title: (-title[4], -title[1]))
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
|
||||||
logger.debug('Error: %s' % str(e))
|
logger.debug('Error: %s' % str(e))
|
||||||
logger.info('No track information for %s - %s. Defaulting to highest quality' % (albums[0], albums[1]))
|
logger.info('No track information for %s - %s. Defaulting to highest quality' % (albums[0], albums[1]))
|
||||||
|
|
||||||
nzblist = sorted(resultlist, key=lambda title: title[1], reverse=True)
|
nzblist = sorted(resultlist, key=lambda title: (-title[4], -title[1]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
nzblist = sorted(resultlist, key=lambda title: title[1], reverse=True)
|
nzblist = sorted(resultlist, key=lambda title: (-title[4], -title[1]))
|
||||||
|
|
||||||
|
|
||||||
if new:
|
if new:
|
||||||
|
|||||||
Reference in New Issue
Block a user