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

Fix lrclib lyrics #5406

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

Fix lrclib lyrics #5406

wants to merge 26 commits into from

Conversation

snejus
Copy link
Member

@snejus snejus commented Sep 4, 2024

Fixes #5102
Fixes #5133

LRCLib

Adjust the base URL to perform a /search instead of attempting to /get specific lyrics
where we're unlikely to find anything for some specific combination of album, artist and
title fields.

Since we receive an array of matching lyrics candidates, rank them by

  1. Duration similarity to the target item
  2. Availability of synced lyrics

and pick the best match.


Additionally, I did a small refactor of lyrics integration tests and removed some unused lyrics files.

@snejus snejus self-assigned this Sep 4, 2024
@snejus snejus linked an issue Sep 4, 2024 that may be closed by this pull request
@snejus snejus requested a review from bal-e September 4, 2024 04:27
@snejus snejus force-pushed the fix-lrclib-lyrics branch 2 times, most recently from d4bed72 to 829192d Compare September 4, 2024 04:40
@snejus snejus force-pushed the fix-lrclib-lyrics branch 5 times, most recently from cb8929f to c2807f0 Compare September 4, 2024 10:26
@snejus
Copy link
Member Author

snejus commented Sep 4, 2024

The build on win32 is failing to install reflink because it's only supported until Python 3.7.

I will address this in a separate PR and rebase this one accordingly once the fix is merged.

Note: this issue popped up now because I added a new requests-mock dependency which invalidated cached dependencies.

Copy link
Member

@bal-e bal-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a much better implementation now, well done. I especially like that you've managed to remove the test resources -- I wasn't expecting 2000 lines of lyrics in there.

beetsplug/lyrics.py Outdated Show resolved Hide resolved
beetsplug/lyrics.py Outdated Show resolved Hide resolved
snejus added a commit that referenced this pull request Sep 8, 2024
…5407)

See my comment under #5406 for context

> The build on win32 is failing to install reflink because it's [only
supported until Python
3.7](https://gitlab.com/rubdos/pyreflink/-/blob/master/setup.py?ref_type=heads).
>
> I will address this in a separate PR and rebase this one accordingly
once the fix is merged.
>
> Note: this issue popped up now because I added a new requests-mock
dependency which invalidated cached dependencies.
@snejus snejus requested a review from bal-e September 11, 2024 09:28
@snejus snejus force-pushed the fix-lrclib-lyrics branch 3 times, most recently from dc02c94 to 622ed3c Compare September 11, 2024 11:21
@snejus snejus requested a review from JOJ0 September 11, 2024 11:40
beetsplug/lyrics.py Outdated Show resolved Hide resolved
beetsplug/lyrics.py Outdated Show resolved Hide resolved
beetsplug/lyrics.py Outdated Show resolved Hide resolved
@tranxuanthang
Copy link

Hey, LRCLIB author here 👋. It would be great if you could make the /search API a fallback for the /get API (instead of replacing it entirely) when no result is found. The /get API is more performant on LRCLIB's side, whereas the /search API is much slower.

Also, the /get API has been updated recently, and the album_name parameter is no longer a hard requirement.

If you have any ideas for further improvements to LRCLIB's API, feel free to let me know!

@snejus
Copy link
Member Author

snejus commented Sep 26, 2024

Hey, LRCLIB author here 👋. It would be great if you could make the /search API a fallback for the /get API (instead of replacing it entirely) when no result is found. The /get API is more performant on LRCLIB's side, whereas the /search API is much slower.

Also, the /get API has been updated recently, and the album_name parameter is no longer a hard requirement.

If you have any ideas for further improvements to LRCLIB's API, feel free to let me know!

Hi @tranxuanthang, thanks for popping in! Absolutely, that's no problem at all. This should make most lyrics queries even speedier on our side.

Now that we're on this topic, I think it may be a good idea to also add caching: for example, if we're getting lyrics for two separate files

  1. Artist - Title (Some Remix)
  2. Artist - Title

Ideally we should only ask for Artist - Title lyrics once when Artist - Title (Some Remix) is not found.

@tranxuanthang thanks for a reliable and performant API!

Create 'helpers.ConfigMixin' which sets up testing configuration.
This is helpful for tests (e.g. test_lyrics.py) that only need the
configuration and do not require temp dir.

(#5102) Refactor lyrics tests to fix the issue global beets config
issue.

Additionally, add 'integration_test' mark that can be used to mark tests
that should only run once a week.
Improve requests performance with requests.Session which uses connection
pooling for repeated requests to the same host.

Additionally, this centralizes request configuration, making sure that
we use the same timeout and provide beets user agent for all requests.
Due to request error handling this logic will only run for successful
requests, so we can safely assume the html to be a string.
Tidy up 'Google.is_page_candidate' method and remove 'Google.sluggify'
method which was a duplicate of 'slug'.

Since 'GeniusFetchTest' only tested whether the artist name is cleaned
up (the rest of the functionality is patched), remove it and move its
test cases to the 'test_slug' test.
@snejus snejus force-pushed the fix-lrclib-lyrics branch 4 times, most recently from 0012d50 to 2602482 Compare October 1, 2024 09:43
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.

lyrics: config in tests not reset before each test beets can't fetch lyrics from lrclib.net
3 participants