Last active 1444397284

Lyrics getter

Revision 086a0d3410d7fcfab89d01eaefb30e669bf3d9f7

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;")
7artist = re.search(r'ArtistName = "(.*?)"', a).group(1)
8title = re.search(r'SongName = "(.*?)"', a).group(1)
9if not b:
10 print "Song not found :/"
11 sys.exit
12c = str(b).replace("[<div", "<div")
13c = c.replace("</div>]", "</div>")
14try:
15 file = open(artist + " - " + title + ".html", "w")
16except IndexError:
17 print "Song name not in correct format: artistname/songname"
18 print "Example: amateurtransplants/londonunderground"
19 sys.exit
20file.write(c)
21file.close()
22print "Success. Lyrics written to " + file.name