def show_similar_lyrics(self, bean=None): if not bean: bean = self.bean if bean.UUID != self.bean.UUID: return if self.info_cache.lyric_bean == bean: return None self.info_cache.lyric_bean = bean """lyrics""" if not os.path.isdir(LYRICS_DIR): os.mkdir(LYRICS_DIR) lyrics_list = os.listdir(LYRICS_DIR) lyrics_title = "*** %s - %s *** \n" % (bean.artist, bean.title) text = None if lyrics_title in lyrics_list: text = "".join(open(os.path.join(LYRICS_DIR, lyrics_title), 'r').readlines()) else: try: logging.debug("Try to get lyrics from lyrics.wikia.com") text = get_lyrics(bean.artist, bean.title) except: logging.info("Error occurred when getting lyrics from lyrics.wikia.com") if not text: text = get_lyrics_by_parsing(bean.artist, bean.title) if text: open(os.path.join(LYRICS_DIR, lyrics_title), 'w').write(text) else: logging.info("The text not found") text = "The text not found" if bean.UUID == self.bean.UUID: self.lyrics.set_text(text, lyrics_title) self.controls.coverlyrics.lyrics.set_text(text, lyrics_title)
def show_similar_lyrics(self): if self.info_cache.lyric_bean == self.bean: return None self.info_cache.lyric_bean = self.bean """lyrics""" text = get_lyrics(self.bean.artist, self.bean.title) lyrics_title = "*** %s - %s *** \n" % (self.bean.artist, self.bean.title) self.lyrics.set_text(text, lyrics_title)
def show_similar_lyrics(self, bean=None): if not bean: bean = self.bean if not bean: return if bean.UUID != self.bean.UUID: return """lyrics""" if not os.path.isdir(LYRICS_DIR): os.mkdir(LYRICS_DIR) cache_name = lyrics_title = "%s - %s" % (bean.artist, bean.title) illegal_chars = ["/", "#", ";", ":", "%", "*", "&", "\\"] for char in illegal_chars: cache_name = cache_name.replace(char, "_") cache_name = cache_name.lower().strip() text = None if os.path.exists(os.path.join(LYRICS_DIR, cache_name)): with open(os.path.join(LYRICS_DIR, cache_name), 'r') as cache_file: text = "".join(cache_file.readlines()) else: self.lyrics.set_text(_("Loading..."), lyrics_title) try: logging.debug("Try to get lyrics from lyrics.wikia.com") text = get_lyrics(bean.artist, bean.title) except: logging.info( "Error occurred when getting lyrics from lyrics.wikia.com") if not text: text = get_lyrics_by_parsing(bean.artist, bean.title) if text: with open(os.path.join(LYRICS_DIR, cache_name), 'w') as cache_file: cache_file.write(text) else: logging.info("The text not found") text = _("The text not found") if bean.UUID == self.bean.UUID: self.set_lyrics(text, lyrics_title)
def show_similar_lyrics(self, bean=None): if not bean: bean = self.bean if not bean: return if bean.UUID != self.bean.UUID: return """lyrics""" if not os.path.isdir(LYRICS_DIR): os.mkdir(LYRICS_DIR) cache_name = lyrics_title = "%s - %s" % (bean.artist, bean.title) illegal_chars = ["/", "#", ";", ":", "%", "*", "&", "\\"] for char in illegal_chars: cache_name = cache_name.replace(char, "_") cache_name = cache_name.lower().strip() text = None if os.path.exists(os.path.join(LYRICS_DIR, cache_name)): with open(os.path.join(LYRICS_DIR, cache_name), 'r') as cache_file: text = "".join(cache_file.readlines()) else: self.lyrics.set_text(_("Loading..."), lyrics_title) try: logging.debug("Try to get lyrics from lyrics.wikia.com") text = get_lyrics(bean.artist, bean.title) except: logging.info("Error occurred when getting lyrics from lyrics.wikia.com") if not text: text = get_lyrics_by_parsing(bean.artist, bean.title) if text: with open(os.path.join(LYRICS_DIR, cache_name), 'w') as cache_file: cache_file.write(text) else: logging.info("The text not found") text = _("The text not found") if bean.UUID == self.bean.UUID: self.set_lyrics(text, lyrics_title)
def show_similar_lyrics(self): if self.info_cache.lyric_bean == self.bean: return None self.info_cache.lyric_bean = self.bean """lyrics""" if not os.path.isdir(LYRICS_DIR): os.mkdir(LYRICS_DIR) lyrics_list = os.listdir(LYRICS_DIR) lyrics_title = "*** %s - %s *** \n" % (self.bean.artist, self.bean.title) if lyrics_title in lyrics_list: text = "".join(open(os.path.join(LYRICS_DIR, lyrics_title), 'r').readlines()) else: text = get_lyrics(self.bean.artist, self.bean.title) if text: open(os.path.join(LYRICS_DIR, lyrics_title), 'w').write(text) else: text = "The text not found" self.lyrics.set_text(text, lyrics_title) self.controls.coverlyrics.lyrics.set_text(text, lyrics_title)