From ed9a05c666d09455edb234ba8448ee26dbceb4ec Mon Sep 17 00:00:00 2001 From: Mijael Viricochea <34387536+omensight@users.noreply.github.com> Date: Thu, 23 Apr 2026 16:59:38 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20option=20to=20write=20LRC?= =?UTF-8?q?=20file=20(#308)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/config.example.toml | 4 ++++ tiddl/cli/commands/download/__init__.py | 16 +++++++++++++++- tiddl/cli/config.py | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/config.example.toml b/docs/config.example.toml index 5299da1..99331c7 100644 --- a/docs/config.example.toml +++ b/docs/config.example.toml @@ -80,6 +80,10 @@ update_mtime = false # could be useful when data on Tidal has changed. 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] # embed metadata in files diff --git a/tiddl/cli/commands/download/__init__.py b/tiddl/cli/commands/download/__init__.py index 995d49f..04c8cd5 100644 --- a/tiddl/cli/commands/download/__init__.py +++ b/tiddl/cli/commands/download/__init__.py @@ -135,6 +135,18 @@ def download_callback( 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( resource_type: VALID_M3U_RESOURCE_LITERAL, filename: str, @@ -237,7 +249,7 @@ def download_callback( if isinstance(item, Track): lyrics_subtitles = "" - if CONFIG.metadata.lyrics: + if CONFIG.metadata.lyrics or CONFIG.download.write_lrc_file: try: lyrics_subtitles = ctx.obj.api.get_track_lyrics( item.id @@ -255,6 +267,8 @@ def download_callback( if track_metadata.cover and track_metadata.cover.data is None: track_metadata.cover.fetch_data() + write_lrc_file(item, lyrics_subtitles, download_path) + add_track_metadata( path=download_path, track=item, diff --git a/tiddl/cli/config.py b/tiddl/cli/config.py index c2447a1..ef7159b 100644 --- a/tiddl/cli/config.py +++ b/tiddl/cli/config.py @@ -55,6 +55,7 @@ class Config(BaseModel): videos_filter: VIDEOS_FILTER_LITERAL = "none" update_mtime: bool = False rewrite_metadata: bool = False + write_lrc_file: bool = False def model_post_init(self, __context): # set scan path to download path when download path is non default