From 00703ca278f7969c2a8b23fe9ea91d3b0796ba9d Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Fri, 29 May 2026 09:25:00 +0200 Subject: [PATCH] fix(cli): simplify determining output file --- src/video2srt/cli.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/video2srt/cli.py b/src/video2srt/cli.py index 7d41576..a91796c 100644 --- a/src/video2srt/cli.py +++ b/src/video2srt/cli.py @@ -25,22 +25,16 @@ DEFAULT_MODEL = os.environ.get("WHISPER_MODEL", "large-v3") DEFAULT_DEVICE = "cuda" if torch.cuda.is_available() else "cpu" -def output_stem(video: Path, override: str | None) -> Path: - if override: - path = Path(override) - return path.with_suffix("") if path.suffix == ".srt" else path - return video.with_suffix("") - - def process(video: Path, model: Whisper, args: argparse.Namespace) -> None: - out_stem = output_stem(video, args.output) - srt = out_stem.with_suffix(".srt") + srt = video.with_suffix(".srt") + if args.output: + srt = Path(args.output) if srt.exists() and not args.force: print(f"skip: {srt} exists (use --force to overwrite)") return - out_stem.parent.mkdir(parents=True, exist_ok=True) + srt.parent.mkdir(parents=True, exist_ok=True) print(f">> {video}") result: stable_whisper.WhisperResult = model.transcribe( # type: ignore @@ -50,9 +44,7 @@ def process(video: Path, model: Whisper, args: argparse.Namespace) -> None: suppress_silence=True, denoiser="demucs" if args.denoiser else None, ) - result.to_srt_vtt( - str(srt), word_level=False, segment_level=True - ) + result.to_srt_vtt(str(srt), word_level=False, segment_level=True) print(f"<< {srt}")