Last active 1444397284

Lyrics getter

Revision 649f8b84f77348808970cf29825bc3d9641077ef

lyrics.py Raw
1import urllib,re,sys;
2from BeautifulSoup import BeautifulSoup
3inp = str(sys.argv[1])
4a = urllib.urlopen("http://www.azlyrics.com/lyrics/" + inp + ".html").read()
5soup = BeautifulSoup(a)
6b = soup.findAll(style="margin-left:10px;margin-right:10px;")
7try:
8 artist = re.search(r'ArtistName = "(.*?)"', a).group(1)
9except AttributeError:
10 print "Song lookup failed."
11 print "It is possible that:"
12 print "Song name not in correct format: artistname/songname"
13 print "Example: amateurtransplants/londonunderground"
14 sys.exit()
15title = re.search(r'SongName = "(.*?)"', a).group(1)
16c = str(b).replace("[<div", "<div")
17c = c.replace("</div>]", "</div>")
18file = open(artist + " - " + title + ".html", "w")
19file.write(c)
20file.close()
21print "Success. Lyrics written to " + file.name