From 7f2671e6c3582bfbfa04816ecbbdbdac9271ef75 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Mon, 5 Nov 2012 13:26:27 -0500 Subject: [PATCH] Better fix for non-unicode artist names being passed into artistlist_to_mbids --- headphones/importer.py | 10 ++++++++++ headphones/mb.py | 11 ----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/headphones/importer.py b/headphones/importer.py index 447ff908..001786fe 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -49,6 +49,16 @@ def artistlist_to_mbids(artistlist, forced=False): if not artist and not (artist == ' '): continue + + # If adding artists through Manage New Artists, there coming through as non-unicode (utf-8?) + # and screwing everything up + if not isinstance(artist, unicode): + try: + artist = artist.decode('utf-8', 'replace') + except: + logger.warn("Unable to convert artist to unicode so cannot do a database lookup") + continue + results = mb.findArtist(artist, limit=1) if not results: diff --git a/headphones/mb.py b/headphones/mb.py index 84c21ec5..5a20e0ad 100644 --- a/headphones/mb.py +++ b/headphones/mb.py @@ -407,17 +407,6 @@ def getTracksFromRelease(release): # Used when there is a disambiguation def findArtistbyAlbum(name): - # Somehow non unicode is getting passed into this function? - if not isinstance(name, unicode): - try: - name = name.decode('latin-1', 'replace') - except: - try: - name = name.decode(headphones.SYS_ENCODING, 'replace') - except: - logger.warn("Unable to convert artist to unicode so cannot do a database lookup") - return False - myDB = db.DBConnection() artist = myDB.action('SELECT AlbumTitle from have WHERE ArtistName=? AND AlbumTitle IS NOT NULL ORDER BY RANDOM()', [name]).fetchone()