Skip to content

Commit e89d718

Browse files
committed
lyrics/LRCLib: handle instrumental lyrics
1 parent bd9a943 commit e89d718

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

beetsplug/lyrics.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
TAG_RE = re.compile(r"<[^>]*>")
6161
BREAK_RE = re.compile(r"\n?\s*<br([\s|/][^>]*)*>\s*\n?", re.I)
6262
USER_AGENT = f"beets/{beets.__version__}"
63+
INSTRUMENTAL_LYRICS = "[Instrumental]"
6364

6465
# The content for the base index.rst generated in ReST mode.
6566
REST_INDEX_TEMPLATE = """Lyrics
@@ -349,6 +350,9 @@ def fetch(
349350
if data:
350351
item = self.pick_lyrics(length, data)
351352

353+
if item["instrumental"]:
354+
return INSTRUMENTAL_LYRICS
355+
352356
if self.config["synced"] and (synced := item["syncedLyrics"]):
353357
return synced
354358

@@ -536,7 +540,7 @@ def _try_extracting_lyrics_from_non_data_lyrics_container(self, soup):
536540
string="This song is an instrumental",
537541
):
538542
self._log.debug("Detected instrumental")
539-
return "[Instrumental]"
543+
return INSTRUMENTAL_LYRICS
540544
else:
541545
self._log.debug("Couldn't scrape page using known layouts")
542546
return None

test/plugins/test_lyrics.py

+6
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ def test_scrape(self, backend, lyrics_html, expecting_lyrics):
347347

348348
def lyrics_match(**overrides):
349349
return {
350+
"instrumental": False,
350351
"duration": LYRICS_DURATION,
351352
"syncedLyrics": "synced",
352353
"plainLyrics": "plain",
@@ -386,6 +387,11 @@ def test_synced_config_option(self, fetch_lyrics, expected_lyrics):
386387
pytest.param(
387388
[lyrics_match()], "synced", id="synced when available"
388389
),
390+
pytest.param(
391+
[lyrics_match(instrumental=True)],
392+
"[Instrumental]",
393+
id="instrumental track",
394+
),
389395
pytest.param(
390396
[lyrics_match(syncedLyrics=None)],
391397
"plain",

0 commit comments

Comments
 (0)