From e6bdd159ecfbfb655bb69852b16b7a36977f1c0b Mon Sep 17 00:00:00 2001 From: Remy Date: Sun, 17 Jul 2011 20:17:30 -0700 Subject: [PATCH] Bug fixes: more info error, ascii fix maybe? --- headphones/importer.py | 22 ++++++++++++---------- headphones/mb.py | 2 +- headphones/searcher.py | 40 ++++++++++++++++++++++++---------------- headphones/webserve.py | 13 +++++++++++-- 4 files changed, 48 insertions(+), 29 deletions(-) diff --git a/headphones/importer.py b/headphones/importer.py index 4259be51..4128f4b7 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -16,16 +16,15 @@ def scanMusic(dir=None): results = [] - for r,d,f in os.walk(str(dir)): + for r,d,f in os.walk(dir): for files in f: if any(files.endswith(x) for x in (".mp3", ".flac", ".aac", ".ogg", ".ape")): - try: - file = unicode(files) - root = unicode(r) - results.append(os.path.join(root,file)) - except UnicodeDecodeError, e: - logger.error('Can not decode file %s. Error: %s' % (str(files), str(e))) - continue + logger.debug('File found: %s' % files) + try: + results.append(os.path.join(r, files)) + except UnicodeDecodeError, e: + logger.error('Can not decode file %s. Error: %s' % (str(files), str(e))) + continue logger.info(u'%i music files found' % len(results)) @@ -56,8 +55,11 @@ def scanMusic(dir=None): # Get the average bitrate if the option is selected if headphones.DETECT_BITRATE: - headphones.PREFERRED_BITRATE = sum(bitrates)/len(bitrates)/1000 - + try: + headphones.PREFERRED_BITRATE = sum(bitrates)/len(bitrates)/1000 + except ZeroDivisionError: + logger.error('No bitrates found - cannot automatically detect preferred bitrate') + artistlist = {}.fromkeys(lst).keys() logger.info(u"Preparing to import %i artists" % len(artistlist)) diff --git a/headphones/mb.py b/headphones/mb.py index f023ff23..b4947adb 100644 --- a/headphones/mb.py +++ b/headphones/mb.py @@ -74,7 +74,7 @@ def getArtist(artistid): artist_dict['artist_uniquename'] = artist.getUniqueName() artist_dict['artist_type'] = u.extractFragment(artist.type) artist_dict['artist_begindate'] = artist.beginDate - artist_dict['artist_endDate'] = artist.endDate + artist_dict['artist_enddate'] = artist.endDate releasegroups = [] diff --git a/headphones/searcher.py b/headphones/searcher.py index 52940adf..686caa52 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -20,7 +20,10 @@ def searchNZB(albumid=None): albumid = albums[2] reldate = albums[3] - year = reldate[:4] + try: + year = reldate[:4] + except TypeError: + year = '' clname = string.replace(helpers.latinToAscii(albums[0]), ' & ', ' ') clalbum = string.replace(helpers.latinToAscii(albums[1]), ' & ', ' ') term1 = re.sub('[\.\-]', ' ', '%s %s %s' % (clname, clalbum, year)).encode('utf-8') @@ -66,8 +69,8 @@ def searchNZB(albumid=None): else: logger.info('%s is larger than the maxsize for this category, skipping. (Size: %i bytes)' % (title, size)) - except Exception, e: - logger.info(u"No results found. %s" % e) + except AttributeError, e: + logger.info(u"No results found.") if headphones.NEWZNAB: @@ -91,19 +94,24 @@ def searchNZB(albumid=None): d = feedparser.parse(searchURL) logger.debug('Parsing complete. Found %i results' % len(d.entries)) - for item in d.entries: - try: - url = item.link - title = item.title - size = int(item.links[1]['length']) - if size < maxsize: - resultlist.append((title, size, url)) - logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size))) - else: - logger.info('%s is larger than the maxsize for this category, skipping. (Size: %i bytes)' % (title, size)) - - except Exception, e: - logger.info(u"No results found. %s" % e) + + if not len(d.entries): + logger.info(u"No results found.") + + else: + for item in d.entries: + try: + url = item.link + title = item.title + size = int(item.links[1]['length']) + if size < maxsize: + resultlist.append((title, size, url)) + logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size))) + else: + logger.info('%s is larger than the maxsize for this category, skipping. (Size: %i bytes)' % (title, size)) + + except Exception, e: + logger.error(u"An unknown error occured trying to parse the feed: %s" % e) if headphones.NZBSORG: diff --git a/headphones/webserve.py b/headphones/webserve.py index 46e39877..32efab92 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -216,9 +216,18 @@ class WebInterface(object): page.append(templates._logobar) page.append(templates._nav) artist = mb.getArtist(artistid) + if artist['artist_begindate']: + begindate = artist['artist_begindate'] + else: + begindate = '' + if artist['artist_enddate']: + enddate = artist['artist_enddate'] + else: + enddate = '' page.append('''

Artist Information:

''') - page.append('''

Artist Name: %s
''' % artist['artist_name']) - page.append('''Unique ID: %s

Albums:
''' % artist['artist_id']) + page.append('''

Artist Name: %s (%s)
''' % (artist['artist_name'], artist['artist_type'])) + page.append('''

Years Active: %s - %s

''' % (begindate, enddate)) + page.append('''MusicBrainz Link: http://www.musicbrainz.org/artist/%s

Albums:
''' % (artistid, artistid)) for rg in artist['releasegroups']: page.append('''%s
''' % rg['title']) return page