replace_br function added to reduce code duplication
@@ -387,6 +387,10 @@ class Genius(Backend):
except ValueError:
return None
+ def replace_br(self, lyrics_div):
+ for br in lyrics_div.find_all("br"):
+ br.replace_with("\n")
+
def _scrape_lyrics_from_html(self, html):
"""Scrape lyrics from a given genius.com html"""
@@ -405,8 +409,7 @@ class Genius(Backend):
lyrics_div = soup.find("div", {"data-lyrics-container": True})
if lyrics_div:
- for br in lyrics_div.find_all("br"):
- br.replace_with("\n")
+ self.replace_br(lyrics_div)
if not lyrics_div:
self._log.debug('Received unusual song page html')
@@ -423,8 +426,7 @@ class Genius(Backend):
return None
lyrics_div = verse_div.parent
- for br in lyrics_div.find_all("br"):
- br.replace_with("\n")
+ self.replace_br(lyrics_div)
ads = lyrics_div.find_all("div",
class_=re.compile("InreadAd__Container"))
