From 2fb72c65a5e89c767e62182bee772c464cc9f2da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Fri, 27 Sep 2024 23:00:01 +0100 Subject: [PATCH] lyrics/LRCLib: handle instrumental lyrics --- beetsplug/lyrics.py | 6 +++++- test/plugins/test_lyrics.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index eedf1e0e2..a938f5318 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -60,6 +60,7 @@ COMMENT_RE = re.compile(r"", re.S) TAG_RE = re.compile(r"<[^>]*>") BREAK_RE = re.compile(r"\n?\s*]*)*>\s*\n?", re.I) USER_AGENT = f"beets/{beets.__version__}" +INSTRUMENTAL_LYRICS = "[Instrumental]" # The content for the base index.rst generated in ReST mode. REST_INDEX_TEMPLATE = """Lyrics @@ -349,6 +350,9 @@ class LRCLib(Backend): if data: item = self.pick_lyrics(length, data) + if item["instrumental"]: + return INSTRUMENTAL_LYRICS + if self.config["synced"] and (synced := item["syncedLyrics"]): return synced @@ -536,7 +540,7 @@ class Genius(Backend): string="This song is an instrumental", ): self._log.debug("Detected instrumental") - return "[Instrumental]" + return INSTRUMENTAL_LYRICS else: self._log.debug("Couldn't scrape page using known layouts") return None diff --git a/test/plugins/test_lyrics.py b/test/plugins/test_lyrics.py index dceec79b5..96ecfbba8 100644 --- a/test/plugins/test_lyrics.py +++ b/test/plugins/test_lyrics.py @@ -347,6 +347,7 @@ LYRICS_DURATION = 950 def lyrics_match(**overrides): return { + "instrumental": False, "duration": LYRICS_DURATION, "syncedLyrics": "synced", "plainLyrics": "plain", @@ -386,6 +387,11 @@ class TestLRCLibLyrics(LyricsBackendTest): pytest.param( [lyrics_match()], "synced", id="synced when available" ), + pytest.param( + [lyrics_match(instrumental=True)], + "[Instrumental]", + id="instrumental track", + ), pytest.param( [lyrics_match(syncedLyrics=None)], "plain",