Comply with PEP8
@@ -336,7 +336,10 @@ class MusiXmatch(SymbolsReplaced):
class Genius(Backend):
"""Fetch lyrics from Genius via genius-api.
- Simply adapted from https://bigishdata.com/2016/09/27/getting-song-lyrics-from-geniuss-api-scraping/"""
+
+ Simply adapted from
+ bigishdata.com/2016/09/27/getting-song-lyrics-from-geniuss-api-scraping/
+ """
base_url = "https://api.genius.com"
@@ -353,14 +356,19 @@ class Genius(Backend):
response = requests.get(song_url, headers=self.headers)
json = response.json()
path = json["response"]["song"]["path"]
- #gotta go regular html scraping... come on Genius
+
+ # Gotta go regular html scraping... come on Genius.
page_url = "https://genius.com" + path
page = requests.get(page_url)
html = BeautifulSoup(page.text, "html.parser")
- #remove script tags that they put in the middle of the lyrics
+
+ # Remove script tags that they put in the middle of the lyrics.
[h.extract() for h in html('script')]
- #at least Genius is nice and has a tag called 'lyrics'!
- lyrics = html.find("div", class_="lyrics").get_text() #updated css where the lyrics are based in HTML
+
+ # At least Genius is nice and has a tag called 'lyrics'!
+ # Updated css where the lyrics are based in HTML.
+ lyrics = html.find("div", class_="lyrics").get_text()
+
return lyrics
def fetch(self, artist, title):
@@ -374,6 +382,7 @@ class Genius(Backend):
if hit["result"]["primary_artist"]["name"] == artist:
song_info = hit
break
+
if song_info:
song_api_path = song_info["result"]["api_path"]
return self.lyrics_from_song_api_path(song_api_path)
