"""Extract only used PPT media and copy approved community assets; no image editing."""
from pathlib import Path
from pptx import Presentation
from PIL import Image
import argparse,re,json,shutil
p=argparse.ArgumentParser();p.add_argument('--government-ppt',required=True);p.add_argument('--community-assets',required=True);a=p.parse_args()
r=Path(__file__).parent;out=r/'deliverables'/'assets';out.mkdir(parents=True,exist_ok=True)
source=(r/'render.cjs').read_text();prs=Presentation(a.government_ppt)
for name in sorted(set(re.findall(r'gov-p\d+-\d+\.(?:png|jpg|jpeg)',source))):
 m=re.fullmatch(r'gov-p(\d+)-(\d+)\.(\w+)',name);image=prs.slides[int(m[1])-1].shapes[int(m[2])].image
 (out/name).write_bytes(image.blob)
for name in ['scale410.png','binding.png','period-report.png']:
 shutil.copy2(Path(a.community_assets)/name,out/name)
d={}
for f in out.iterdir():
 try:
  with Image.open(f) as im:d[f.name]=list(im.size)
 except Exception:pass
(out/'dimensions.json').write_text(json.dumps(d))
print('prepared',len(d),'media files')
