Branchwell

AI Resource Pro / full-access-films / tools / outro_sample.py

1#!/usr/bin/env python3
2"""Builds film-outro/: the last seconds of film-codex alone, to review the ending."""
3import os, re, shutil
4S, D, L = "film-codex", "film-outro", 11.3
5shutil.rmtree(D, ignore_errors=True)
6shutil.copytree(S, D, ignore=shutil.ignore_patterns("clips", ".hyperframes", "renders", "mix.m4a"))
7html = open(f"{D}/index.html").read()
8total = float(re.search(r'data-composition-id="main" data-start="0" data-duration="([\d.]+)"', html).group(1))
9off = total - L
10html = re.sub(r'\s*<div id="(?!field|outro|root)\w+" data-composition-id="\w+" data-composition-src.*?</div>', "", html)
11html = re.sub(r"\s*<audio.*?</audio>", "", html)
12html = html.replace(f'data-duration="{total:.3f}"', f'data-duration="{L}"')
13html = re.sub(r'(id="outro".*?data-start=")[\d.]+', lambda m: f"{m.group(1)}{L - 8.3}", html)
14open(f"{D}/index.html", "w").write(html)
15cues = open(f"{D}/assets/cues.js").read()
16cues = re.sub(r"FILM_SECONDS = [\d.]+", f"FILM_SECONDS = {L}", cues)
17items = re.findall(r"\{ t: ([\d.]+), (.*?) \}", cues)
18kept = [f"{{ t: {max(0, float(t) - off):.3f}, {body} }}" for t, body in items]
19cues = re.sub(r"window\.FIELD_CUES = \[.*\];", lambda m: "window.FIELD_CUES = [\n" + ",".join(kept) + "\n];", cues, flags=re.S)
20open(f"{D}/assets/cues.js", "w").write(cues)