From c0bb2ff2a175a4a5cce2db590d1d065c14475cd1 Mon Sep 17 00:00:00 2001 From: olgarrahan Date: Fri, 15 Apr 2022 16:37:05 -0400 Subject: [PATCH 1/4] Genius lyrics header bug fixed and updated test case for lyrics plugin --- beetsplug/lyrics.py | 8 +- .../lyrics/geniuscom/Ttngchinchillalyrics.txt | 864 ++++++++++++++++++ test/test_lyrics.py | 2 +- 3 files changed, 871 insertions(+), 3 deletions(-) create mode 100644 test/rsrc/lyrics/geniuscom/Ttngchinchillalyrics.txt diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 1f215df45..e73c3bc8a 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -401,7 +401,12 @@ class Genius(Backend): # all of the lyrics can be found already correctly formatted # Sometimes, though, it packages the lyrics into separate divs, most # likely for easier ad placement - lyrics_div = soup.find("div", class_="lyrics") + + lyrics_div = soup.find("div", {"data-lyrics-container": True}) + + for br in lyrics_div.find_all("br"): + br.replace_with("\n") + if not lyrics_div: self._log.debug('Received unusual song page html') verse_div = soup.find("div", @@ -429,7 +434,6 @@ class Genius(Backend): class_=re.compile("Lyrics__Footer")) for footer in footers: footer.replace_with("") - return lyrics_div.get_text() diff --git a/test/rsrc/lyrics/geniuscom/Ttngchinchillalyrics.txt b/test/rsrc/lyrics/geniuscom/Ttngchinchillalyrics.txt new file mode 100644 index 000000000..fa28a1b2a --- /dev/null +++ b/test/rsrc/lyrics/geniuscom/Ttngchinchillalyrics.txt @@ -0,0 +1,864 @@ + + + + TTNG – Chinchilla Lyrics | Genius Lyrics + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

🚧  The new song page is now the default experience! We need your help to continue improving contributor features.  🚧

+
So far we've lost focus
Let's just concentrate on words that could mean everything

On nights like this
We drink ourselves dry
And make promises
Without intention

So fortunate that this was brought up
The last time. As I recall
I can’t hold up your every expectation

On nights like this
We drink ourselves dry
And make promises
Without intention

My God, is this what we’ve become?
Living parodies of love and loss
Can we really be all that lost?

So fortunate that this was brought up
The last time. As I recall
I can’t hold up your every expectation

One moment to another I am restless
Seems making love forever can often risk your heart
And I cannot remember when I was this messed up
In service of another I am beautiful
How to Format Lyrics:
  • Type out all lyrics, even if it’s a chorus that’s repeated throughout the song
  • The Section Header button breaks up song sections. Highlight the text then click the link
  • Use Bold and Italics only to distinguish between different singers in the same verse.
    • E.g. “Verse 1: Kanye West, Jay-Z, Both
  • Capitalize each line
  • To move an annotation to different lyrics in the song, use the [...] menu to switch to referent editing mode

About

This song bio is unreviewed
Genius Annotation

This song is about those relationships with a lot of fights and reconciliations. The singer and his couple are aruging/reconciliating, telling themselves everything is going to be better and things will change for good, specially when they get drunk, just to fight and reconciliate over and over again.

Ask us a question about this song
No questions asked yet
Credits
Written By
Stuart Smith
Release Date
October 13, 2008
Tags
Comments
Add a comment
Get the conversation started
Be the first to comment
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/test_lyrics.py b/test/test_lyrics.py index 3adf6e359..57f5ce13d 100644 --- a/test/test_lyrics.py +++ b/test/test_lyrics.py @@ -457,7 +457,7 @@ class GeniusScrapeLyricsFromHtmlTest(GeniusBaseTest): def test_good_lyrics(self): """Ensure we are able to scrape a page with lyrics""" - url = 'https://genius.com/Wu-tang-clan-cream-lyrics' + url = 'https://genius.com/Ttng-chinchilla-lyrics' mock = MockFetchUrl() self.assertIsNotNone(genius._scrape_lyrics_from_html(mock(url))) From 16d74bafc3ab5c9837950718a380001f54e07fc6 Mon Sep 17 00:00:00 2001 From: olgarrahan Date: Sat, 16 Apr 2022 13:19:13 -0400 Subject: [PATCH 2/4] Genius lyrics header bug fixed and updated test case for lyrics plugin --- beetsplug/lyrics.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index e73c3bc8a..820d16abf 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -404,8 +404,9 @@ class Genius(Backend): lyrics_div = soup.find("div", {"data-lyrics-container": True}) - for br in lyrics_div.find_all("br"): - br.replace_with("\n") + if lyrics_div: + for br in lyrics_div.find_all("br"): + br.replace_with("\n") if not lyrics_div: self._log.debug('Received unusual song page html') From a26a53099623c696c389c5d9c0b25a9108019495 Mon Sep 17 00:00:00 2001 From: olgarrahan Date: Sun, 17 Apr 2022 15:25:14 -0400 Subject: [PATCH 3/4] replace_br function added to reduce code duplication --- beetsplug/lyrics.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 820d16abf..6e0439271 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -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")) From 0e006f116a0578a02dac8ae73fd2d62f3cb337a0 Mon Sep 17 00:00:00 2001 From: olgarrahan Date: Sun, 17 Apr 2022 21:19:26 -0400 Subject: [PATCH 4/4] changelog updates --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4126a8cce..366981684 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -66,6 +66,8 @@ Bug fixes: * :doc:`plugins/embedart`: Fix a crash when using recent versions of ImageMagick and the ``compare_threshold`` option. :bug:`4272` +* :doc:`plugins/lyrics`: Fixed issue with Genius header being included in lyrics, + added test case of up-to-date Genius html For packagers: