mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
lyrics/LRCLib: handle instrumental lyrics
This commit is contained in:
parent
30379bca38
commit
2fb72c65a5
2 changed files with 11 additions and 1 deletions
|
|
@ -60,6 +60,7 @@ COMMENT_RE = re.compile(r"<!--.*-->", re.S)
|
|||
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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue