mirror of
https://github.com/oskvr37/tiddl.git
synced 2026-06-13 04:05:08 +03:00
✨ Added option to write LRC file (#308)
This commit is contained in:
committed by
GitHub
parent
8a2c30feaf
commit
ed9a05c666
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user