#!/usr/bin/env python3 """Write the burned-in captions as an SRT on the *edited* timeline. The clip drops a span in the middle, so a cue anchored to source seconds has to be shifted by however much was cut before it. A cue that straddles a cut is an error, not something to silently trim: it means CUES and KEEP disagree. """ import sys from cues import CUES, KEEP def to_out(t): acc = 0.0 for a, b in KEEP: if a <= t <= b: return acc + (t - a) acc += b - a return None def ts(t): h, rem = divmod(t, 3600) m, s = divmod(rem, 60) return f"{int(h):02d}:{int(m):02d}:{s:06.3f}".replace(".", ",") def main(out_path): lines = [] for i, (a, b, text) in enumerate(CUES, 1): oa, ob = to_out(a), to_out(b) if oa is None or ob is None: sys.exit(f"cue {i} ({a}-{b}) falls outside KEEP: {text!r}") if ob <= oa: sys.exit(f"cue {i} is inverted after mapping: {oa} -> {ob}") lines.append(f"{i}\n{ts(oa)} --> {ts(ob)}\n{text}\n") for (a1, b1, _), (a2, _, _) in zip(CUES, CUES[1:]): if a2 < b1: sys.exit(f"cues overlap at {a2}") open(out_path, "w").write("\n".join(lines) + "\n") print(f"{len(CUES)} cues -> {out_path}") print("edited duration:", round(sum(b - a for a, b in KEEP), 2), "s") if __name__ == "__main__": main(sys.argv[1])