mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
* feat(platforms): split arcade aliases into per-emulator-family slugs Give MAME, AdvanceMAME, FBNeo, FBA, Daphne, Singe and the arcade boards that need their own emulator (NAOMI/NAOMI 2/NAOMI GD-ROM, Model 2/3, Hikaru, Triforce, Lindbergh, Namco System 246/3xx, Gaelco, ...) their own slugs with verified provider IDs. Providers without a dedicated entry fall back to their Arcade platform via arcade_fallbacks(). MAME-only boards (CPS1-3, System 16/32, Model 1, Namco 22) stay aliases of arcade. Refs #5272 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(platforms): code-review pass on arcade slugs - Retry IGDB on unmatched scans for every platform IGDB resolves, not just slugs in IGDB_PLATFORM_LIST. - Resolve config binding/version values through the alias table, so a binding to a retired slug (cps2, model1, ...) still lands on a platform. - Alias the Batocera `typex` folder to type-x. - Build provider id->slug reverse maps before merging Arcade fallbacks. - Share one MAME title lookup between base_handler and libretro. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(platforms): simplify pass on arcade slugs - Alias the three RomM-keyed IGDB versions inside IGDB_PLATFORM_VERSIONS, dropping IGDB_VERSION_SLUGS and _version_slug. - Derive EmulatorJS arcade entries from ARCADE_SET_PLATFORMS. - Remove the unused provider id->slug reverse maps, so the Arcade fallback merge no longer has an ordering constraint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(platforms): humanizer pass on arcade slug comments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(platforms): settle arcade slug review decisions - Migration 0154 moves platforms still on a retired MAME-only board slug (cps1-3, model1, system16, system32, system-32) to arcade, so no row carries a slug the enum no longer has. - MAME shortname expansion keys off the RomM slug via MAME_SHORTNAME_PLATFORMS instead of per-provider arcade ids, so Daphne, Singe, Type X and Lindbergh sets are no longer read as MAME sets. Neo Geo now expands at ScreenScraper too, as it already did at IGDB and Moby. - fba offers fbneo before the FinalBurn Alpha CPS cores. - AdvanceMAME leaves the WebRcade feed; EmulatorJS and WebRcade share PLAYABLE_ARCADE_SET_PLATFORMS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(platforms): code-review pass (xhigh) on arcade slugs Verify arcade-board BIOS files against the known list's arcade entries, and make migration 0154 match retired slugs case-insensitively. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(platforms): simplify pass on arcade slugs Apply IGDB family overrides once in get_platform instead of on each return path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(platforms): use a slug with no shipped icon singe now ships an icon, so the no-icon prefetch test needs a slug that never will. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(platforms): add a teknoparrot arcade slug TeknoParrot runs PC-based arcade boards outside the MAME/FinalBurn family, so its folder gets its own platform (RetroBat and ES-DE both use `teknoparrot`). Providers fall back to their Arcade entry, MAME shortname expansion skips it, and it gets a placeholder icon copied from `arcade`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(platforms): give each arcade-family icon its own marquee title Redraws the ARCADE marquee on the copied cabinet icons with each platform's name, in the Bungee typeface with the original inline and extrusion styling. Sega boards use Sega blue, Namco systems Namco red, and Type X Taito blue; the rest keep the original amber. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(platforms): code-review pass (xhigh) on arcade slugs Neo Geo BIOS lives under arcade in the known BIOS list, so map neogeoaes and neogeomvs there too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(platforms): simplify pass on arcade slug tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
296 lines
10 KiB
Python
296 lines
10 KiB
Python
import re
|
|
from typing import Any
|
|
|
|
from config import LAUNCHBOX_API_ENABLED
|
|
from handler.filesystem import fs_rom_handler
|
|
from handler.redis_handler import async_cache
|
|
from logger.logger import log
|
|
from utils.arcade_platforms import MAME_SHORTNAME_PLATFORMS
|
|
from utils.cache import is_cache_store_ready
|
|
from utils.database import safe_int
|
|
from utils.platform_slugs import UniversalPlatformSlug as UPS
|
|
|
|
from ..base_handler import (
|
|
MetadataHandler,
|
|
tag_id_from_filename,
|
|
)
|
|
from .local_source import LocalSource
|
|
from .media import build_rom, local_media_req, remote_media_req
|
|
from .platforms import get_platform
|
|
from .remote_source import RemoteSource
|
|
from .types import (
|
|
DASH_COLON_REGEX,
|
|
LAUNCHBOX_METADATA_INITIAL_IMPORT_KEY,
|
|
LAUNCHBOX_METADATA_NAME_KEY,
|
|
LAUNCHBOX_METADATA_STORE,
|
|
LAUNCHBOX_PLATFORMS_DIR,
|
|
LAUNCHBOX_TAG_REGEX,
|
|
LaunchboxPlatform,
|
|
LaunchboxRom,
|
|
)
|
|
|
|
|
|
class LaunchboxHandler(MetadataHandler):
|
|
def __init__(self) -> None:
|
|
self._local = LocalSource()
|
|
self._remote = RemoteSource()
|
|
|
|
@classmethod
|
|
def is_cloud_enabled(cls) -> bool:
|
|
return LAUNCHBOX_API_ENABLED
|
|
|
|
@classmethod
|
|
def is_local_enabled(cls) -> bool:
|
|
return LAUNCHBOX_PLATFORMS_DIR.exists()
|
|
|
|
@classmethod
|
|
def is_enabled(cls) -> bool:
|
|
return cls.is_cloud_enabled() or cls.is_local_enabled()
|
|
|
|
@staticmethod
|
|
async def is_remote_store_populated() -> bool:
|
|
return await is_cache_store_ready(
|
|
async_cache, LAUNCHBOX_METADATA_STORE, LAUNCHBOX_METADATA_NAME_KEY
|
|
)
|
|
|
|
@staticmethod
|
|
async def is_remote_store_importing() -> bool:
|
|
return bool(await async_cache.exists(LAUNCHBOX_METADATA_INITIAL_IMPORT_KEY))
|
|
|
|
async def heartbeat(self) -> bool:
|
|
if self.is_local_enabled():
|
|
return True
|
|
|
|
if not self.is_cloud_enabled():
|
|
return False
|
|
|
|
# A first import commits in batches, so the store starts answering for a
|
|
# handful of names long before it holds the whole dump. Until that run
|
|
# finishes, most lookups still miss.
|
|
if await self.is_remote_store_importing():
|
|
return False
|
|
|
|
# Cloud lookups read from a cache the metadata update task fills. Until
|
|
# it has run, every lookup returns nothing, so reporting healthy here
|
|
# would be a lie.
|
|
return await self.is_remote_store_populated()
|
|
|
|
def get_platform(self, slug: str) -> LaunchboxPlatform:
|
|
return get_platform(slug)
|
|
|
|
async def get_rom(
|
|
self,
|
|
fs_name: str,
|
|
platform_slug: str,
|
|
keep_tags: bool = False,
|
|
*,
|
|
remote_enabled: bool = True,
|
|
) -> LaunchboxRom:
|
|
fallback_rom = LaunchboxRom(launchbox_id=None)
|
|
|
|
if not self.is_enabled():
|
|
return fallback_rom
|
|
|
|
local = await self._local.get_rom(fs_name, platform_slug)
|
|
|
|
remote_available = remote_enabled and await self.is_remote_store_populated()
|
|
|
|
if local is not None:
|
|
launchbox_id_local = safe_int(local.get("DatabaseID"))
|
|
remote: dict[str, Any] | None = None
|
|
if remote_available:
|
|
if launchbox_id_local:
|
|
remote = await self._remote.get_by_id(launchbox_id_local)
|
|
|
|
if remote is None:
|
|
local_title = (local.get("Title") or "").strip()
|
|
if local_title:
|
|
remote = await self._remote.get_rom(
|
|
local_title,
|
|
platform_slug,
|
|
assume_cache_present=True,
|
|
)
|
|
platform_name = get_platform(platform_slug).get("name")
|
|
remote_images = await self._remote.fetch_images(
|
|
remote=remote, remote_enabled=remote_available
|
|
)
|
|
media_req = local_media_req(
|
|
platform_name=platform_name,
|
|
fs_name=fs_name,
|
|
local=local,
|
|
remote=remote,
|
|
remote_images=remote_images,
|
|
remote_enabled=remote_available,
|
|
)
|
|
return build_rom(
|
|
local=local,
|
|
remote=remote,
|
|
launchbox_id=launchbox_id_local
|
|
or (remote.get("DatabaseID") if remote else None),
|
|
media_req=media_req,
|
|
)
|
|
|
|
launchbox_id_from_tag = tag_id_from_filename(LAUNCHBOX_TAG_REGEX, fs_name)
|
|
|
|
if launchbox_id_from_tag is not None:
|
|
log.debug(f"Found LaunchBox ID tag in filename: {launchbox_id_from_tag}")
|
|
rom_by_id = await self.get_rom_by_id(
|
|
launchbox_id_from_tag, remote_enabled=remote_enabled
|
|
)
|
|
if rom_by_id["launchbox_id"]:
|
|
log.debug(
|
|
f"Successfully matched ROM by LaunchBox ID tag: {fs_name} -> {launchbox_id_from_tag}"
|
|
)
|
|
return rom_by_id
|
|
else:
|
|
log.warning(
|
|
f"LaunchBox ID {launchbox_id_from_tag} from filename tag not found in LaunchBox"
|
|
)
|
|
|
|
if not remote_available:
|
|
return fallback_rom
|
|
|
|
# LaunchBox indexes the filenames its own dumps use, so try that before
|
|
# rewriting the name into something the title index might accept.
|
|
index_entry = await self._remote.get_rom_by_file_name(fs_name, platform_slug)
|
|
|
|
if index_entry is None:
|
|
# `keep_tags` prevents stripping content that is considered a tag, e.g., anything between `()` or `[]`.
|
|
# By default, tags are still stripped to keep scan behavior consistent with previous versions.
|
|
# If `keep_tags` is True, the full `fs_name` is used for searching.
|
|
if not keep_tags:
|
|
search_term = fs_rom_handler.get_file_name_with_no_tags(fs_name)
|
|
else:
|
|
search_term = fs_name
|
|
|
|
# The rewrites below are anchored on spaces, so a dump that separates
|
|
# words with underscores reaches none of them.
|
|
search_term = search_term.replace("_", " ")
|
|
|
|
# Resolve MAME arcade filename (e.g. wrlok_l3.zip) to its full title
|
|
# via LaunchBox's Mame.xml before name-based lookup.
|
|
if platform_slug in MAME_SHORTNAME_PLATFORMS:
|
|
mame_entry = await self._remote.get_mame_entry(fs_name)
|
|
if mame_entry:
|
|
name = (mame_entry.get("Name") or "").strip()
|
|
if name:
|
|
search_term = name
|
|
fallback_rom = LaunchboxRom(launchbox_id=None, name=name)
|
|
|
|
# We replace " - "/"- " with ": " to match Launchbox's naming convention
|
|
search_term = re.sub(DASH_COLON_REGEX, ": ", search_term).lower()
|
|
|
|
# Check if game is scummvm shortname
|
|
if platform_slug == UPS.SCUMMVM:
|
|
search_term = await self._scummvm_format(search_term)
|
|
fallback_rom = LaunchboxRom(launchbox_id=None, name=search_term)
|
|
|
|
index_entry = await self._remote.get_rom(
|
|
search_term,
|
|
platform_slug,
|
|
assume_cache_present=True,
|
|
)
|
|
|
|
if not index_entry:
|
|
return fallback_rom
|
|
|
|
remote_images = await self._remote.fetch_images(
|
|
remote=index_entry, remote_enabled=remote_available
|
|
)
|
|
media_req = remote_media_req(
|
|
remote=index_entry,
|
|
remote_images=remote_images,
|
|
remote_enabled=remote_available,
|
|
platform_name=get_platform(platform_slug).get("name"),
|
|
fs_name=fs_name,
|
|
)
|
|
|
|
return build_rom(
|
|
local=None,
|
|
remote=index_entry,
|
|
launchbox_id=index_entry["DatabaseID"],
|
|
media_req=media_req,
|
|
)
|
|
|
|
async def get_rom_by_id(
|
|
self,
|
|
database_id: int,
|
|
*,
|
|
remote_enabled: bool = True,
|
|
fs_name: str | None = None,
|
|
platform_slug: str | None = None,
|
|
) -> LaunchboxRom:
|
|
if not self.is_enabled():
|
|
return LaunchboxRom(launchbox_id=None)
|
|
|
|
if not remote_enabled:
|
|
return LaunchboxRom(launchbox_id=None)
|
|
|
|
remote = await self._remote.get_by_id(database_id)
|
|
if not remote:
|
|
return LaunchboxRom(launchbox_id=None)
|
|
|
|
# Merge local-only fields when a local LaunchBox install has the same game
|
|
local: dict[str, str] | None = None
|
|
if fs_name and platform_slug:
|
|
candidate = await self._local.get_rom(fs_name, platform_slug)
|
|
if (
|
|
candidate is not None
|
|
and safe_int(candidate.get("DatabaseID")) == database_id
|
|
):
|
|
local = candidate
|
|
|
|
platform_name = (
|
|
get_platform(platform_slug).get("name") if platform_slug else None
|
|
)
|
|
remote_images = await self._remote.fetch_images(
|
|
remote=remote, remote_enabled=remote_enabled
|
|
)
|
|
if local is not None:
|
|
media_req = local_media_req(
|
|
platform_name=platform_name,
|
|
fs_name=fs_name or "",
|
|
local=local,
|
|
remote=remote,
|
|
remote_images=remote_images,
|
|
remote_enabled=remote_enabled,
|
|
)
|
|
else:
|
|
media_req = remote_media_req(
|
|
remote=remote,
|
|
remote_images=remote_images,
|
|
remote_enabled=remote_enabled,
|
|
platform_name=platform_name,
|
|
fs_name=fs_name or "",
|
|
)
|
|
|
|
return build_rom(
|
|
local=local,
|
|
remote=remote,
|
|
launchbox_id=database_id,
|
|
media_req=media_req,
|
|
)
|
|
|
|
async def get_matched_roms_by_name(
|
|
self, search_term: str, platform_slug: str
|
|
) -> list[LaunchboxRom]:
|
|
if not self.is_enabled():
|
|
return []
|
|
|
|
if self.is_cloud_enabled() and not await self.is_remote_store_populated():
|
|
log.warning(
|
|
"LaunchBox metadata store is empty, so no cloud results can be "
|
|
"returned. Set ENABLE_SCHEDULED_UPDATE_LAUNCHBOX_METADATA=true and "
|
|
"run the LaunchBox metadata update task to populate it."
|
|
)
|
|
|
|
rom = await self.get_rom(search_term, platform_slug, keep_tags=True)
|
|
return [rom]
|
|
|
|
async def get_matched_rom_by_id(self, database_id: int) -> LaunchboxRom | None:
|
|
if not self.is_enabled():
|
|
return None
|
|
|
|
rom = await self.get_rom_by_id(database_id)
|
|
return rom if rom.get("launchbox_id") else None
|