6 from urllib.error
import HTTPError
8 from html.parser
import HTMLParser
13 __title__ =
'lyricwiki'
17 LIC_TXT =
'we are not licensed to display the full lyrics for this song at the moment'
24 self.
url =
'http://lyrics.wikia.com/api.php?func=getSong&artist=%s&song=%s&fmt=realjson'
27 log(
'%s: searching lyrics for %s - %s' % (__title__, song.artist, song.title), debug=self.
DEBUG)
28 lyrics = Lyrics(settings=self.
settings)
30 lyrics.source = __title__
33 req = requests.get(self.
url % (urllib.parse.quote(song.artist), urllib.parse.quote(song.title)), timeout=10)
37 data = json.loads(response)
42 if not self.
page.endswith(
'action=edit'):
43 log(
'%s: search url: %s' % (__title__, self.
page), debug=self.
DEBUG)
45 req = requests.get(self.
page, timeout=10)
47 except requests.exceptions.HTTPError
as error:
48 if error.response.status_code == 404:
49 response = error.response.text
54 matchcode = re.search(
"class='lyricbox'>(.*?)<div", response)
56 lyricscode = (matchcode.group(1))
57 htmlparser = HTMLParser()
58 lyricstext = htmlparser.unescape(lyricscode).replace(
'<br />',
'\n')
59 lyr = re.sub(
'<[^<]+?>',
'', lyricstext)