import threading
class AADownloadThread (threading.Thread):
- def __init__ (self, url, counter):
+ def __init__ (self, url, artist, album, counter):
threading.Thread.__init__ (self, target=self.grab_image, args=(url,))
self.thumbnailer = LocalThumbnailer ()
self.counter = counter
+ self.artistName = artist.replace (" ", "_")
+ self.albumName = album.replace (" ", "_")
self.image_path = None
self.thumb_path = None
self.urllib_wrapper = UrllibWrapper ()
print "Working", self.counter
image = self.urllib_wrapper.get_url (image_url)
if (image):
- self.image_path = os.path.join (CACHE_LOCATION, "alternative-" + str(self.counter))
- self.thumb_path = os.path.join (CACHE_LOCATION, "alternative-" + str(self.counter) + "thumb")
+ self.image_path = os.path.join (CACHE_LOCATION, self.artistName + self.albumName + str(self.counter))
+ self.thumb_path = os.path.join (CACHE_LOCATION, self.artistName + self.albumName + str(self.counter) + "thumb")
self.urllib_wrapper.save_content_into_file (image, self.image_path)
self.thumbnailer.create (self.image_path, self.thumb_path)
return a list of paths of possible album arts
"""
results_page = self.__msn_images (artist, album)
- return self.__process_results_page (results_page, max_alternatives)
+ return self.__process_results_page (results_page, artist, album, 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):
+ def __process_results_page (self, results_page, artist, album, max_alternatives):
counter = 0
threads = []
for image_url in self.__get_url_from_msn_results_page (results_page):
if (counter >= max_alternatives):
break
- t = AADownloadThread (image_url, counter)
+ t = AADownloadThread (image_url, artist, album, counter)
t.start ()
threads.append (t)
counter += 1
def save_alternative (self, artist, album, img_path, thumb_path):
+ """
+ This is done now in the controller
+ """
if not os.path.exists (img_path) or not os.path.exists (thumb_path):
print "**** CRITICAL **** image in path", path, "doesn't exist!"
return (None, None)