Skip to content

Commit

Permalink
Add config option to prefer synced lyrics over plain
Browse files Browse the repository at this point in the history
  • Loading branch information
mumumumu committed Nov 5, 2023
1 parent f98b9a7 commit 973a57c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion beetsplug/lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ def fetch(self, artist, title, album=None, length=None):
self._log.debug("LRCLib API request failed: {0}", exc)
return None

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

return data.get("plainLyrics")


class MusiXmatch(Backend):
Expand Down Expand Up @@ -796,6 +799,7 @@ def __init__(self):
"fallback": None,
"force": False,
"local": False,
"synced": False,
# Musixmatch is disabled by default as they are currently blocking
# requests with the beets user agent.
"sources": [s for s in self.SOURCES if s != "musixmatch"],
Expand Down
3 changes: 2 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ New features:
but no thumbnail is provided by CAA. We now fallback to the raw image.
* :doc:`/plugins/advancedrewrite`: Add an advanced version of the `rewrite`
plugin which allows to replace fields based on a given library query.
* :doc:`/plugins/lyrics`: Add LRCLIB as a new lyrics provider.
* :doc:`/plugins/lyrics`: Add LRCLIB as a new lyrics provider and a new
`synced` option to prefer synced lyrics over plain lyrics.

Bug fixes:

Expand Down
1 change: 1 addition & 0 deletions docs/plugins/lyrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ configuration file. The available options are:
is setup.
The ``google``, ``genius``, and ``tekstowo`` sources will only be enabled if
BeautifulSoup is installed.
- **synced**: Prefer synced lyrics over plain lyrics if a source offers them. Currently `lrclib` is the only source that provides them. Default: `no`.

Here's an example of ``config.yaml``::

Expand Down
3 changes: 3 additions & 0 deletions test/plugins/test_lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,10 @@ def test_fetch_synced_lyrics(self, mock_get):
mock_get.return_value.status_code = 200

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")
Expand Down

0 comments on commit 973a57c

Please sign in to comment.