Merge pull request #4013 from rommapp/fix/hashes-scan-rematches-hasheous

fix(backend): re-run the Hasheous hash lookup on a hashes scan
This commit is contained in:
Georges-Antoine Assi
2026-07-30 19:23:56 -04:00
committed by GitHub
3 changed files with 269 additions and 35 deletions

View File

@@ -231,19 +231,26 @@ class HasheousHandler(MetadataHandler):
ra_id=platform["ra_id"],
)
async def lookup_rom(self, platform_slug: str, files: list[RomFile]) -> HasheousRom:
async def lookup_rom(
self, platform_slug: str, files: list[RomFile]
) -> tuple[HasheousRom, bool]:
"""Identify a ROM by its file hashes.
Returns a HasheousRom with the matched IDs, or an empty match if the
lookup fails. The lookup is best-effort and never raises to the caller,
so an unreachable Hasheous can't abort a scan.
The second value tells the two empty matches apart: True means Hasheous
answered and knows nothing about these hashes, False means we never got
an answer (disabled, no hashes to send, or the request failed). Only the
former is safe to treat as "this ROM is not in any database".
"""
fallback_rom = HasheousRom(
hasheous_id=None, igdb_id=None, tgdb_id=None, ra_id=None
)
if not self.is_enabled():
return fallback_rom
return fallback_rom, False
filtered_files = [
file
@@ -284,7 +291,7 @@ class HasheousHandler(MetadataHandler):
"No hashes provided for Hasheous lookup. "
"At least one of md5, sha1, or crc is required."
)
return fallback_rom
return fallback_rom, False
try:
hasheous_game = await self._request(
@@ -297,10 +304,10 @@ class HasheousHandler(MetadataHandler):
)
except Exception as exc:
log.error("Hasheous hash lookup failed, skipping: %s", exc)
return fallback_rom
return fallback_rom, False
if not hasheous_game:
return fallback_rom
return fallback_rom, True
metadata = hasheous_game.get("metadata", [])
attributes = hasheous_game.get("attributes", [])
@@ -331,24 +338,27 @@ class HasheousHandler(MetadataHandler):
url_cover = f"https://hasheous.org{attr['link']}"
break
return HasheousRom(
hasheous_id=hasheous_game["id"],
name=hasheous_game.get("name", ""),
igdb_id=int(igdb_id) if igdb_id else None,
tgdb_id=int(tgdb_id) if tgdb_id else None,
ra_id=int(ra_id) if ra_id else None,
url_cover=url_cover,
hasheous_metadata=HasheousMetadata(
tosec_match="TOSEC" in signatures,
mame_arcade_match="MAMEArcade" in signatures,
mame_mess_match="MAMEMess" in signatures,
nointro_match="NoIntros" in signatures,
redump_match="Redump" in signatures,
whdload_match="WHDLoad" in signatures,
ra_match="RetroAchievements" in signatures,
fbneo_match="FBNeo" in signatures,
puredos_match="PureDOS" in signatures,
return (
HasheousRom(
hasheous_id=hasheous_game["id"],
name=hasheous_game.get("name", ""),
igdb_id=int(igdb_id) if igdb_id else None,
tgdb_id=int(tgdb_id) if tgdb_id else None,
ra_id=int(ra_id) if ra_id else None,
url_cover=url_cover,
hasheous_metadata=HasheousMetadata(
tosec_match="TOSEC" in signatures,
mame_arcade_match="MAMEArcade" in signatures,
mame_mess_match="MAMEMess" in signatures,
nointro_match="NoIntros" in signatures,
redump_match="Redump" in signatures,
whdload_match="WHDLoad" in signatures,
ra_match="RetroAchievements" in signatures,
fbneo_match="FBNeo" in signatures,
puredos_match="PureDOS" in signatures,
),
),
True,
)
async def get_igdb_game(self, hasheous_rom: HasheousRom) -> HasheousRom:

View File

@@ -444,13 +444,14 @@ async def scan_rom(
gamelist_id=None,
)
async def fetch_hasheous_hash_match() -> HasheousRom:
async def fetch_hasheous_hash_match() -> tuple[HasheousRom, bool]:
if (
MetadataSource.HASHEOUS in metadata_sources
and platform.hasheous_id
and (
newly_added
or scan_type == ScanType.COMPLETE
or scan_type == ScanType.HASHES
or (scan_type == ScanType.UPDATE and rom.hasheous_id)
or (
scan_type == ScanType.UNMATCHED
@@ -463,7 +464,10 @@ async def scan_rom(
platform.slug, get_match_files()
)
return HasheousRom(hasheous_id=None, igdb_id=None, tgdb_id=None, ra_id=None)
return (
HasheousRom(hasheous_id=None, igdb_id=None, tgdb_id=None, ra_id=None),
False,
)
_added_rom = db_rom_handler.add_rom(Rom(**rom_attrs))
_added_rom.is_identifying = True
@@ -488,7 +492,7 @@ async def scan_rom(
# Run hash fetches concurrently
(
playmatch_hash_match,
hasheous_hash_match,
(hasheous_hash_match, hasheous_lookup_conclusive),
) = await asyncio.gather(
fetch_playmatch_hash_match(),
fetch_hasheous_hash_match(),
@@ -817,6 +821,7 @@ async def scan_rom(
and (
newly_added
or scan_type == ScanType.COMPLETE
or scan_type == ScanType.HASHES
or (scan_type == ScanType.UPDATE and rom.hasheous_id)
or (
scan_type == ScanType.UNMATCHED
@@ -1014,9 +1019,11 @@ async def scan_rom(
if field_value:
rom_attrs[field] = field_value
# Don't overwrite existing base fields on update and unmatched scans
if not newly_added and (
scan_type == ScanType.UNMATCHED or scan_type == ScanType.UPDATE
# Don't overwrite existing base fields on update, unmatched and hashes scans
if not newly_added and scan_type in (
ScanType.UNMATCHED,
ScanType.UPDATE,
ScanType.HASHES,
):
# A ROM's name defaults to a filename-derived placeholder when first
# created. Treat that placeholder as "no name" so a freshly matched provider
@@ -1048,6 +1055,18 @@ async def scan_rom(
}
)
# A rehash that no longer matches must drop the previous Hasheous match, or
# the ROM keeps showing verification flags earned by hashes it no longer has.
# Only a conclusive lookup clears them, so an unreachable Hasheous can't
# silently de-verify a library.
if (
scan_type == ScanType.HASHES
and hasheous_lookup_conclusive
and not hasheous_hash_match.get("hasheous_id")
):
rom_attrs["hasheous_id"] = None
rom_attrs["hasheous_metadata"] = {}
# Use PICO-8 cartridge PNG as cover art if no cover is set.
# PICO-8 .p8.png files are valid PNG images whose visual content is the
# cartridge label, so the ROM file itself serves as the cover art.