Preparing 0.5.2-2 release
[mussorgsky] / src / album_art_thread.py
index 2b2dc25..13d3a06 100755 (executable)
@@ -113,8 +113,15 @@ class MussorgskyAlbumArt:
         """
         return a list of paths of possible album arts
         """
-        counter = 0
         results_page = self.__msn_images (artist, album)
+        return self.__process_results_page (results_page, max_alternatives)
+
+    def get_alternatives_free_text (self, search_text, max_alternatives=4):
+        results_page = self.__msn_images_free_text (search_text)
+        return self.__process_results_page (results_page, max_alternatives)
+
+    def __process_results_page (self, results_page, max_alternatives):
+        counter = 0
         threads = []
         for image_url in self.__get_url_from_msn_results_page (results_page):
             if (not image_url):
@@ -161,7 +168,7 @@ class MussorgskyAlbumArt:
 
         good_artist = self.__clean_string_for_search (artist)
         good_album = self.__clean_string_for_search (album)
-
+        
         if (good_album and good_artist):
             full_try = BASE_MSN + good_album + "+" + good_artist + MSN_MEDIUM + MSN_SQUARE
             print "Searching (album + artist): %s" % (full_try)
@@ -189,9 +196,13 @@ class MussorgskyAlbumArt:
         
         return None
 
+    def __msn_images_free_text (self, search_text):
+        full_try = BASE_MSN + self.__clean_string_for_search (search_text) + MSN_MEDIUM + MSN_SQUARE
+        result = self.urllib_wrapper.get_url (full_try)
+        return result
+    
 
     def __get_url_from_msn_results_page (self, page):
-
         if (not page):
             return
 
@@ -201,11 +212,11 @@ class MussorgskyAlbumArt:
         # 500 is just a safe limit
         for i in range (0, 500):
             # Iterate until find a jpeg
-            start = page.find ("furl=", starting_at)
+            start = page.find ("imgurl:"", starting_at)
             if (start == -1):
                 yield None
-            end = page.find ("\"", start + len ("furl="))
-            current_option = page [start + len ("furl="): end].replace ("amp;", "")
+            end = page.find ("&", start + len ("imgurl:""))
+            current_option = page [start + len ("imgurl:""): end].replace ("amp;", "")
             if (current_option.lower().endswith (".jpg") or
                 current_option.lower().endswith (".jpeg")):
                 yield current_option