Skip to content

Commit

Permalink
Make new version of Genius work
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRu committed May 16, 2020
1 parent f2ec7cb commit 097c0c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

name = "lyrics"
description = "Get the lyrics from a Spotify song in the terminal"
__version__ = "1.2.4"
__version__ = "1.2.5"


watch_timeout = 3
Expand Down
30 changes: 21 additions & 9 deletions lib/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def get_page_title(page):
song_artist_elements = page.select(
".header_with_cover_art-primary_info-primary_artist")

if (len(song_name_elements) == 0 or len(song_artist_elements) == 0):
song_name_elements = page.select(
"h1[class*=SongHeader__Title]")
song_artist_elements = page.select(
"a[class*=SongHeader__Artist]")

if (len(song_name_elements) == 0 or len(song_artist_elements) == 0):
return None

Expand All @@ -90,12 +96,18 @@ def get_page_title(page):

def get_page_lyrics(page):
full_text_elements = page.select("div.lyrics")

if (len(full_text_elements) == 0):
return None

text = full_text_elements[0].text
text = text.replace("More on Genius", "").strip()
text = re.sub("\n\n(\n+)", "\n\n", text)

return text
if (len(full_text_elements) > 0):
text = full_text_elements[0].text
text = text.replace("More on Genius", "").strip()
text = re.sub("\n\n(\n+)", "\n\n", text)
return text

full_text_elements = page.select("div[class*=Lyrics__Container]")
if (len(full_text_elements) > 0):
text = '\n'.join([str(f) for f in full_text_elements])
text = text.replace('<br/>', '\n')
text = BeautifulSoup(text, "html.parser").text
text = text.replace("More on Genius", "").strip()
return text

return None

0 comments on commit 097c0c3

Please sign in to comment.