lyrics/LRCLib: handle instrumental lyrics

This commit is contained in:
Šarūnas Nejus 2024-09-27 23:00:01 +01:00
parent 30379bca38
commit 2fb72c65a5
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
2 changed files with 11 additions and 1 deletions

View file

@ -60,6 +60,7 @@ COMMENT_RE = re.compile(r"<!--.*-->", re.S)
TAG_RE = re.compile(r"<[^>]*>") TAG_RE = re.compile(r"<[^>]*>")
BREAK_RE = re.compile(r"\n?\s*<br([\s|/][^>]*)*>\s*\n?", re.I) BREAK_RE = re.compile(r"\n?\s*<br([\s|/][^>]*)*>\s*\n?", re.I)
USER_AGENT = f"beets/{beets.__version__}" USER_AGENT = f"beets/{beets.__version__}"
INSTRUMENTAL_LYRICS = "[Instrumental]"
# The content for the base index.rst generated in ReST mode. # The content for the base index.rst generated in ReST mode.
REST_INDEX_TEMPLATE = """Lyrics REST_INDEX_TEMPLATE = """Lyrics
@ -349,6 +350,9 @@ class LRCLib(Backend):
if data: if data:
item = self.pick_lyrics(length, data) item = self.pick_lyrics(length, data)
if item["instrumental"]:
return INSTRUMENTAL_LYRICS
if self.config["synced"] and (synced := item["syncedLyrics"]): if self.config["synced"] and (synced := item["syncedLyrics"]):
return synced return synced
@ -536,7 +540,7 @@ class Genius(Backend):
string="This song is an instrumental", string="This song is an instrumental",
): ):
self._log.debug("Detected instrumental") self._log.debug("Detected instrumental")
return "[Instrumental]" return INSTRUMENTAL_LYRICS
else: else:
self._log.debug("Couldn't scrape page using known layouts") self._log.debug("Couldn't scrape page using known layouts")
return None return None

View file

@ -347,6 +347,7 @@ LYRICS_DURATION = 950
def lyrics_match(**overrides): def lyrics_match(**overrides):
return { return {
"instrumental": False,
"duration": LYRICS_DURATION, "duration": LYRICS_DURATION,
"syncedLyrics": "synced", "syncedLyrics": "synced",
"plainLyrics": "plain", "plainLyrics": "plain",
@ -386,6 +387,11 @@ class TestLRCLibLyrics(LyricsBackendTest):
pytest.param( pytest.param(
[lyrics_match()], "synced", id="synced when available" [lyrics_match()], "synced", id="synced when available"
), ),
pytest.param(
[lyrics_match(instrumental=True)],
"[Instrumental]",
id="instrumental track",
),
pytest.param( pytest.param(
[lyrics_match(syncedLyrics=None)], [lyrics_match(syncedLyrics=None)],
"plain", "plain",