def test_get_lyrics(): info = {'artist': 'Evanescence', 'title': 'Snow White Queen'} c = ChartLyrics() lyrics = c.search(info) assert lyrics log.info("lyrics: %s" % lyrics)
def get_lyrics(lid, nocache=False, info=None): lyrics_path = os.path.join("/", app.iposonic.cache_dir, "%s.lyr" % lid) try: with open(lyrics_path, "rb") as f: ret = f.read() if ret: return {'lyrics': ret} except IOError: pass # if the entry is not in cache, search the web log.warn("cannot find lyrics on cache") assert info, "Bad call of get_lyrics without info argument" c = ChartLyrics() ret = c.search(info) with open(lyrics_path, "wb") as f: f.write(ret.get('lyrics').encode('utf-8')) return ret