Skip to content

Instantly share code, notes, and snippets.

@blha303
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save blha303/37f5a628da1b2ef36bb2 to your computer and use it in GitHub Desktop.

Select an option

Save blha303/37f5a628da1b2ef36bb2 to your computer and use it in GitHub Desktop.
Opens a webbrowser with the azlyrics page for the now-playing song
import pylast, webbrowser, re, sys
key = "9eefecb15b3891540eb66748f37bf539"
use = sys.argv[1] if len(sys.argv) > 1 else "blha303"
def strip(string):
return re.sub(r'[\W_]+', '', string.replace("&", " and "))
lfm = pylast.LastFMNetwork(api_key=key, username=use)
track = lfm.get_user(use).get_now_playing()
if track:
webbrowser.open("http://www.azlyrics.com/lyrics/{}/{}.html".format(strip(str(track.artist).lower()),
strip(str(track.title).lower())
))
else:
webbrowser.open("data:text/html,You don't have a track playing according to last.fm.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment