This commit is contained in:
世界观察日志
2025-11-29 10:26:53 +08:00
parent a4c5541485
commit 53d5166a22
4 changed files with 18 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
# DO NOT EDIT IT
version = "0.0.8"
version = "0.0.9"
[instance]
url = "127.0.0.1:8080"
@@ -92,7 +92,10 @@ playlistSongNameFormat = "{playlistSongIndex:02d}. {artist} - {title}"
# Save lyrics as .lrc file
saveLyrics = true
# lrc or ttml
lyricsFormat = "ttml"
# TTML format lyrics will be saved as .ttml suffix
lyricsFormat = "lrc"
# Only applies to lrc lyrics
lyricsExtra = ["translation", "pronunciation"]
saveCover = true
coverFormat = "jpg"
coverSize = "5000x5000"

View File

@@ -5,7 +5,7 @@ from creart import exists_module
from creart.creator import AbstractCreator, CreateTargetInfo
from pydantic import BaseModel
CONFIG_VERSION = "0.0.8"
CONFIG_VERSION = "0.0.9"
class Instance(BaseModel):
@@ -44,6 +44,7 @@ class Download(BaseModel):
playlistSongNameFormat: str = "{playlistSongIndex:02d}. {artist} - {title}"
saveLyrics: bool = True
lyricsFormat: str = "lrc"
lyricsExtra: list[str] = ["translation", "pronunciation"]
saveCover: bool = True
coverFormat: str = "jpg"
coverSize: str = "5000x5000"

View File

@@ -23,6 +23,9 @@ def save(song: bytes, codec: str, metadata: SongMetadata, playlist: PlaylistInfo
if it(Config).download.saveLyrics and metadata.lyrics:
lrc = ttml_convent(metadata.lyrics)
if lrc:
lrc_path = dir_path / Path(song_name + ".lrc")
if it(Config).download.lyricsFormat == "ttml":
lrc_path = dir_path / Path(song_name + ".ttml")
else:
lrc_path = dir_path / Path(song_name + ".lrc")
lrc_path.write_text(lrc, encoding="utf-8")
return song_path.absolute()

View File

@@ -100,7 +100,7 @@ def ttml_convent(ttml: str) -> str:
lyric_time: str = lyric.get("begin")
if not lyric_time:
return ""
#raise NotTimeSyncedLyricsException
# raise NotTimeSyncedLyricsException
if lyric_time.find('.') == -1:
lyric_time += '.000'
match lyric_time.count(":"):
@@ -123,11 +123,16 @@ def ttml_convent(ttml: str) -> str:
get_digit_from_string(split_time[2]), get_digit_from_string(split_time[3]))
lrc_lines.append(
f"[{str(m + h * 60).rjust(2, '0')}:{str(s).rjust(2, '0')}.{str(int(ms / 10)).rjust(2, '0')}]{lyric.text}")
if b.tt.head.metadata.iTunesMetadata.translation:
if "translation" in it(Config).download.lyricsExtra and b.tt.head.metadata.iTunesMetadata.translation:
for translation in b.tt.head.metadata.iTunesMetadata.translation.children:
if lyric.get("itunes:key") == translation.get("for"):
lrc_lines.append(
f"[{str(m + h * 60).rjust(2, '0')}:{str(s).rjust(2, '0')}.{str(int(ms / 10)).rjust(2, '0')}]{translation.text}")
if "pronunciation" in it(Config).download.lyricsExtra and b.tt.head.metadata.iTunesMetadata.transliteration:
for transliteration in b.tt.head.metadata.iTunesMetadata.transliteration.children:
if lyric.get("itunes:key") == transliteration.get("for"):
lrc_lines.append(
f"[{str(m + h * 60).rjust(2, '0')}:{str(s).rjust(2, '0')}.{str(int(ms / 10)).rjust(2, '0')}]{transliteration.text}")
return "\n".join(lrc_lines)