From 885560ef5fe25ad61fd2c61d7c1b2afbe9088ad9 Mon Sep 17 00:00:00 2001 From: Honney OC Date: Tue, 15 Sep 2026 21:09:17 +0000 Subject: [PATCH] feat: add start-offset validation against file durations --- extract.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/extract.py b/extract.py index f5ebdbe..b754e40 100644 --- a/extract.py +++ b/extract.py @@ -439,6 +439,24 @@ _stems = _derive_stems(INPUT_FILES) # ─── Prepare output folder ─── os.makedirs(OUT_DIR, exist_ok=True) +# ─── Validate start offset against file durations ─── +for _check_idx, _check_file in enumerate(INPUT_FILES): + try: + _r = subprocess.run( + ["ffprobe", "-v", "error", "-show_entries", "format=duration", + "-of", "default=noprint_wrappers=1:nokey=1", _check_file], + capture_output=True, text=True, timeout=10 + ) + _dur = float(_r.stdout.strip()) if _r.returncode == 0 else 0 + _label = "A" if _check_idx == 0 else "B" + if _dur > 0 and START_SEC >= _dur: + print(f"WARNING: start={START_SEC}s is BEYOND file {_label} duration ({_dur:.1f}s) — extraction will produce empty/silent output!", file=sys.stderr) + elif _dur > 0 and START_SEC + DURATION > _dur: + _remaining = _dur - START_SEC + print(f"WARNING: start={START_SEC}s + duration={DURATION}s exceeds file {_label} ({_dur:.1f}s) — only {_remaining:.1f}s available", file=sys.stderr) + except Exception: + pass + _audio_stream_selections = [] # track selected stream indices for config for _file_idx, INPUT_FILE in enumerate(INPUT_FILES):