mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 06:18:51 -06:00
scraper/ held the platform scrapers next to three other subjects. The launcher readers move to scraper/launchers/ (their _launchers suffix dropped), the MAME and FBNeo hash scrapers and romset importers to scraper/arcade/, the DAT readers and dump catalog importers to scraper/dats/. The buildbot check is a freshness check and moves to freshness/buildbot.py. Every -m command, workflow job, schema description and page follows. The scraper discovery in scraper/__init__.py had no caller: the registry's scraper: field names the module, and the pages now say so.
100 lines
3.5 KiB
Python
100 lines
3.5 KiB
Python
"""Fetch Redump BIOS DAT files and write a provenance snapshot.
|
|
|
|
Redump serves BIOS DATs as Logiqx files linked from
|
|
https://redump.info/downloads. The links were static files under
|
|
/static/bios/<name>.dat and are now one route per system,
|
|
/bios/<CODE> (PSX, PS2, GC, XBOX), served as an attachment. The
|
|
downloads page is scanned for either shape, so new BIOS DATs are
|
|
picked up without code changes.
|
|
|
|
Run manually, then commit the snapshot:
|
|
python -m scripts.scraper.dats.redump_dat_scraper --dry-run
|
|
python -m scripts.scraper.dats.redump_dat_scraper --output provenance/redump.json
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import re
|
|
import sys
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
|
|
from model.dumpcatalog import write_provenance_snapshot
|
|
from ..base_scraper import fetch_bytes
|
|
from .logiqx_parser import parse_logiqx, validate_logiqx_format
|
|
|
|
BASE_URL = "https://redump.info"
|
|
DOWNLOADS_URL = f"{BASE_URL}/downloads"
|
|
|
|
|
|
def _fetch(url: str) -> str:
|
|
return fetch_bytes(url).decode("utf-8", "replace")
|
|
|
|
|
|
def discover_bios_datfiles(downloads_html: str) -> list[str]:
|
|
"""Extract BIOS DAT paths from the downloads page."""
|
|
paths = set(re.findall(r'href="(/static/bios/[^"]+\.dat)"', downloads_html))
|
|
paths.update(re.findall(r'href="(/bios/[A-Za-z0-9_-]+)"', downloads_html))
|
|
return sorted(paths)
|
|
|
|
|
|
def parse_redump_dat(content: str) -> tuple[str, str, list[dict]]:
|
|
"""Parse a Redump Logiqx BIOS DAT into provenance entries.
|
|
|
|
The machine description carries the useful context (hardware
|
|
model, kernel or firmware version), so it is kept per entry.
|
|
"""
|
|
dat = parse_logiqx(content)
|
|
return dat.name, dat.version, dat.provenance_entries()
|
|
|
|
|
|
def fetch_snapshot() -> tuple[dict, list[dict]]:
|
|
"""Fetch all Redump BIOS DATs. Returns (dats metadata, entries)."""
|
|
paths = discover_bios_datfiles(_fetch(DOWNLOADS_URL))
|
|
if not paths:
|
|
raise ValueError("No BIOS datfile links found on downloads page")
|
|
dats = {}
|
|
entries = []
|
|
for path in paths:
|
|
content = _fetch(f"{BASE_URL}{path}")
|
|
if not validate_logiqx_format(content):
|
|
raise ValueError(f"Unexpected DAT format for {path}")
|
|
name, version, dat_entries = parse_redump_dat(content)
|
|
dats[name] = version
|
|
entries.extend(dat_entries)
|
|
return dats, entries
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(allow_abbrev=False, description="Fetch Redump BIOS DAT provenance")
|
|
parser.add_argument("--dry-run", action="store_true", help="Show fetched entries")
|
|
parser.add_argument(
|
|
"--output", "-o", default="provenance/redump.json", help="Snapshot output path"
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
try:
|
|
dats, entries = fetch_snapshot()
|
|
except (ConnectionError, ValueError) as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
return 1
|
|
|
|
if args.dry_run:
|
|
for dat in sorted(dats):
|
|
count = sum(1 for e in entries if e["dat"] == dat)
|
|
print(f" {dat} ({dats[dat]}): {count} entries")
|
|
print(f"\nTotal: {len(entries)} entries across {len(dats)} DATs")
|
|
return 0
|
|
|
|
Path(args.output).parent.mkdir(parents=True, exist_ok=True)
|
|
imported_at = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
|
written = write_provenance_snapshot(args.output, "redump", imported_at, dats, entries)
|
|
status = "Written" if written else "Unchanged"
|
|
print(f"{status} {args.output}: {len(entries)} entries from {len(dats)} DATs")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|