Skip to content

Commit

Permalink
Merge branch 'eeishaan-patch-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwmillr committed Sep 20, 2020
2 parents 74eae9f + cb3f5d1 commit 6304fdb
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lyricsgenius/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,25 +385,17 @@ def _scrape_song_lyrics_from_url(self, url):

# Determine the class of the div
old_div = html.find("div", class_="lyrics")

if old_div:
lyrics = old_div.get_text()
else:
lyrics = ''
for tag in html.find_all('div'):
for attribute, value in list(tag.attrs.items()):
if attribute == 'class' and 'Lyrics__Root' in str(value):
lyrics = tag
break
if lyrics:
break
new_div = html.find("div", class_=re.compile("Lyrics__Root"))
if new_div:
lyrics = new_div.get_text('\n').replace('\n[', '\n\n[')
else:
if self.verbose:
print("Couldn't find the lyrics section.")
return None

lyrics = lyrics.get_text('\n').replace('\n[', '\n\n[')

if self.remove_section_headers: # Remove [Verse], [Bridge], etc.
lyrics = re.sub(r'(\[.*?\])*', '', lyrics)
lyrics = re.sub('\n{2}', '\n', lyrics) # Gaps between verses
Expand Down

0 comments on commit 6304fdb

Please sign in to comment.