Added option to write LRC file (#308)

This commit is contained in:
Mijael Viricochea
2026-04-23 16:59:38 -04:00
committed by GitHub
parent 8a2c30feaf
commit ed9a05c666
3 changed files with 20 additions and 1 deletions
+4
View File
@@ -80,6 +80,10 @@ update_mtime = false
# could be useful when data on Tidal has changed. # could be useful when data on Tidal has changed.
rewrite_metadata = false rewrite_metadata = false
# if this option is set to true, an .lrc file will be created alongside the
# track file with the same name
write_lrc_file = false
[metadata] [metadata]
# embed metadata in files # embed metadata in files
+15 -1
View File
@@ -135,6 +135,18 @@ def download_callback(
log.debug(f"{ctx.params=}") log.debug(f"{ctx.params=}")
def write_lrc_file(track: Track, lyrics: str, file_path: Path):
if not CONFIG.download.write_lrc_file or not lyrics.strip():
return
lrc_file_path = file_path.with_suffix(".lrc")
try:
with open(lrc_file_path, "w", encoding="utf-8") as f:
f.write(lyrics)
except Exception as e:
log.error(f"Failed to write LRC file for track {track.title} (ID: {track.id}): {e}")
def save_m3u( def save_m3u(
resource_type: VALID_M3U_RESOURCE_LITERAL, resource_type: VALID_M3U_RESOURCE_LITERAL,
filename: str, filename: str,
@@ -237,7 +249,7 @@ def download_callback(
if isinstance(item, Track): if isinstance(item, Track):
lyrics_subtitles = "" lyrics_subtitles = ""
if CONFIG.metadata.lyrics: if CONFIG.metadata.lyrics or CONFIG.download.write_lrc_file:
try: try:
lyrics_subtitles = ctx.obj.api.get_track_lyrics( lyrics_subtitles = ctx.obj.api.get_track_lyrics(
item.id item.id
@@ -255,6 +267,8 @@ def download_callback(
if track_metadata.cover and track_metadata.cover.data is None: if track_metadata.cover and track_metadata.cover.data is None:
track_metadata.cover.fetch_data() track_metadata.cover.fetch_data()
write_lrc_file(item, lyrics_subtitles, download_path)
add_track_metadata( add_track_metadata(
path=download_path, path=download_path,
track=item, track=item,
+1
View File
@@ -55,6 +55,7 @@ class Config(BaseModel):
videos_filter: VIDEOS_FILTER_LITERAL = "none" videos_filter: VIDEOS_FILTER_LITERAL = "none"
update_mtime: bool = False update_mtime: bool = False
rewrite_metadata: bool = False rewrite_metadata: bool = False
write_lrc_file: bool = False
def model_post_init(self, __context): def model_post_init(self, __context):
# set scan path to download path when download path is non default # set scan path to download path when download path is non default