From dfcffe16711f21c95e5682a4563db3f823254700 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Fri, 17 Aug 2012 19:51:09 +0530 Subject: [PATCH] Another possible fix for fetching album art from last.fm during post-processing. hit or miss. needs for testing --- headphones/albumart.py | 8 ++++++-- headphones/cache.py | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/headphones/albumart.py b/headphones/albumart.py index 5fd6f8a8..47981662 100644 --- a/headphones/albumart.py +++ b/headphones/albumart.py @@ -37,8 +37,12 @@ def getCachedArt(albumid): return None if artwork_path.startswith('http://'): - artwork = urllib2.urlopen(artwork_path, timeout=20).read() - return artwork + try: + artwork = urllib2.urlopen(artwork_path, timeout=20).read() + return artwork + except: + logger.warn("Unable to open url: " + artwork_path) + return None else: artwork = open(artwork_path, "r").read() return artwork diff --git a/headphones/cache.py b/headphones/cache.py index 5c257a61..28f9d500 100644 --- a/headphones/cache.py +++ b/headphones/cache.py @@ -229,7 +229,7 @@ class Cache(object): try: image_url = data['artist']['image'][-1]['#text'] - except KeyError: + except Exception: logger.debug('No artist image found on url: ' + url) image_url = None @@ -266,11 +266,12 @@ class Cache(object): try: image_url = data['artist']['image'][-1]['#text'] - except KeyError: + except Exception: logger.debug('No artist image found on url: ' + url) image_url = None thumb_url = self._get_thumb_url(data) + if not thumb_url: logger.debug('No artist thumbnail image found on url: ' + url) @@ -310,17 +311,17 @@ class Cache(object): return try: self.info_summary = data['artist']['bio']['summary'] - except KeyError: + except Exception: logger.debug('No artist bio summary found on url: ' + url) self.info_summary = None try: self.info_content = data['artist']['bio']['content'] - except KeyError: + except Exception: logger.debug('No artist bio found on url: ' + url) self.info_content = None try: image_url = data['artist']['image'][-1]['#text'] - except KeyError: + except Exception: logger.debug('No artist image found on url: ' + url) image_url = None @@ -356,21 +357,22 @@ class Cache(object): return try: self.info_summary = data['album']['wiki']['summary'] - except KeyError: + except Exception: logger.debug('No album summary found from: ' + url) self.info_summary = None try: self.info_content = data['album']['wiki']['content'] - except KeyError: + except Exception: logger.debug('No album infomation found from: ' + url) self.info_content = None try: image_url = data['album']['image'][-1]['#text'] - except KeyError: + except Exception: logger.debug('No album image link found on url: ' + url) image_url = None thumb_url = self._get_thumb_url(data) + if not thumb_url: logger.debug('No album thumbnail image found on url: ' + url) @@ -402,7 +404,6 @@ class Cache(object): # Should we grab the artwork here if we're just grabbing thumbs or info?? Probably not since the files can be quite big if image_url and self.query_type == 'artwork': - try: artwork = urllib2.urlopen(image_url, timeout=20).read() except Exception, e: