Created
February 17, 2012 20:46
-
-
Save plamere/1855349 to your computer and use it in GitHub Desktop.
Example of using LyricFind and Echo Nest to generate a playlist with lyrics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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],) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.