From: Ivan Frade Date: Fri, 21 Aug 2009 15:00:45 +0000 (+0300) Subject: Handle no_results page in image online search X-Git-Tag: mussorgsky-0.2-1~10 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=43f8a56f662a41ab7e9e282766d6d49c58bbe558;p=mussorgsky Handle no_results page in image online search --- diff --git a/src/album_art.py b/src/album_art.py index 912aa06..72cf1db 100755 --- a/src/album_art.py +++ b/src/album_art.py @@ -102,6 +102,10 @@ class MussorgskyAlbumArt: results_page = self.__msn_images (artist, album) valid_images = [] for image_url in self.__get_url_from_msn_results_page (results_page): + if (not image_url): + # Some searches doesn't return anything at all! + break + image = self.__get_url (image_url) if (image): image_path = os.path.join (CACHE_LOCATION, "alternative-" + str(len(valid_images))) @@ -112,16 +116,17 @@ class MussorgskyAlbumArt: return valid_images def save_alternative (self, artist, album, path): - if (not os.path.exists (path)): + if not os.path.exists (path): print "**** CRITICAL **** image in path", path, "doesn't exist!" - + return (None, None) + filename = getCoverArtFileName (album) thumbnail = getCoverArtThumbFileName (album) os.rename (path, filename) if (not self.__request_thumbnail (filename)): print "Something wrong creating the thumbnail!" - + return (filename, thumbnail) def __last_fm (self, artist, album): @@ -157,7 +162,8 @@ class MussorgskyAlbumArt: full_try = BASE_MSN + good_album + "+" + good_artist + MSN_MEDIUM + MSN_SQUARE print "Searching (album + artist): %s" % (full_try) result = self.__get_url (full_try) - return result + if (result.find ("no_results") == -1): + return result if (album): if (album.lower ().find ("greatest hit") != -1): @@ -167,13 +173,15 @@ class MussorgskyAlbumArt: album_try = BASE_MSN + good_album + MSN_MEDIUM + MSN_SQUARE print "Searching (album): %s" % (album_try) result = self.__get_url (album_try) - return result + if (result.find ("no_results") == -1): + return result if (artist): artist_try = BASE_MSN + good_artist + "+CD+music" + MSN_SMALL + MSN_SQUARE + MSN_PHOTO print "Searching (artist CD): %s" % (artist_try) result = self.__get_url (artist_try) - return result + if (result.find ("no_results") == -1): + return result return None