Skip to content

Commit

Permalink
lyrics/LRCLib: handle instrumental lyrics
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Oct 13, 2024
1 parent e931721 commit 964de46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion beetsplug/lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
TAG_RE = re.compile(r"<[^>]*>")
BREAK_RE = re.compile(r"\n?\s*<br([\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
Expand Down Expand Up @@ -343,6 +344,9 @@ def fetch(
if data:
item = self.pick_lyrics(length, data)

if item["instrumental"]:
return INSTRUMENTAL_LYRICS

if self.config["synced"] and (synced := item["syncedLyrics"]):
return synced

Expand Down Expand Up @@ -530,7 +534,7 @@ def _try_extracting_lyrics_from_non_data_lyrics_container(self, soup):
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
Expand Down
6 changes: 6 additions & 0 deletions test/plugins/test_lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def test_scrape(self, backend, lyrics_html, expecting_lyrics):

def lyrics_match(**overrides):
return {
"instrumental": False,
"duration": LYRICS_DURATION,
"syncedLyrics": "synced",
"plainLyrics": "plain",
Expand Down Expand Up @@ -409,6 +410,11 @@ def test_synced_config_option(self, fetch_lyrics, expected_lyrics):
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",
Expand Down

0 comments on commit 964de46

Please sign in to comment.