#!/usr/bin/env python3 """Derive a bounded poster/bootstrap from the exact user-authorized immutable pack. CPU decode only. Portrait outputs stay ignored; the metadata records exact provenance. """ import argparse, hashlib, io, json, subprocess from pathlib import Path from PIL import Image ROOT=Path(__file__).resolve().parents[1] PIN='208f703ed92bf795bfeb78a1cef89b67bed2e45da80038a56157fd1ecd4cfa93' ASSET_ROOT='avatar/a01-black-tulle-roomy720-correct03/' BASIC_ROOT='avatar/startup-black-tulle-correct03/' sha=lambda data:hashlib.sha256(data).hexdigest() def derive(source): index=source/'manifest.json';assert sha(index.read_bytes())==PIN,'exact index drift' m=json.loads(index.read_bytes());row=next(r for r in m['conversationPackages'] if r['id']==m['fallbackPackageId']) runtime=source/row['runtimeManifest']['path'];assert sha(runtime.read_bytes())==row['runtimeManifest']['sha256'] body=json.loads(runtime.read_bytes())['body'];name=str(Path(row['runtimeManifest']['path']).parent/body['path']) path=source/name;assert sha(path.read_bytes())==body['sha256'] assert (body['width'],body['height'])==(720,1280) and body['ptsUs'][0]==0 and body['hasAudio'] is False native=subprocess.check_output(['/home/ubuntu/gori-bin/ffmpeg','-v','error','-i',str(path),'-frames:v','1','-f','image2pipe','-vcodec','png','-'],timeout=30) image=Image.open(io.BytesIO(native)).convert('RGB').resize((180,320),Image.Resampling.LANCZOS) out=io.BytesIO();image.save(out,format='PNG',optimize=True);poster=out.getvalue();assert len(poster)<=100_000 meta={'schemaVersion':1,'sourceIndexSha256':PIN,'posterSha256':sha(poster),'posterWidth':180,'posterHeight':320, 'provenance':'Exact decoded neutral source frame0; CPU downsample, no generated media; user-authorized debug integration, not Pi certification', 'body':{**body,'path':ASSET_ROOT+name}} return (json.dumps(meta,indent=2)+'\n').encode(),poster def prepare(source,verify_only=False): raw,poster=derive(source) outputs={ROOT/'manifests/startup-black-tulle-correct03.json':raw, ROOT/'app/src/main/assets'/BASIC_ROOT/'manifest.json':raw, ROOT/'app/src/main/assets'/BASIC_ROOT/'poster.png':poster, ROOT/'app/src/main/res/drawable-nodpi/startup_black_tulle_poster.png':poster} for path,data in outputs.items(): if path.exists():assert path.read_bytes()==data,'Unknown bootstrap bytes preserved: '+str(path) else: assert not verify_only,'missing bootstrap: '+str(path) path.parent.mkdir(parents=True,exist_ok=True);path.write_bytes(data) return {'status':'passed','index_sha256':PIN,'bootstrap_sha256':sha(raw),'poster_sha256':sha(poster),'poster_bytes':len(poster),'paid_calls':0} if __name__=='__main__': parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--source',type=Path,required=True);parser.add_argument('--verify-only',action='store_true') args=parser.parse_args();print(json.dumps(prepare(args.source,args.verify_only),indent=2))