Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of using LyricFind and Echo Nest to generate a playlist with lyrics
import sys
import urllib
import json
from pyechonest import playlist
def show_playlist(seed_artist):
for s in playlist.basic(artist=seed_artist, type='artist-radio', ]
buckets=['id:lyricfind-US'], results=10, limit=True):
print '=================================================================='
print s.title, 'by', s.artist_name
print '=================================================================='
show_lyrics(s)
def show_lyrics(s):
lfid = s.get_foreign_id('lyricfind-US').replace('lyricfind-US:song:', '')
url = 'http://test.lyricfind.com/api_service/lyric.do' + \
'?apikey=your_api_key' + \
'&reqtype=default&output=json&trackid=elid:' + lfid
f = urllib.urlopen(url)
js = f.read()
f.close()
dict = json.loads(js)
try:
lyrics = dict['track']['lyrics']
for line in lyrics.split('\r\n'):
print line
print
except:
print '(no lyrics)'
if __name__ == '__main__':
if len(sys.argv) > 1:
show_playlist(' '.join(sys.argv[1:]))
else:
print 'usage: %s artist name' % (sys.argv[0],)
@Khalian
Copy link

Khalian commented Dec 8, 2015

add these lines to your code

from pyechonest import config
config.ECHO_NEST_API_KEY="YOUR API KEY"

Btw your code does not work, i tried it with : python lyrical_playlist.py queen

And it gives songs that have nothing to do with queen e.g.

Walk Of Life by Dire Straits

http://test.lyricfind.com/api_service/lyric.do?apikey=K54MGT0TONSDQDKXE&reqtype=default&output=json&trackid=elid:02c2d35016bb14a6517c0f12551bf169
(no lyrics)

and none of the output actually lists a lyrics.

Please post working examples next time you submit some code for public consumption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment