#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Census of a Redump "Sony - PlayStation 2" set, from names and zip directories only. Reads the directory named by $REDUMP_DIR (or --dir), sub-folder "Sony - PlayStation 2": one .zip per disc. Nothing is extracted, copied or hashed. Each zip's central directory (member names and sizes) is read: a DVD image is one .iso; a CD image is a .cue with one or more .bin tracks. DVD-9 (dual layer) is inferred from size above DVD-5's 4,700,372,992 bytes (HYPOTHESIS: size, not the disc's layer field, which only the image holds). REDUMP_DIR=... python -I scripts/census_redump.py > tests/detectors/census-redump-ps2-.txt """ from __future__ import annotations import argparse import collections import os import re import sys import zipfile from pathlib import Path DVD5_BYTES = 4_700_372_992 REGIONS = ("USA", "Europe", "Japan", "Asia", "Korea", "Germany", "France", "Italy", "Spain", "UK", "Australia", "Brazil", "Netherlands", "Sweden", "Russia", "World", "Taiwan", "China", "Canada", "Poland", "Greece", "Scandinavia", "Portugal", "Hong Kong") TAGS = ("Demo", "Beta", "Proto", "Rev", "Kiosk", "Taikenban", "Promo", "Bonus Disc", "Alt", "Unl", "Disc 1", "Disc 2", "Disc 3", "Disc 4") def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("--dir", default=os.environ.get("REDUMP_DIR"), help="default $REDUMP_DIR") parser.add_argument("--system", default="Sony - PlayStation 2") args = parser.parse_args() if not args.dir: print("set REDUMP_DIR or pass --dir", file=sys.stderr) return 2 root = Path(args.dir) / args.system names = sorted(p.name for p in root.iterdir() if p.suffix.lower() == ".zip") print(f"set: $REDUMP_DIR/{args.system}") print(f"disc zips present: {len(names)}") note = Path(args.dir) / f"{args.system}.txt" if note.exists(): print(f"note beside the set ({note.name}): {note.read_text(errors='replace').strip()!r}") kinds: collections.Counter[str] = collections.Counter() regions: collections.Counter[str] = collections.Counter() tags: collections.Counter[str] = collections.Counter() tracks: collections.Counter[int] = collections.Counter() total = {"dvd": 0, "cd": 0} dvd9 = 0 largest = (0, "") errors = 0 titles: set[str] = set() for name in names: stem = name[:-4] groups = re.findall(r"\(([^)]*)\)", stem) for group in groups: parts = [p.strip() for p in group.split(",")] if any(p in REGIONS for p in parts): for p in parts: regions[p] += 1 break for group in groups: for tag in TAGS: if group == tag or group.startswith(tag + " "): tags[tag] += 1 titles.add(re.sub(r"\s*\(.*$", "", stem)) try: with zipfile.ZipFile(root / name) as archive: members = archive.infolist() except (OSError, zipfile.BadZipFile): errors += 1 continue isos = [m for m in members if m.filename.lower().endswith(".iso")] bins = [m for m in members if m.filename.lower().endswith(".bin")] if isos and not bins: kinds["DVD (.iso)"] += 1 size = sum(m.file_size for m in isos) total["dvd"] += size dvd9 += size > DVD5_BYTES largest = max(largest, (size, stem)) elif bins: kinds["CD (.cue/.bin)"] += 1 tracks[len(bins)] += 1 total["cd"] += sum(m.file_size for m in bins) else: kinds["other: " + ",".join(sorted({Path(m.filename).suffix for m in members}))] += 1 print(f"zip directories unreadable: {errors}") print(f"distinct base titles (text before the first parenthesis): {len(titles)}") print("\nmedia:") for kind, count in kinds.most_common(): print(f" {kind:20} {count}") print(f" DVD images above DVD-5 size (dual layer, DVD-9): {dvd9}") print(f" largest DVD image: {largest[0]} bytes ({largest[1]})") print(f" DVD bytes: {total['dvd'] / 2**40:.2f} TiB; CD .bin bytes: {total['cd'] / 2**30:.1f} GiB") print("\nCD .bin tracks per disc:") for count, discs in sorted(tracks.items()): print(f" {count:3} track(s): {discs}") print("\nregions (a multi-region disc counts once per region):") for region, count in regions.most_common(): print(f" {region:12} {count}") print("\ntags:") for tag, count in tags.most_common(): print(f" {tag:12} {count}") return 0 if __name__ == "__main__": sys.exit(main())