Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Genius: handle lyrics divs with no text #5585

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

valrus
Copy link
Contributor

@valrus valrus commented Jan 10, 2025

Description

Fixes #5583.

It's possible for a Genius page to have a lyrics div with no text that will be retrieved by BeautifulSoup's get_text method, which causes lyric fetching to crash. Based on the example in #5583 I believe the problem URL was this one: https://genius.com/Ludwig-van-beethoven-symphony-no-5-in-c-minor-op-67-1st-movement-allegro-con-brio-annotated
Note that the "lyrics" are a series of pictures of the pages of the score, so the text retrieved is an empty string. Prior to this fix, when this happened, this loop would remove the last character of the string until it was empty and then attempt to access the last character again and crash:

        while lyrics[-1] == "\n":
            lyrics = lyrics[:-1]

The intention of that loop seems to be to do what lyrics.rstrip('\n') would do. I replaced it with lyrics.rstrip() to ensure that if we have lyrics consisting only of any whitespace, they'll be turned into an empty string (and this will become None as in other cases where there are no lyrics to be found).

  • Documentation: N/A, no change to interface or intended behavior
  • Changelog: will do once approved
  • Tests.

Copy link

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Beets import crash with lyrics plugin for file w/o lyrics
1 participant