feat(lyrics): fetch lyrics text from LRCLIB (--lyrics-from lrclib)

Text only; the audio alignment is unchanged. The release is chosen by length
(within 5 s of the audio) and live/acoustic/remix/karaoke versions rank last.
The chosen release is recorded in meta.json as lyrics_source.
Local use only: lyrics are copyrighted and must not be redistributed.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-07 11:55:56 +01:00
parent c4613d5616
commit c761a244d8
5 changed files with 150 additions and 1 deletions

View File

@ -98,3 +98,33 @@ def test_is_ultrastar_file_detects_ultrastar_but_not_plain_text(tmp_path):
plain.write_text("We do it all\nEverything on our own\n", encoding="utf-8")
assert is_ultrastar_file(us)
assert not is_ultrastar_file(plain)
def test_pick_version_chooses_length_match_and_skips_instrumentals_and_empty():
import pytest
from unmix.pipeline.lrclib import LyricsLookupError, pick_version
results = [
{"trackName": "A", "plainLyrics": None, "duration": 221.0},
{"trackName": "B", "plainLyrics": "la", "instrumental": True, "duration": 221.0},
{"trackName": "C", "plainLyrics": "text", "duration": 266.0},
{"trackName": "D", "plainLyrics": "text", "duration": 222.0},
]
assert pick_version(results, 221.5)["trackName"] == "D"
with pytest.raises(LyricsLookupError, match="passender Länge"):
pick_version(results, 120.0)
with pytest.raises(LyricsLookupError, match="kein Eintrag"):
pick_version([{"plainLyrics": None, "duration": 221.0}], 221.0)
def test_pick_version_prefers_studio_over_live_when_both_fit():
from unmix.pipeline.lrclib import pick_version
results = [
{"trackName": "Chasing Cars", "albumName": "Live in Studio - Acoustic", "plainLyrics": "a", "duration": 268.0},
{"trackName": "Chasing Cars", "albumName": "Eyes Open", "plainLyrics": "b", "duration": 270.0},
]
assert pick_version(results, 268.0)["albumName"] == "Eyes Open"
# if only the live version fits, it is still used
assert pick_version(results[:1], 268.0)["albumName"].startswith("Live")