From 09360259cc85f9d7e9655419b9fd71ebb6e8438c Mon Sep 17 00:00:00 2001 From: Edgars Supe Date: Thu, 25 Jan 2024 19:19:37 +0200 Subject: [PATCH] lyrics: Fallback to plain lyrics if synced not available --- beetsplug/lyrics.py | 2 +- docs/changelog.rst | 4 ++++ test/plugins/test_lyrics.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 899bf39921..047550386c 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -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") diff --git a/docs/changelog.rst b/docs/changelog.rst index 0246a15769..7bedaa457e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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: diff --git a/test/plugins/test_lyrics.py b/test/plugins/test_lyrics.py index a65ae84827..f9f9d9be77 100644 --- a/test/plugins/test_lyrics.py +++ b/test/plugins/test_lyrics.py @@ -620,6 +620,7 @@ 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"] @@ -627,6 +628,19 @@ def test_fetch_synced_lyrics(self, mock_get): 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 = { @@ -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"]