Steven Smith revised this gist . Go to revision
1 file changed, 2 insertions, 2 deletions
lfm_getlyrics.py
| @@ -1,7 +1,7 @@ | |||
| 1 | - | import pylast, webbrowser, urllib, re | |
| 1 | + | import pylast, webbrowser, re, sys | |
| 2 | 2 | ||
| 3 | 3 | key = "9eefecb15b3891540eb66748f37bf539" | |
| 4 | - | use = "blha303" | |
| 4 | + | use = sys.argv[1] if len(sys.argv) > 1 else "blha303" | |
| 5 | 5 | ||
| 6 | 6 | def strip(string): | |
| 7 | 7 | return re.sub(r'[\W_]+', '', string.replace("&", " and ")) | |
Steven Smith revised this gist . Go to revision
1 file changed, 16 insertions
lfm_getlyrics.py(file created)
| @@ -0,0 +1,16 @@ | |||
| 1 | + | import pylast, webbrowser, urllib, re | |
| 2 | + | ||
| 3 | + | key = "9eefecb15b3891540eb66748f37bf539" | |
| 4 | + | use = "blha303" | |
| 5 | + | ||
| 6 | + | def strip(string): | |
| 7 | + | return re.sub(r'[\W_]+', '', string.replace("&", " and ")) | |
| 8 | + | ||
| 9 | + | lfm = pylast.LastFMNetwork(api_key=key, username=use) | |
| 10 | + | track = lfm.get_user(use).get_now_playing() | |
| 11 | + | if track: | |
| 12 | + | webbrowser.open("http://www.azlyrics.com/lyrics/{}/{}.html".format(strip(str(track.artist).lower()), | |
| 13 | + | strip(str(track.title).lower()) | |
| 14 | + | )) | |
| 15 | + | else: | |
| 16 | + | webbrowser.open("data:text/html,You don't have a track playing according to last.fm.") | |