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