From 07ffe8691cfe6b2407904cfb5c054bb925a60bff Mon Sep 17 00:00:00 2001 From: Remy Date: Tue, 9 Aug 2011 21:02:47 -0700 Subject: [PATCH] Added interfaces to staticdir in webstart, searcher excludes Various Artists from search (also cleaned up term encoding), default usenet retention in postprocessor/preprocess --- headphones/postprocessor.py | 6 ++++++ headphones/searcher.py | 27 +++++++++++++++++++-------- headphones/webstart.py | 4 ++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index e28033c3..d8b8cd14 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -111,6 +111,12 @@ def verify(albumid, albumpath): tracks = myDB.select('SELECT * from tracks WHERE AlbumID=?', [albumid]) downloaded_track_list = [] + + try: + albumpath = str(albumpath) + except UnicodeEncodeError: + albumpath = unicode(albumpath).encode('unicode_escape') + for r,d,f in os.walk(albumpath): for files in f: if any(files.endswith('.' + x) for x in headphones.MEDIA_FORMATS): diff --git a/headphones/searcher.py b/headphones/searcher.py index 763e6326..cf25b050 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -74,17 +74,22 @@ def searchNZB(albumid=None, new=False): dic = {'...':'', ' & ':' ', ' = ': ' ', '?':'', '$':'s', ' + ':' ', '"':'', ',':''} - cleanartistalbum = helpers.latinToAscii(helpers.replace_all(albums[0]+' '+albums[1], dic)) + cleanalbum = helpers.latinToAscii(helpers.replace_all(albums[1], dic)) cleanartist = helpers.latinToAscii(helpers.replace_all(albums[0], dic)) - # FLAC usually doesn't have a year for some reason so I'll leave it out: - term = re.sub('[\.\-\/]', ' ', '%s' % (cleanartistalbum)).encode('utf-8') - altterm = re.sub('[\.\-\/]', ' ', '%s %s' % (cleanartistalbum, year)).encode('utf-8') - artistterm = re.sub('[\.\-\/]', ' ', '%s' % (cleanartist)).encode('utf-8') - + # FLAC usually doesn't have a year for some reason so I'll leave it out + # Various Artist albums might be listed as VA, so I'll leave that out too # Only use the year if the term could return a bunch of different albums, i.e. self-titled albums if albums[0] in albums[1] or len(albums[0]) < 4 or len(albums[1]) < 4: - term = altterm + term = cleanartist + ' ' + cleanalbum + ' ' + year + elif albums[0] == 'Various Artists': + term = cleanalbum + ' ' + year + else: + term = cleanartist + ' ' + cleanalbum + + # Replace bad characters in the term and unicode it + term = re.sub('[\.\-\/]', ' ', term).encode('utf-8') + artistterm = re.sub('[\.\-\/]', ' ', cleanartist).encode('utf-8') logger.info("Searching for %s since it was marked as wanted" % term) @@ -459,6 +464,12 @@ def getresultNZB(result): return nzb def preprocess(resultlist): + + if not headphones.USENET_RETENTION: + usenet_retention = 1000 + else: + usenet_retention = int(headphones.USENET_RETENTION) + for result in resultlist: nzb = getresultNZB(result) if nzb: @@ -467,7 +478,7 @@ def preprocess(resultlist): node = d.documentElement nzbfiles = d.getElementsByTagName("file") for nzbfile in nzbfiles: - if nzbfile.getAttribute("date") < (time.time() - int(headphones.USENET_RETENTION) * 86400): + if nzbfile.getAttribute("date") < (time.time() - usenet_retention * 86400): logger.error('NZB contains a file out of your retention. Skipping.') continue #TODO: Do we want rar checking in here to try to keep unknowns out? diff --git a/headphones/webstart.py b/headphones/webstart.py index 474676b2..e5c14cd7 100644 --- a/headphones/webstart.py +++ b/headphones/webstart.py @@ -22,6 +22,10 @@ def initialize(options={}): '/': { 'tools.staticdir.root': os.path.join(headphones.PROG_DIR, 'data') }, + '/interfaces':{ + 'tools.staticdir.on': True, + 'tools.staticdir.dir': "interfaces" + }, '/images':{ 'tools.staticdir.on': True, 'tools.staticdir.dir': "images"