from __future__ import annotations import json import sys from pathlib import Path from pptx import Presentation from pptx.enum.shapes import MSO_SHAPE_TYPE MANIFEST = Path(sys.argv[1] if len(sys.argv) > 1 else "artifacts/music-template-extraction/review/manifest.json") TARGETS = set(sys.argv[2:] or ["candidate-05", "candidate-20", "candidate-26", "candidate-30", "candidate-31", "candidate-33"]) def main() -> None: items = json.loads(MANIFEST.read_text(encoding="utf-8"))["items"] for item in items: if item["id"] not in TARGETS: continue deck = Presentation(item["source"]) print(f"\n{item['id']} {item['name']}") for sample in item["samples"]: number = int(Path(sample).stem.split("-")[1]) slide = deck.slides[number - 1] print(f" slide={number}") for index, shape in enumerate(slide.shapes): if shape.shape_type != MSO_SHAPE_TYPE.PICTURE: continue left = shape.left / deck.slide_width top = shape.top / deck.slide_height width = shape.width / deck.slide_width height = shape.height / deck.slide_height print(f" picture={index:02d} box=({left:.3f},{top:.3f},{width:.3f},{height:.3f}) area={width * height:.3f}") if __name__ == "__main__": main()