Skip to content

Commit

Permalink
lyrics: Fallback to plain lyrics if synced lyrics not available (#5089)
Browse files Browse the repository at this point in the history
The `synced` config flag was not working the way the docs described it
for the LRCLIB source. With `synced: yes`, if a track does not have
synced lyrics, but does have plain lyrics, the plugin would return no
lyrics. The docs imply that, with the flag enabled, it would still use
plain lyrics if there are no synced lyrics.

LRCLIB API call that returns plain lyrics can be found
[here](https://lrclib.net/api/get?artist_name=Hania%20Rani&track_name=Moans&album_name=Ghosts&duration=274).
  • Loading branch information
snejus authored Dec 7, 2024
2 parents 755e825 + 0936025 commit af41eef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion beetsplug/lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def fetch(self, artist, title, album=None, length=None):
return None

if self.config["synced"]:
return data.get("syncedLyrics")
return data.get("syncedLyrics") or data.get("plainLyrics")

return data.get("plainLyrics")

Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Unreleased

New features:
Bug fixes:

* :doc:`plugins/lyrics`: LRCLib will fallback to plain lyrics if synced lyrics
are not found and `synced` flag is set to `yes`.

For packagers:
Other changes:

Expand Down
15 changes: 15 additions & 0 deletions test/plugins/test_lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,27 @@ def test_fetch_synced_lyrics(self, mock_get):
mock_get.return_value.json.return_value = mock_response
mock_get.return_value.status_code = 200

self.plugin.config["synced"] = False
lyrics = lrclib.fetch("la", "la", "la", 999)
assert lyrics == mock_response["plainLyrics"]

self.plugin.config["synced"] = True
lyrics = lrclib.fetch("la", "la", "la", 999)
assert lyrics == mock_response["syncedLyrics"]

@patch("beetsplug.lyrics.requests.get")
def test_fetch_synced_lyrics_fallback(self, mock_get):
mock_response = {
"syncedLyrics": "",
"plainLyrics": "la la la",
}
mock_get.return_value.json.return_value = mock_response
mock_get.return_value.status_code = 200

self.plugin.config["synced"] = True
lyrics = lrclib.fetch("la", "la", "la", 999)
assert lyrics == mock_response["plainLyrics"]

@patch("beetsplug.lyrics.requests.get")
def test_fetch_plain_lyrics(self, mock_get):
mock_response = {
Expand All @@ -636,6 +650,7 @@ def test_fetch_plain_lyrics(self, mock_get):
mock_get.return_value.json.return_value = mock_response
mock_get.return_value.status_code = 200

self.plugin.config["synced"] = False
lyrics = lrclib.fetch("la", "la", "la", 999)

assert lyrics == mock_response["plainLyrics"]
Expand Down

0 comments on commit af41eef

Please sign in to comment.