Fix crash when lyrics not yet released on Genius

There are some tracks on Genius whose lyrics are yet to be released.
When the tool previously attempted to scrape such webpages, it
resulted in a crash.
The tool will now raise an exception; LyricNotFoundError when such a
track is encountered, which is then handled internally by the tool.

Example of one such track on Genius:
https://genius.com/The-federal-empire-good-man-lyrics

Fixes #647.
This commit is contained in:
Ritiek Malhotra
2020-01-10 15:33:02 +05:30
parent e47744f99c
commit c73f55b8ce

View File

@@ -37,8 +37,10 @@ class Genius(LyricBase):
def _get_lyrics_text(self, html):
soup = BeautifulSoup(html, "html.parser")
lyrics_paragraph = soup.find("p")
lyrics = lyrics_paragraph.get_text()
return lyrics
if lyrics_paragraph:
return lyrics_paragraph.get_text()
else:
raise LyricsNotFound("The lyrics for this track are yet to be released.")
def get_lyrics(self, linesep="\n", timeout=None):
url = self._guess_lyric_url()