def test_useless_are_not_called(self): '''Retrievers which don't provide requested data are not called''' pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(Trackable) get_lyrics.get_lyrics('a', 'b', request=('foo',), timeout=0.3) time.sleep(0.2) assert Trackable.called == False
def test_noone_is_fast_enough(self): '''when no retriever is fast enough, (None, None) should be returned''' pluginsystem.register_plugin(Slow) res = get_lyrics.get_lyrics('a', 'b', request=('foo',), timeout=0.2) print 'NOONE', res assert res is None
def test_slow_if_no_matches(self): '''when no matches are found, slowness is ok''' pluginsystem.register_plugin(Slow) start = time.time() res = get_lyrics.get_lyrics('a', 'b', request=('foo',), analyzer='first_match') assert time.time() - start > 1.0
def test_no_extra(self): '''Don't return anything that is not requested''' pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(QuickBar) res = get_lyrics.get_lyrics('a', 'b', request=('foo',)) print 'result', res assert 'foo' in res assert 'bar' not in res
def test_best_found(self): '''first_match must found the "best", even if not perfect''' pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(QuickBar) res = get_lyrics.get_lyrics('a', 'b', request=('foo', 'bar'), timeout=0.5) assert 'bar' in res assert 'foo' not in res
def test_slow_if_no_matches(self): "when no matches are found, slowness is ok" pluginsystem.register_plugin('slow', Slow) pluginsystem.register_plugin('quick', Quick) start = time.time() res = get_lyrics.get_lyrics('a', 'b', request=('donthaveit'), analyzer='first_match') assert time.time() - start > 1.0
def songs(): #words = get_lyrics("billie jean") song_original_lyrics = get_lyrics(request.form["search-bar"]) song_new_lyrics = read_lyrics(request.form["search-bar"]) return render_template('songs.html', old_lyrics=song_original_lyrics, new_lyrics=song_new_lyrics, song_title=request.form["search-bar"])
def test_timeout(self): '''Timeout must do its job''' pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(Quick) start = time.time() res = get_lyrics.get_lyrics('a', 'b', request=('donthaveit'), timeout=1) assert time.time() - start < 2.0
def test_first_match(self): '''first match analyzer should choose the quickest, and do it quick''' #TODO: change to a more explicit, analyzer-choosing API pluginsystem.register_plugin(Quick) pluginsystem.register_plugin(Slow) res = get_lyrics.get_lyrics('a', 'b', request=('foo',), analyzer='first_match') assert res['foo'] == 'quick foo'
def test_first_advanced_match(self): '''first match should "compose" results''' pluginsystem.register_plugin(Quick) pluginsystem.register_plugin(QuickBar) res = get_lyrics.get_lyrics('a', 'b', request=('foo', 'bar'), analyzer='first_match') assert 'bar' in res assert res['bar'] == 'quickBar bar' assert 'foo' in res assert res['foo'] == 'quick foo'
def lyrics(): '''Retrieve lyrics for the current track''' title = sonos_actions.current()['title'] artist = sonos_actions.current()['artist'] lyrics = get_lyrics(artist, title) click.secho(f"\n{title} by {artist}", fg='cyan', bold=True, nl=False) if not lyrics: click.echo("Couldn't retrieve lyrics") else: click.echo(lyrics)
def get_all_lyrics(artists, filename): lyrics = '' for artist in artists: print('>>> Collecting lyrics of: ' + artist + '...') lyrics += get_lyrics.get_lyrics(artist) file = open(filename, 'w+', encoding='utf-8') lyrics = lyrics.replace(' \n ', '\n') file.write(lyrics) file.close() print('>>> Done collecting lyrics.')
def set_lyrics(path): tags = ID3(path) lyrics = get_lyrics(tags['TIT2'].text[0], tags['TPE1'].text[0]) fin_lyr = None for lyric in lyrics: if bool(re.match(tags['TIT2'].text[0], lyric[1]['song']['title'])): fin_lyr = lyric[0] tags[u"USLT"] = USLT(encoding=3, lang=u'eng', desc=u'desc', text=fin_lyr) tags.save()
position = track.get('position', 0) if prev_title != title: screen_rows = get_screen_size().rows need_scroll = False duration = track.get('duration', 0) artist = track.get('artist', '') prev_title = title sys.stdout.write("\x1b[2J") #erase screen, go home sys.stdout.write("\x1b[H") sys.stdout.flush() lyrics = get_lyrics(artist, title) if not lyrics: print("Couldn't retrieve lyrics") continue line_count = lyrics.count('\n') if screen_rows - 3 > line_count: print(f"\n\x1b[0;31m{title} by {artist} page: 1/1\x1b[0m", end="") print(lyrics) else: pages = int(line_count/screen_rows) + 1 char = findnth(lyrics, '\n', screen_rows - 3) prev_char = char n = 2 last_position = 0 print(f"\n\x1b[0;31m{title} by {artist} page: 1/{pages}\x1b[0m", end="")
continue if prev_track != track: data = {"header":f"{artist}-{track}", "text":f"<bodyItalic>Looking for lyrics to {track}</bodyItalic>"} try: publish_lyrics(payload=json.dumps(data)) except Exception as e: print(e) prev_track = track if not track: continue lyrics = get_lyrics(artist, track) if not lyrics: # previously was erasing lyrics when no lyrics -- need to revisit 04192019 data = {"header":f"{artist}-{track}", "text":f"<bodyItalic>Could not find the lyrics to {track}</bodyItalic>"} publish_lyrics(payload=json.dumps(data)) continue data = {"header":f"{artist}<br/>{track}", "text":f"<lyrics>{lyrics}</lyrics>"} try: publish_lyrics(payload=json.dumps(data)) except Exception as e: print(e) t1 = time() print(t1) sonos_status[0] = 'PLAYING' # if we switched the picture and posted lyrics we're playing because there may be a lag in getting state/status info
def setLyric(self, lyric): self.lyrics = get_lyrics(lyric)
def GET(self): self.cache_key = None self.lyric = "" self.words = None self.error = None self.photos = [] obj = videclipr() data = web.input() query = data.get("q") next_song = int(data.get('next', 0)) print "Finding track %s" % query results = pyella.search_tracks(query, "fulltracks").get_next_page() print results print len(results) if results: if next_song > len(results) - 1: next_song = 0 print "Ela results " ,len(results), next_song track = results[next_song] self.cache_key = str(track.get_id()) if self.cache_key in cache: return cache[self.cache_key] print track.get_mbid(), track.get_title(), track.get_artist_name() print track.get_attribute("rhythm_bpm_value") print track.get_audio() obj.title = track.get_title() obj.artist = track.get_artist_name() obj.bpm = track.get_attribute("rhythm_bpm_value")[0][1:] obj.audio = track.get_audio() obj.isrc = track.get_attribute("track_isrc") obj.duration = track.get_attribute('track_duration') print obj.isrc obj.label = track.get_attribute("track_label") print obj.label obj.cover = track.get_image() links = track.get_links() mblink = links[3][1] if mblink: #Here we have the MusicBrainz ID mbid = get_mbi_from_url(mblink) self.lyric = get_musixmatch_lyric(mbid) #print self.lyric obj.setLyric(self.lyric) else: #print "No MusicBrainz ID found... trying with musixmatch" self.lyric = get_musixmatch_lyric_by_query(track.get_title()) obj.setLyric(self.lyric) else: self.error = "Music not found in ELLA! Please try another song" if not self.lyric: self.error = "Can't found lyrics for this song. :(" if self.lyric: self.time_lyrics = get_lyrics(self.lyric) self.keywords = get_keywords(self.lyric) self.image_lyrics = get_image_lyrics(self.keywords, self.time_lyrics) #self.words = get_words(self.lyric) #self.lyric = re.sub(r"\n", "<br/>", self.lyric) self.photos = [] #self.lyrics = get_lyrics(self.lyric) #for count, key in enumerate(self.words): # word = self.words[key][0][0] # print "Finding photos for word %s" % word # phs = gd_client.SearchCommunityPhotos(word, limit='20') # photos_array = [p.content.src for p in phs.entry] # #photos_array = search_images(word) for i, item in enumerate(self.image_lyrics): keyword = item[1] #print 'keyword:', keyword #phs = gd_client.SearchCommunityPhotos(keyword, limit='1') #self.photos.extend([p.content.src for p in phs.entry]) rand = False if not keyword: keyword = track.get_title() + ' ' + track.get_artist_name() rand = True print "Searching for %s" % keyword #if i > 25: # break photos = search_images(keyword, rand) #random.shuffle(photos_array) self.photos.append([item[0], photos]) obj.set_photos(self.photos) #main = unicode(render.main(self)) #return return_composite_parts(main) j = obj.toJSON() cache[self.cache_key] = j; return j
data = { "header": f"{artist}-{track}<br/>", "text": f"Looking for lyrics to {track}" } try: publish_lyrics(payload=json.dumps(data)) except Exception as e: print(e) prev_track = track if not track: continue lyrics = get_lyrics(artist, track) if not lyrics: # previously was erasing lyrics when no lyrics -- need to revisit 04192019 data = { "header": f"{artist}-{track}<br/>", "text": f"Could not find the lyrics to {track}" } publish_lyrics(payload=json.dumps(data)) continue text = lyrics.replace("\n", "<br/>") data = {"header": f"{artist}<br/>{track}", "text": text} try: publish_lyrics(payload=json.dumps(data)) except Exception as e:
if len(sys.argv) == 2: file_path = sys.argv[1] print('Loading lyrics...') try: with open(file_path, 'r') as f: lyrics = f.read() except: print('Bad input file path: ' + file_path) sys.exit() elif len(sys.argv) == 3: artist = sys.argv[1] song_title = sys.argv[2] print('Downloading lyrics...') lyrics = get_lyrics(artist, song_title) if not lyrics: print('We couldn\'t find the song you specified.') sys.exit() else: print( 'Please specify path to a lyrics file or artist with song title to download lyrics.' ) sys.exit() score = predict(cond_prob, prior, lyrics) print('Most probable genre: ' + min(score, key=score.get))
def test_first_dont_match(self): '''first match should not match results that don't satisfies request''' pluginsystem.register_plugin(Quick) res = get_lyrics.get_lyrics('a', 'b', request=('donthaveit',), analyzer='first_match') assert res == None
def test_bad_analyzer(self): get_lyrics.get_lyrics('a', 'b', analyzer='dontexist')
def test_all(self): pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(Quick) get_lyrics.get_lyrics('a', 'b', request=('foo',))
def test_select(self): pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(Quick) get_lyrics.get_lyrics('a', 'b', request=('foo',), plugin_filter=('quick',))
def test_error_handling(self): '''Even when retrievers raise, all is fine''' pluginsystem.register_plugin(Error) get_lyrics.get_lyrics('a', 'b')
def test_none(self): pluginsystem.register_plugin(Slow) get_lyrics.get_lyrics('a', 'b', request=('foo',), plugin_filter=())
import pandas as pd from get_songs import get_songs from get_lyrics import get_lyrics from settings import CLIENT_ACCESS_TOKEN HEADERS = {'Authorization': 'Bearer ' + CLIENT_ACCESS_TOKEN} KENDRICK_LAMAR_ID = "1421" KENDRICK_LAMAR = 'Kendrick Lamar' songs = get_songs(HEADERS, KENDRICK_LAMAR_ID, max_songs=1) lyrics = get_lyrics(songs, KENDRICK_LAMAR) df = pd.DataFrame(lyrics) df.to_csv('kendrick_lamar.csv') print(df.head())