Skip to content

Commit 085f39e

Browse files
committed
Formatting changeFormatting changes
1 parent 9e35cc0 commit 085f39e

15 files changed

+584
-663
lines changed

lLyrics/AZLyricsParser.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818

1919
import Util
2020

21+
2122
class Parser(object):
22-
2323
def __init__(self, artist, title):
2424
self.artist = artist
2525
self.title = title
2626
self.lyrics = ""
27-
27+
2828
def parse(self):
2929
# remove unwanted characters from artist and title strings
3030
clean_artist = self.artist
@@ -33,11 +33,11 @@ def parse(self):
3333
clean_artist = clean_artist.replace(" and ", "")
3434
clean_artist = clean_artist.replace(" ", "")
3535
clean_artist = Util.remove_punctuation(clean_artist)
36-
36+
3737
clean_title = self.title
3838
clean_title = clean_title.replace(" ", "")
3939
clean_title = Util.remove_punctuation(clean_title)
40-
40+
4141
# create lyrics Url
4242
url = "http://www.azlyrics.com/lyrics/" + clean_artist + "/" + clean_title + ".html"
4343
print("azlyrics Url " + url)
@@ -46,30 +46,29 @@ def parse(self):
4646
except:
4747
print("could not connect to azlyrics.com")
4848
return ""
49-
49+
5050
resp = Util.bytes_to_string(resp)
5151
self.lyrics = self.get_lyrics(resp)
5252
self.lyrics = string.capwords(self.lyrics, "\n").strip()
53-
53+
5454
return self.lyrics
55-
55+
5656
def get_lyrics(self, resp):
5757
# cut HTML source to relevant part
5858
start = resp.find("that. -->")
5959
if start == -1:
6060
print("lyrics start not found")
6161
return ""
62-
resp = resp[(start+9):]
62+
resp = resp[(start + 9):]
6363
end = resp.find("</div>")
6464
if end == -1:
6565
print("lyrics end not found ")
6666
return ""
67-
resp = resp[:(end-1)]
68-
67+
resp = resp[:(end - 1)]
68+
6969
# replace unwanted parts
7070
resp = resp.replace("<br>", "")
7171
resp = resp.replace("<i>", "")
7272
resp = resp.replace("</i>", "")
73-
73+
7474
return resp
75-

lLyrics/ChartlyricsParser.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@
2424

2525
import Util
2626

27+
2728
class Parser(HTMLParser):
28-
2929
def __init__(self, artist, title):
3030
HTMLParser.__init__(self)
3131
self.artist = artist
3232
self.title = title
3333
self.tag = None
3434
self.correct = True
3535
self.lyrics = ""
36-
36+
3737
# define handler for parsing
3838
def handle_starttag(self, tag, attrs):
3939
self.tag = tag
40-
40+
4141
# definde handler for parsing
4242
def handle_endtag(self, tag):
4343
self.tag = None
44-
44+
4545
# definde handler for parsing
4646
def handle_data(self, data):
4747
if self.tag == "lyricsong":
@@ -54,20 +54,20 @@ def handle_data(self, data):
5454
return
5555
if self.correct and self.tag == "lyric":
5656
self.lyrics = data
57-
57+
5858
def parse(self):
5959
# API searchLyric request
60-
url = "http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=" + urllib.parse.quote(self.artist) + "&song=" + urllib.parse.quote(self.title)
60+
url = "http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=" + urllib.parse.quote(
61+
self.artist) + "&song=" + urllib.parse.quote(self.title)
6162
print("call chartlyrics API: " + url)
6263
try:
6364
resp = urllib.request.urlopen(url, None, 3).read()
6465
except:
6566
print("could not connect to chartlyric.com API")
66-
67+
6768
resp = Util.bytes_to_string(resp)
6869
self.feed(resp)
69-
70+
7071
self.lyrics = string.capwords(self.lyrics, "\n").strip()
71-
72+
7273
return self.lyrics
73-

0 commit comments

Comments
 (0)