mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
Each network job had several copies. One is kept per job and every caller uses it. - Source revision: model.sourcerevision (source_revision, required_revision, platform_revision) replaces BaseTargetScraper's pattern list, the exporter's _REVISION, the four launcher_revision copies and RetroBat's own YAML reader. It reads the union of the shapes: GitHub raw, blob and tree with or without a path after the revision, GitLab raw, blob, tree and archive, codeload tar.gz and zip. The target scrapers now answer for RetroDECK, NextUI, MinUI and MyMinUI, whose tree URLs end at the commit, and the exporter reads GitLab blob and tree and codeload zip. EmuDeck and RetroBat still require a 40-hex commit, and each launcher reader requires its own repository in the URL. - Latest release: fetch_github_latest_version, type-checked, is the only lookup. mame_hash_scraper, romset_dat_importer and the Lakka target scraper call it. romset_dat_importer's NoReleaseError is gone: a release without a tag raises RuntimeError. - Tree listing: github_tree and tree_entries refuse a truncated or unreadable listing. The libretro and core-info scrapers share core_info_files and fetch_info_file, with libretro's refusal of an empty listing. The core-info listing and the RetroDECK, ROCKNIX launcher and libretro listings were not checked for truncation before. - GET: fetch_bytes is the one request path. fetch_text, fetch_present (None on 404 only), github_json and download are built on it, so every read retries 429 and 5xx, caps the body and raises FetchError, a ConnectionError carrying the HTTP status. The target scrapers' own fetch_text raised RuntimeError: they now raise FetchError, and an optional Batocera board include is skipped on 404 only, not on any failure. The exporter's originals, MiSTer, RetroPie, redump and the buildbot index go through it too. - Headers: core.upstream.forge_headers is the one builder. The token goes to api.github.com and raw.githubusercontent.com, the host compared whole, as Bearer. A URL that only names api.github.com in its query got the scrapers' token before, and profile_sync sent its token to github.com, whose release downloads redirect to asset storage with the header. Scraper reads of raw files now carry the token. - Submodule commit: submodule_commit checks that the path is a submodule. Batocera's target scraper accepted any contents answer with a sha, a directory's tree sha included. - Download: download streams through a scratch file renamed into place, retries like fetch_bytes, can keep an existing file and returns the Content-Disposition. It replaces the _download of romset_dat_importer and game_dat_importer.
227 lines
8.8 KiB
Python
227 lines
8.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Scraper for MiSTer FPGA BIOS requirements.
|
|
|
|
Source: ajgowans/BiosDB_MiSTer, branch db, file bios_db.json.zip
|
|
Format: MiSTer Downloader database (JSON inside a ZIP)
|
|
Hash: MD5
|
|
|
|
MiSTer verification logic (MiSTer-devel/Downloader_MiSTer):
|
|
- file_system.py:705-712, hash_file() is a plain MD5 of the file bytes
|
|
- jobs/process_db_index_worker.py:216, an installed file is up to date when
|
|
its MD5 equals the description hash
|
|
- jobs/process_db_index_worker.py:242, integrity checks compare MD5 only,
|
|
and the declared size is logged on failure but never gates the result
|
|
- jobs/fetch_file_worker.py:61-65, a freshly downloaded file is rejected on
|
|
MD5 mismatch
|
|
|
|
The database carries no required/optional flag: every entry is installed
|
|
unless the user sets a tag filter, which defaults to empty (config.py:161).
|
|
Entries reached through the archives section (UniBIOS) are extracted from a
|
|
remote ZIP and carry the hash of the extracted member, not of the archive.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import json
|
|
import zipfile
|
|
from datetime import datetime, timezone
|
|
|
|
from .base_scraper import (
|
|
BaseScraper,
|
|
BiosRequirement,
|
|
fetch_branch_head,
|
|
fetch_bytes,
|
|
json_object,
|
|
requirement_entry,
|
|
)
|
|
|
|
PLATFORM_NAME = "misterfpga"
|
|
|
|
BIOSDB_REPO = "ajgowans/BiosDB_MiSTer"
|
|
SOURCE_URL = (
|
|
"https://raw.githubusercontent.com/ajgowans/BiosDB_MiSTer/{rev}/bios_db.json.zip"
|
|
)
|
|
|
|
DB_MEMBER = "bios_db.json"
|
|
|
|
# Files live under games/ on the SD card, and base_destination carries that prefix
|
|
DB_ROOT = "games/"
|
|
|
|
# MiSTer core folder -> (retrobios system ID, display name, core repository)
|
|
SYSTEM_MAP = {
|
|
"3DO": ("3do", "3DO Interactive Multiplayer", "3DO_MiSTer"),
|
|
"Apple-IIgs": ("apple-iigs", "Apple IIGS", "Apple-IIgs_MiSTer"),
|
|
"Astrocade": ("bally-astrocade", "Bally Astrocade", "Astrocade_MiSTer"),
|
|
"AtariLynx": ("atari-lynx", "Atari Lynx", "AtariLynx_MiSTer"),
|
|
"CD-i": ("philips-cdi", "Philips CD-i", "CDi_MiSTer"),
|
|
"COCO3": ("coco3", "Tandy Color Computer 3", "CoCo3_MiSTer"),
|
|
"Casio_PV-2000": ("casio-pv2000", "Casio PV-2000", "Casio_PV-2000_MiSTer"),
|
|
"CreatiVision": ("creativision", "VTech CreatiVision", "CreatiVision_MiSTer"),
|
|
"GAMEBOY": ("nintendo-gb", "Game Boy / Game Boy Color", "Gameboy_MiSTer"),
|
|
"GBA": ("nintendo-gba", "Game Boy Advance", "GBA_MiSTer"),
|
|
"Gamate": ("gamate", "Bit Corporation Gamate", "Gamate_MiSTer"),
|
|
"GameCom": ("tiger-game-com", "Tiger Game.com", ""),
|
|
"Intellivision": ("mattel-intellivision", "Mattel Intellivision", "Intv_MiSTer"),
|
|
"Interact": ("interact", "Interact Home Computer", "Interact_MiSTer"),
|
|
"Jaguar": ("atari-jaguar", "Atari Jaguar", "Jaguar_MiSTer"),
|
|
"MSX1": ("microsoft-msx", "MSX1", "MSX1_MiSTer"),
|
|
"MegaCD": ("sega-mega-cd", "Sega CD / Mega-CD", "MegaCD_MiSTer"),
|
|
"N64": ("nintendo-64", "Nintendo 64", "N64_MiSTer"),
|
|
"NEOGEO": ("snk-neogeo", "Neo Geo AES / MVS", "NeoGeo_MiSTer"),
|
|
"NES": ("nintendo-nes", "NES / Famicom Disk System", "NES_MiSTer"),
|
|
"NeoGeo-CD": ("snk-neogeo-cd", "Neo Geo CD", "NeoGeo_MiSTer"),
|
|
"NeoGeoPocket": ("snk-neogeo-pocket", "Neo Geo Pocket", ""),
|
|
"PC8801": ("nec-pc-88", "NEC PC-8801", "PC88_MiSTer"),
|
|
"PSX": ("sony-playstation", "Sony PlayStation", "PSX_MiSTer"),
|
|
"PocketChallengeV2": (
|
|
"pocket-challenge-v2",
|
|
"Benesse Pocket Challenge V2",
|
|
"WonderSwan_MiSTer",
|
|
),
|
|
"PokemonMini": ("nintendo-pokemon-mini", "Pokemon Mini", "PokemonMini_MiSTer"),
|
|
"SCV": ("epoch-scv", "Epoch Super Cassette Vision", "SuperCassetteVision_MiSTer"),
|
|
"SGB": ("nintendo-sgb", "Super Game Boy", "SGB_MiSTer"),
|
|
"SNES": ("nintendo-snes", "Super NES / Super Famicom", "SNES_MiSTer"),
|
|
"Saturn": ("sega-saturn", "Sega Saturn", "Saturn_MiSTer"),
|
|
"SharpX1": ("sharp-x1", "Sharp X1", "SharpX1_Mister"),
|
|
"TGFX16-CD": ("nec-pc-engine-cd", "PC Engine CD / TurboGrafx-CD", "TurboGrafx16_MiSTer"),
|
|
"TI-99_4A": ("ti99", "Texas Instruments TI-99/4A", "TI-99_4A_MiSTer"),
|
|
"WonderSwan": ("wonderswan", "Bandai WonderSwan", "WonderSwan_MiSTer"),
|
|
"WonderSwanColor": (
|
|
"wonderswan-color",
|
|
"Bandai WonderSwan Color",
|
|
"WonderSwan_MiSTer",
|
|
),
|
|
}
|
|
|
|
|
|
def parse_db(raw: str) -> dict[str, dict]:
|
|
"""Return every installable file entry of the database, keyed by path.
|
|
|
|
Entries listed under archives are inlined: the Downloader extracts them
|
|
from a remote ZIP, and their hash describes the extracted member.
|
|
"""
|
|
data = json.loads(raw)
|
|
entries: dict[str, dict] = dict(data.get("files", {}))
|
|
for archive in data.get("archives", {}).values():
|
|
inline = archive.get("summary_inline", {}).get("files", {})
|
|
entries.update(inline)
|
|
if not entries:
|
|
raise ValueError("no file entries found in bios_db.json")
|
|
return entries
|
|
|
|
|
|
def system_of(path: str) -> str:
|
|
"""Return the core folder a database path belongs to."""
|
|
remainder = path[len(DB_ROOT):] if path.startswith(DB_ROOT) else path
|
|
return remainder.split("/", 1)[0]
|
|
|
|
|
|
class Scraper(BaseScraper):
|
|
"""Scraper for the MiSTer BiosDB database."""
|
|
|
|
def __init__(self, url: str | None = None) -> None:
|
|
# The database is published on the db branch: the commit read is recorded.
|
|
if url is None:
|
|
url = SOURCE_URL.format(rev=fetch_branch_head(BIOSDB_REPO, "db"))
|
|
super().__init__(url=url)
|
|
|
|
def _fetch_raw(self) -> str:
|
|
"""Fetch bios_db.json.zip and return the JSON it contains."""
|
|
if self._raw_data is not None:
|
|
return self._raw_data
|
|
with zipfile.ZipFile(io.BytesIO(fetch_bytes(self.url))) as archive:
|
|
self._raw_data = archive.read(DB_MEMBER).decode("utf-8")
|
|
return self._raw_data
|
|
|
|
def validate_format(self, raw_data: str) -> bool:
|
|
"""Validate the BiosDB database format."""
|
|
data = json_object(raw_data)
|
|
if data is None or data.get("db_id") != "bios_db":
|
|
return False
|
|
files = data.get("files")
|
|
if not isinstance(files, dict) or not files:
|
|
return False
|
|
return all(
|
|
isinstance(entry.get("hash"), str) and isinstance(entry.get("size"), int)
|
|
for entry in files.values()
|
|
)
|
|
|
|
def fetch_requirements(self) -> list[BiosRequirement]:
|
|
"""Parse bios_db.json and return BIOS requirements."""
|
|
raw = self._fetch_raw()
|
|
if not self.validate_format(raw):
|
|
raise ValueError("bios_db.json format validation failed")
|
|
|
|
requirements = []
|
|
for path, entry in sorted(parse_db(raw).items()):
|
|
folder = system_of(path)
|
|
system, _, _ = SYSTEM_MAP.get(folder, (folder.lower(), folder, ""))
|
|
destination = path[len(DB_ROOT):] if path.startswith(DB_ROOT) else path
|
|
requirements.append(
|
|
BiosRequirement(
|
|
name=destination.rsplit("/", 1)[-1],
|
|
system=system,
|
|
md5=entry["hash"],
|
|
size=entry.get("size"),
|
|
destination=destination,
|
|
required=True,
|
|
native_id=folder,
|
|
)
|
|
)
|
|
return requirements
|
|
|
|
def generate_platform_yaml(self) -> dict:
|
|
"""Build the MiSTer FPGA platform configuration."""
|
|
data = json.loads(self._fetch_raw())
|
|
systems: dict[str, dict] = {}
|
|
|
|
for req in self.fetch_requirements():
|
|
_, display, repo = SYSTEM_MAP.get(
|
|
req.native_id or "", (req.system, req.system, "")
|
|
)
|
|
entry = systems.setdefault(
|
|
req.system,
|
|
{
|
|
"files": [],
|
|
"native_id": req.native_id,
|
|
"name": display,
|
|
"docs": f"https://github.com/MiSTer-devel/{repo}" if repo else "",
|
|
},
|
|
)
|
|
entry["files"].append(requirement_entry(req))
|
|
|
|
for entry in systems.values():
|
|
if not entry["docs"]:
|
|
del entry["docs"]
|
|
|
|
# The BiosDB has no release: the date it was built is the only
|
|
# version the list carries, and the manifest needs one.
|
|
timestamp = data.get("timestamp")
|
|
if not isinstance(timestamp, (int, float)):
|
|
raise RuntimeError(f"{self.url}: the BiosDB records no timestamp")
|
|
released = datetime.fromtimestamp(timestamp, timezone.utc).strftime("%Y-%m-%d")
|
|
|
|
return {
|
|
"platform": "MiSTer FPGA",
|
|
"version": released,
|
|
"homepage": "https://misterfpga.org",
|
|
"source": self.url,
|
|
"base_destination": "games",
|
|
"hash_type": "md5",
|
|
"verification_mode": "md5",
|
|
"cores": [],
|
|
"systems": dict(sorted(systems.items())),
|
|
}
|
|
|
|
|
|
def main() -> None:
|
|
"""Entry point."""
|
|
from .base_scraper import scraper_cli
|
|
|
|
scraper_cli(Scraper, "Scrape MiSTer FPGA BIOS requirements")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|