feat(music): embed plain lyrics and save timed lyrics from Song.synced_lyrics

This commit is contained in:
imSp4rky
2026-10-14 12:37:43 -06:00
parent b107bca168
commit 8a1fbf2de1
6 changed files with 22 additions and 11 deletions
+2 -2
View File
@@ -3867,9 +3867,9 @@ class dl:
)
if include_sample:
self.write_sample(final_path, title, media_info)
if isinstance(title, Song) and title.lyrics and title.lyrics_suffix:
if isinstance(title, Song) and title.synced_lyrics and title.lyrics_suffix:
lyrics_path = final_path.with_suffix(title.lyrics_suffix)
lyrics_path.write_text(f"{title.lyrics}\n", encoding="utf-8")
lyrics_path.write_text(f"{title.synced_lyrics}\n", encoding="utf-8")
sidecar_files.setdefault(muxed_path, []).append(lyrics_path)
self.log.info(f"Saved lyrics to {lyrics_path.name}")
+1
View File
@@ -654,6 +654,7 @@ def build_title(info: Dict[str, Any], service_tag: str, fallback_id: str) -> Tit
label=info.get("label"),
lyrics=info.get("lyrics"),
artwork_url=info.get("artwork_url"),
synced_lyrics=info.get("synced_lyrics"),
lyrics_suffix=info.get("lyrics_suffix"),
)
else:
+9 -1
View File
@@ -28,6 +28,7 @@ SONG_FIELDS = (
"copyright",
"label",
"lyrics",
"synced_lyrics",
"lyrics_suffix",
"artwork_url",
)
@@ -59,9 +60,13 @@ class Song(Title):
label: Optional[str] = None,
lyrics: Optional[str] = None,
artwork_url: Optional[str] = None,
synced_lyrics: Optional[str] = None,
lyrics_suffix: Optional[str] = None,
) -> None:
"""`lyrics_suffix` (".lrc", ".ttml") also saves `lyrics` beside the audio file with that suffix."""
"""`lyrics` is the plain text the tagger embeds.
`synced_lyrics` (timed LRC or TTML) is saved beside the audio file with `lyrics_suffix` (".lrc", ".ttml").
"""
super().__init__(id_, service, language, data)
if not name:
@@ -113,6 +118,8 @@ class Song(Title):
raise TypeError(f"Expected lyrics to be a str, not {lyrics!r}")
if artwork_url is not None and not isinstance(artwork_url, str):
raise TypeError(f"Expected artwork_url to be a str, not {artwork_url!r}")
if synced_lyrics is not None and not isinstance(synced_lyrics, str):
raise TypeError(f"Expected synced_lyrics to be a str, not {synced_lyrics!r}")
if lyrics_suffix is not None and not (isinstance(lyrics_suffix, str) and lyrics_suffix.startswith(".")):
raise TypeError(f"Expected lyrics_suffix to be a str starting with '.', not {lyrics_suffix!r}")
@@ -160,6 +167,7 @@ class Song(Title):
self.label = label
self.lyrics = lyrics
self.artwork_url = artwork_url
self.synced_lyrics = synced_lyrics.strip() if synced_lyrics else None
self.lyrics_suffix = lyrics_suffix
def __str__(self) -> str: