#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Census of the Redump "Microsoft - Xbox" set: names and zip central directories only. Nothing is extracted, copied or hashed: each zip's central directory gives its members' names, sizes and CRC-32s, and the zip's own file name gives title, region and flags. The set is found through REDUMP_DIR (the folder that holds "Microsoft - Xbox"), never a path written into this repository. REDUMP_DIR=... python -I scripts/census_redump.py > tests/detectors/census-redump-xbox-.txt Run it under `nice`; it reads about a thousand central directories. """ from __future__ import annotations import collections import os import re import sys import zipfile from pathlib import Path SET_NAME = "Microsoft - Xbox" # A full XGD1 disc image as Redump keeps it: video partition and game partition together. FLAG_WORDS = ("Demo", "Rev", "Beta", "Proto", "Unl", "Kiosk", "Alt") def main() -> int: root = os.environ.get("REDUMP_DIR") if not root: print("REDUMP_DIR is not set (the folder holding the Redump sets)", file=sys.stderr) return 2 folder = Path(root) / SET_NAME zips = sorted(folder.glob("*.zip")) others = sorted(p.name for p in folder.iterdir() if p.suffix != ".zip") regions: collections.Counter[str] = collections.Counter() flags: collections.Counter[str] = collections.Counter() member_kinds: collections.Counter[str] = collections.Counter() sizes: collections.Counter[int] = collections.Counter() titles: set[str] = set() discs = 0 no_region = 0 total = 0 unreadable: list[str] = [] multi_member: list[str] = [] for path in zips: name = path.stem titles.add(name.split(" (", 1)[0]) groups = re.findall(r"\(([^)]*)\)", name) if groups: for region in groups[0].split(", "): regions[region] += 1 else: no_region += 1 for group in groups[1:]: for word in FLAG_WORDS: if group.startswith(word): flags[word] += 1 if group.startswith("Disc "): discs += 1 try: with zipfile.ZipFile(path) as archive: members = archive.infolist() except (OSError, zipfile.BadZipFile) as error: unreadable.append(f"{path.name}: {error}") continue if len(members) != 1: multi_member.append(f"{path.name}: {[m.filename for m in members]}") for member in members: member_kinds[Path(member.filename).suffix.lower() or "(none)"] += 1 if member.filename.lower().endswith(".iso"): sizes[member.file_size] += 1 total += member.file_size print(f"set: {SET_NAME}") print(f"zips: {len(zips)}") print(f"non-zip entries: {others}") print(f"distinct base titles: {len(titles)}") print(f"discs tagged (Disc N): {discs}") print(f"no region field: {no_region}") print("regions (a multi-region disc counts once per region):") for region, count in regions.most_common(): print(f" {region}: {count}") print("flags:") for word, count in flags.most_common(): print(f" {word}: {count}") print("member kinds:") for kind, count in member_kinds.most_common(): print(f" {kind}: {count}") print(f"ISO bytes, total: {total} ({total / 2**40:.2f} TiB)") print(f"distinct ISO sizes: {len(sizes)}") for size, count in sizes.most_common(12): print(f" {size} bytes ({size / 2048:.0f} sectors of 2048): {count}") print(f"zips with other than one member: {len(multi_member)}") for line in multi_member[:20]: print(f" {line}") print(f"unreadable zips: {len(unreadable)}") for line in unreadable[:20]: print(f" {line}") return 0 if __name__ == "__main__": sys.exit(main())