From c5654c59bc22b7850309f53ae849c484482d35fe Mon Sep 17 00:00:00 2001 From: Uyanide Date: Thu, 2 Apr 2026 11:12:40 +0200 Subject: [PATCH] feat: export to a .txt file instead of .lrc when --plain --- lrx_cli/cli.py | 11 ++++++++--- lrx_cli/lrc.py | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lrx_cli/cli.py b/lrx_cli/cli.py index b1602de..c1beab1 100644 --- a/lrx_cli/cli.py +++ b/lrx_cli/cli.py @@ -254,10 +254,15 @@ def export( logger.error("No lyrics available to export.") sys.exit(1) + # Output file extension + ext = ".lrc" if not plain else ".txt" + if output and not output.endswith(ext): + output += ext + # Build default output path if not output: if track.url: - lrc_path = get_sidecar_path(track.url, ensure_exists=False) + lrc_path = get_sidecar_path(track.url, ensure_exists=False, extension=ext) if lrc_path: output = str(lrc_path) logger.info(f"Exporting to sidecar path: {output}") @@ -265,9 +270,9 @@ def export( # Fallback to current directory with sanitized filename if not output: filename = ( - f"{track.artist} - {track.title}.lrc" + f"{track.artist} - {track.title}{ext}" if track.artist and track.title - else "lyrics.lrc" + else "lyrics" + ext ) # Sanitize filename filename = "".join( diff --git a/lrx_cli/lrc.py b/lrx_cli/lrc.py index 489191e..ffc64be 100644 --- a/lrx_cli/lrc.py +++ b/lrx_cli/lrc.py @@ -297,7 +297,10 @@ def get_audio_path(audio_url: str, ensure_exists: bool = False) -> Optional[Path def get_sidecar_path( - audio_url: str, ensure_audio_exists: bool = False, ensure_exists: bool = False + audio_url: str, + ensure_audio_exists: bool = False, + ensure_exists: bool = False, + extension: str = ".lrc", ) -> Optional[Path]: """Given a file:// URL, return the corresponding .lrc sidecar path. @@ -307,7 +310,7 @@ def get_sidecar_path( audio_path = get_audio_path(audio_url, ensure_exists=ensure_audio_exists) if not audio_path: return None - lrc_path = audio_path.with_suffix(".lrc") + lrc_path = audio_path.with_suffix(extension) if ensure_exists and not lrc_path.exists(): return None return lrc_path