def show_disc_cover(self, bean=None): if not bean: bean = self.bean if bean.UUID != self.bean.UUID: return dict = FCache().covers """update image""" if not bean.image: if not os.path.isdir(COVERS_DIR): os.mkdir(COVERS_DIR) list_images = os.listdir(COVERS_DIR) """remove extra keys""" for key in dict.keys(): if (key + ".jpg") not in list_images: del dict[key] """remove extra files""" for file in list_images: if os.path.splitext(file)[0] not in dict.keys() and os.path.isfile(os.path.join(COVERS_DIR, file)): os.remove(os.path.join(COVERS_DIR, file)) for list, key in zip(dict.values(), dict.keys()): if bean.text in list: bean.image = os.path.join(COVERS_DIR, key + ".jpg") break if not bean.image: """get image url""" bean.image = self.controls.lastfm_service.get_album_image_url(bean.artist, bean.title) if not bean.image: logging.warning( """""Can't get cover image. Check the correctness of the artist's name and track title""" "" ) """make .jpg image and store it in cache""" if bean.image and bean.image.startswith("http://"): url_basename = os.path.splitext(os.path.basename(bean.image))[0] if dict.has_key(url_basename): dict[url_basename].append(bean.text) else: dict[url_basename] = [bean.text] self.image.get_pixbuf().save(os.path.join(COVERS_DIR, url_basename + ".jpg"), "jpeg", {"quality": "90"}) if bean.UUID == self.bean.UUID: self.image.update_info_from(bean) self.controls.trayicon.update_info_from(bean) self.controls.coverlyrics.set_cover()
def show_disc_cover(self): bean = self.bean dict = FCache().covers """update image""" if not bean.image: if not os.path.isdir(COVERS_DIR): os.mkdir(COVERS_DIR) list_images = os.listdir(COVERS_DIR) '''remove extra keys''' for key in dict.keys(): if (key + '.jpg') not in list_images: del dict[key] '''remove extra files''' for file in list_images: if os.path.splitext(file)[0] not in dict.keys(): os.remove(os.path.join(COVERS_DIR, file)) for list, key in zip(dict.values(), dict.keys()): if bean.text in list: bean.image = os.path.join(COVERS_DIR, key + ".jpg") break if not bean.image: '''get image url''' bean.image = self.controls.lastfm_service.get_album_image_url( bean.artist, bean.title) self.image.update_info_from(bean) if not bean.image: logging.warning( """""Can't get cover image. Check the correctness of the artist's name and track title""" "") '''make .jpg image and store it in cache''' if bean.image and bean.image.startswith("http://"): url_basename = os.path.splitext(os.path.basename(bean.image))[0] if dict.has_key(url_basename): dict[url_basename].append(bean.text) else: dict[url_basename] = [bean.text] self.image.get_pixbuf().save( os.path.join(COVERS_DIR, url_basename + '.jpg'), "jpeg", {"quality": "90"}) self.controls.trayicon.update_info_from(bean) self.controls.coverlyrics.set_cover()