import json, subprocess
from pathlib import Path
root=Path(__file__).parent
cases=['1. 43 KB log + readable thread URL / focused Ctrl+V','2. Same log / click conversation, then Ctrl+V','3. 43 KB log + unavailable-environment URL / focused Ctrl+V','4. Same unavailable link / blurred Ctrl+V','5. Control - 43 KB log without a link','6. Control - short readable hosted thread URL','7. Control - copy T3 thread chip, clear, paste']
runs={"before":[{"name":"focused","at":0,"inputBytes":43350,"inlineCharacters":42528,"composerText":"2026-11-03T12:00:00Z worker retrying synthetic job2026-11-03T12:00:00Z worker retrying synthetic job2026-11-03T12:00:00Z","attachment":False,"focused":"composer-editor"},{"name":"blurred","at":3.701,"inputBytes":43350,"inlineCharacters":42528,"composerText":"2026-11-03T12:00:00Z worker retrying synthetic job2026-11-03T12:00:00Z worker retrying synthetic job2026-11-03T12:00:00Z","attachment":False,"focused":"composer-editor"},{"name":"unavailable-focused","at":7.991,"inputBytes":43350,"inlineCharacters":42587,"composerText":"2026-11-03T12:00:00Z worker retrying synthetic job2026-11-03T12:00:00Z worker retrying synthetic job2026-11-03T12:00:00Z","attachment":False,"focused":"composer-editor"},{"name":"unavailable-blurred","at":11.767,"inputBytes":43350,"inlineCharacters":42587,"composerText":"2026-11-03T12:00:00Z worker retrying synthetic job2026-11-03T12:00:00Z worker retrying synthetic job2026-11-03T12:00:00Z","attachment":False,"focused":"composer-editor"},{"name":"no-link","at":15.769,"inputBytes":43350,"inlineCharacters":23,"composerText":"pasted-text-2.txt43 KB ","attachment":False,"focused":"composer-editor"},{"name":"short-link","at":19.435,"inputBytes":43350,"inlineCharacters":12,"composerText":"SRNew thread","attachment":False,"focused":"composer-editor"},{"name":"copied-chip","at":23.071,"inputBytes":43350,"inlineCharacters":12,"composerText":"SRNew thread","attachment":False,"focused":"composer-editor"}],"after":[{"name":"focused","at":0,"inputBytes":43350,"inlineCharacters":23,"composerText":"pasted-text-2.txt43 KB ","attachment":False,"focused":"composer-editor"},{"name":"blurred","at":3.592,"inputBytes":43350,"inlineCharacters":23,"composerText":"pasted-text-3.txt43 KB ","attachment":False,"focused":"composer-editor"},{"name":"unavailable-focused","at":7.59,"inputBytes":43350,"inlineCharacters":23,"composerText":"pasted-text-4.txt43 KB ","attachment":False,"focused":"composer-editor"},{"name":"unavailable-blurred","at":11.183,"inputBytes":43350,"inlineCharacters":23,"composerText":"pasted-text-5.txt43 KB ","attachment":False,"focused":"composer-editor"},{"name":"no-link","at":15.296,"inputBytes":43350,"inlineCharacters":23,"composerText":"pasted-text-6.txt43 KB ","attachment":False,"focused":"composer-editor"},{"name":"short-link","at":19.023,"inputBytes":43350,"inlineCharacters":12,"composerText":"SRNew thread","attachment":False,"focused":"composer-editor"},{"name":"copied-chip","at":22.71,"inputBytes":43350,"inlineCharacters":12,"composerText":"SRNew thread","attachment":False,"focused":"composer-editor"}]}
for side,sha in [('before','d91915db9e'),('after','62df104401')]:
    steps=runs[side]
    filters=["scale=1280:800", "pad=iw:ih+110:0:110:color=0x15181c",
      "drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:text='"+side.upper()+" - "+sha+" | Web dev app | Chromium | Linux | dark | 1280x800':x=20:y=12:fontsize=21:fontcolor=white"]
    for i,step in enumerate(steps):
        end=steps[i+1]['at'] if i+1<len(steps) else 1000
        # Escape colons for ffmpeg's filter grammar.
        label=cases[i].replace(':',r'\:')
        filters.append("drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:text='"+label+"':x=20:y=49:fontsize=20:fontcolor=white:enable='between(t,"+str(step['at'])+","+str(end)+")'")
    subprocess.run(['ffmpeg','-y','-i',str(root/'run-20261110T2338'/f'{side}-raw.mp4'),'-vf',','.join(filters),'-c:v','libx264','-crf','19','-pix_fmt','yuv420p','-an',str(root/f'{side}.mp4')],check=True,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)

