Skip to content

Commit

Permalink
lyrics: Fallback to plain lyrics if synced not available
Browse files Browse the repository at this point in the history
  • Loading branch information
edgars-supe committed Jan 25, 2024
1 parent 7f1250d commit 1adec91
Show file tree
Hide file tree
Showing 2 changed files with 16 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 @@ -313,7 +313,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
15 changes: 15 additions & 0 deletions test/plugins/test_lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,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)
self.assertEqual(lyrics, mock_response["plainLyrics"])

self.plugin.config["synced"] = True
lyrics = lrclib.fetch("la", "la", "la", 999)
self.assertEqual(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)
self.assertEqual(lyrics, mock_response["plainLyrics"])

@patch("beetsplug.lyrics.requests.get")
def test_fetch_plain_lyrics(self, mock_get):
mock_response = {
Expand All @@ -712,6 +726,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)

self.assertEqual(lyrics, mock_response["plainLyrics"])
Expand Down

0 comments on commit 1adec91

Please sign in to comment.