import os import json from pathlib import Path from datetime import datetime ROOT = "R:/" OUTPUT = "C:/Users/admin/.openclaw/workspace/rom-inventory" DISC = {"PSX", "PS2", "PS3", "PSP", "PS VITA", "Sega CD", "Sega Dreamcast", "Sega Saturn", "OG XBOX", "XBOX 360"} EXTS = {".sfc", ".nes", ".z64", ".v64", ".n64", ".gba", ".gbc", ".gb", ".nds", ".3ds", ".iso", ".bin", ".cue", ".md", ".sms", ".gg", ".zip"} os.makedirs(OUTPUT, exist_ok=True) def count_folders(p): return sum(1 for x in Path(p).iterdir() if x.is_dir() and not x.name.startswith(".")) def count_files(p): c, s = 0, 0 for r, d, f in os.walk(p): for x in f: if Path(x).suffix.lower() in EXTS: c += 1 try: s += os.path.getsize(Path(r)/x) except: pass return c, s org = Path(ROOT) / "Rom Sets (Organized)" data = {"date": datetime.now().isoformat(), "consoles": {}} total = 0 size = 0 for mfr in org.iterdir(): if mfr.is_dir(): print(mfr.name) for con in mfr.iterdir(): if con.is_dir(): if any(d in con.name for d in DISC): n = count_folders(con) data["consoles"][con.name] = {"type": "disc", "count": n} else: n, s = count_files(con) data["consoles"][con.name] = {"type": "cart", "count": n, "size_gb": round(s/1e9, 2)} size += s total += n data["total"] = total data["size_gb"] = round(size/1e9, 2) out = Path(OUTPUT) / "rom-inventory.json" with open(out, "w") as f: json.dump(data, f, indent=2) print(f"Done: {total} items, {data['size_gb']} GB") print(f"Saved: {out}")