Commit Graph

318 Commits

Author SHA1 Message Date
Georges-Antoine Assi
fbbadb7c86 refactor(scan): give the title id one resolver and one identity shape
The Tinfoil feed was left behind when `_switch_productid_format` changed
from taking a `re.Match` to taking a `str`, so `/feeds/tinfoil` raised a
TypeError for any Switch rom carrying a product id in its filename but no
titledb id. It went unnoticed because `feeds.py` sits outside the changed
files mypy sees.

That call site was reachable only because "prefer the id the scan read over
the one scraped from the filename" lived in a second helper above the lookup,
leaving each caller to remember it. The resolution now happens inside
`_switch_productid_format`, so the three providers and the feed all get it
without repeating a preamble.

Also:

- Move `SWITCH_PLATFORM_SLUGS` to the sigil adapter so `utils/switch.py`
  stops importing the metadata base handler. The cycle that import created
  was papered over with a function-local import, and `normalize_identity`
  now takes the fact it needs rather than the whole slug set.
- Merge a partial identity update onto the stored identity before
  normalizing it. Normalizing rewrites the whole triple, so a client sending
  only a title id was getting the derived base id next to its old save
  target.
- Add `RomIdentity.from_rom` so the triple has one home on the read side
  too, and drop `asdict` from `as_rom_attrs`.
- Hold the `SigilExtractionResult` on `TitleIdEmbedCandidate` instead of
  copying two of its fields.
- Drop a guard in `_rom_level_identity` that could not fire, derive once in
  `normalize_identity`, and return only the parse from `_rebuild_rom_files`,
  which already owns `fs_rom["fs_name"]`.
- Read the parsed config in the heartbeat rather than forcing a YAML
  re-parse per request, and make `SigilService.is_enabled` a classmethod
  like every other one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 10:57:36 -04:00
Georges-Antoine Assi
e19394e969 feat(scan): surface title id extraction and feed it to metadata matching
The optional binding used to no-op in silence: an absent sigil was
indistinguishable from a file with no title id. `SigilService.is_enabled`
plus `FILESYSTEM.TITLE_ID_EXTRACTION_ENABLED` on the heartbeat put the
feature on the same footing as every other optional capability, and give
a client of `PUT /roms/{id}/identity` a way to ask whether the server
reads binaries at all.

The extracted id also reaches the layer that already matches on Switch
product ids. Until now that layer could only scrape one out of the
filename, which made `embed_switch_title_ids` the de facto transport:
users had to let RomM rewrite their filenames for matching to improve.
`switch_product_id` prefers the id read from the binary, so extraction
helps everyone with the binding and the rename stays cosmetic.

MobyGames' `get_rom` takes the rom, like its IGDB and ScreenScraper
siblings, and the product-id lookup now happens only on Switch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 17:26:19 -04:00
Georges-Antoine Assi
355eee2190 refactor(scan): give the binary identity one shape and one writer
`RomIdentity` replaces the title_id / save_target / save_target_layout
triple that was spelled out separately on `ParsedRomFiles`, in `FSRom`,
and again in the scan's attribute merge.

`switch.normalize_identity` is now the single place that forces a Switch
id onto the base game's, which both the scan and `PUT /roms/{id}/identity`
call. The rule was written twice before, and the two copies disagreed
about what an update's save target should be. The endpoint keeps its
merge semantics: an omitted field is still left alone.

`get_rom_files` is a read again. It records which files can carry their
title id, and the new `embed_switch_title_ids` step performs the renames,
so writing to the user's library is a named call the scan makes rather
than a side effect smuggled out on a parse result.

The Switch family now lives in `utils/switch.py` in RomM's own terms,
instead of being recovered by filtering the sigil adapter's slug map.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 17:26:18 -04:00
Georges-Antoine Assi
7036ae0e9c Merge remote-tracking branch 'origin/master' into feature/sigil-title-ids 2026-09-02 16:34:48 -04:00
Georges-Antoine Assi
a7a15754b0 Merge remote-tracking branch 'origin/master' into claude/steam-metadata-provider
# Conflicts:
#	backend/config/__init__.py
#	backend/config/config_manager.py
#	backend/endpoints/heartbeat.py
#	backend/endpoints/responses/heartbeat.py
#	backend/endpoints/responses/rom.py
#	backend/endpoints/roms/__init__.py
#	backend/handler/database/roms_handler.py
#	backend/handler/metadata/__init__.py
#	backend/handler/scan_handler.py
#	backend/models/rom.py
#	backend/tasks/scheduled/scan_library.py
#	backend/watcher.py
#	env.template
#	frontend/src/__generated__/models/Body_update_rom_api_roms__id__put.ts
#	frontend/src/__generated__/models/DetailedRomSchema.ts
#	frontend/src/__generated__/models/MetadataSourcesDict.ts
#	frontend/src/__generated__/models/SimpleRomSchema.ts
#	frontend/src/locales/bg_BG/settings.json
#	frontend/src/locales/cs_CZ/settings.json
#	frontend/src/locales/de_DE/settings.json
#	frontend/src/locales/en_GB/settings.json
#	frontend/src/locales/en_US/settings.json
#	frontend/src/locales/es_ES/settings.json
#	frontend/src/locales/fr_FR/settings.json
#	frontend/src/locales/hu_HU/settings.json
#	frontend/src/locales/it_IT/settings.json
#	frontend/src/locales/ja_JP/settings.json
#	frontend/src/locales/ko_KR/settings.json
#	frontend/src/locales/pl_PL/settings.json
#	frontend/src/locales/pt_BR/settings.json
#	frontend/src/locales/ro_RO/settings.json
#	frontend/src/locales/ru_RU/settings.json
#	frontend/src/locales/tr_TR/settings.json
#	frontend/src/locales/zh_CN/settings.json
#	frontend/src/locales/zh_TW/settings.json
#	frontend/src/services/api/rom.ts
#	frontend/src/stores/heartbeat.ts
#	frontend/src/v2/components/EditRom/MetadataIdSection.vue
#	frontend/src/v2/components/GameDetails/RelatedGameCard.vue
#	frontend/src/v2/components/GameDetails/providers.ts
#	frontend/src/v2/components/Scan/ScanInfoDialog.vue
#	frontend/src/v2/utils/metadataProviders.ts
#	frontend/src/v2/views/Settings/ScanSettings.vue
2026-09-01 16:49:24 -04:00
Georges-Antoine Assi
9f7b273d70 fix(metadata): keep the scene lock across a failed provider lookup
scene_locked was computed only from the current scan's matches, so a Demozoo
outage on a rescan released the lock and let the catalogs write the cover, and
on a complete scan the name and summary, of an already identified production.
Base the lock on the persisted ids as well; deselecting the source on a
complete rescan clears them, which stays the way out.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-31 21:07:53 -04:00
nendo
e04b6035f2 Merge upstream master into feature/sigil-title-ids
Upstream took 0113, so the sigil migration rechains onto
0113_roms_locked_fields as 0114. The sigil build stage keeps its place
ahead of the emulator stage, which upstream renamed for js-dos.
2026-08-31 11:39:53 +09:00
Georges-Antoine Assi
fc46c3eb1c Merge branch 'master' into feat/demozoo-pouet-phase0
Renumber the two migrations onto master's head: 0108/0109 collided with
0108_roms_primary_region and 0109_rom_files_category_index, leaving the
chain with two heads. They are now 0114 and 0115 behind 0113.

Both rebuild the roms_facets sync triggers from a hardcoded column list,
so add the publishers and developers columns 0112 introduced. Without
them the rebuilt triggers would have silently stopped mirroring the two.

Adopt master's provider taxonomy. METADATA_PROVIDER_GROUPS now carries
demozoo, pouet, and csdb as catalogs, which replaces the branch's own
GENERAL_PROVIDER_KEYS set and feeds the setup wizard, the scan dialog,
and Settings from one registry. CSDb reaches the scan explainer for the
first time; it was already selectable there.

Regenerate the frontend types: DetailedRomSchema was missing the three
metadata blobs the backend has always declared on RomSchema, and the
blobs are now typed rather than Record<string, unknown>.

Correct the setup strings that still called the three sources enabled by
default, and sort the locale keys.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-30 21:32:11 -04:00
Georges-Antoine Assi
c0d01c58ee fix(metadata): harden the scene metadata handlers
Security review follow-ups on the Demozoo, Pouet, and CSDb handlers.

Default the three sources to off, matching every other provider. They
were the only ones defaulting to on, so an upgrade began contacting
demozoo.org, pouet.net, and csdb.dk on the next scan with no operator
opt-in, reachable through the unauthenticated metadata heartbeat.

Guard the bare id conversion in scene_id_or_none. str.isdigit() accepts
superscripts and other digits int() rejects, so a pasted "²" raised out
of the Edit ROM endpoint as a 500.

Filter the remote demozoo_url through http_url(). It was the only one of
the three URL fields taking a string from the API rather than building
one from a hardcoded template and an integer id.

Match a YouTube id against an explicit ASCII class. isalnum() is
Unicode-aware, so it accepted ids the embed URL never can.

Stream the CSDb response against a byte budget. The cap ran after the
whole body was already buffered, so it bounded the parse but not memory.

Catch defusedxml's refusals. EntitiesForbidden derives from ValueError
and ParseError from SyntaxError, so the existing handler caught neither
and an entity-declaring document raised out of production_from_xml.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-30 20:49:14 -04:00
nendo
64a1b57661 refactor(scan): name the save fields for what they address
`save_id` collided with two other meanings in the codebase: `Save` is a
model, and `DeviceSaveSync.save_id` is a foreign key to it. Neither is
what this field holds, which is the on-disk name an emulator gives a
game's saves. It becomes `save_target`, and `save_usage`, which said
nothing about what it decided, becomes `save_target_layout`. Both carry
a `doc=` so the meaning is at hand where the columns are read.

The per-file copies are gone. Nothing read `RomFile.save_id`, and the
per-file `title_id` and `title_version` only fed display chips, while
the category derived from the binary content type is what actually
drives update and DLC behaviour and stays. Save layout belongs to a
game rather than to one of its files, so a client can no longer read a
file's value and build a wrong directory from it.
2026-08-30 13:22:53 +09:00
Georges-Antoine Assi
c3e7aed3ea style: cut the artwork lock comments to the fact each one carries
The rationale for the locking scheme lives in the migration docstring and the
PR; the code only needs the part a reader cannot recover from it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 20:38:22 -04:00
Georges-Antoine Assi
5f9eb14719 refactor(resources): fetch the screenshots that are missing, not the whole set
Review of the artwork-provenance work turned up two gaps behind the cleanup.

The new skip gate compared files on disk against the number of urls, so a
permanently dead url held the count below the target forever and every scan
refetched the entire set. Going index by index refetches only what is absent,
and lets `_store_screenshot` report success instead of the caller stating the
file back off the disk it just wrote.

The SGDB block still read `path_cover_s` to decide whether a cover was hand
supplied, the inferred marker `locked_fields` exists to replace. That also
shielded scraped covers from a better ranked source, which is the behaviour
this branch set out to fix, so it now asks the lock like the block above it.

The rest is cleanup: drop the dead `screenshots_exist`, give the column one
normal form across its writers, hoist the duplicated clear-out dict in
`delete_rom_manuals`, and drop the blanket backfill UPDATE, since a NULL
already reads as "no locks" everywhere.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 19:56:39 -04:00
Georges-Antoine Assi
005db06525 Merge remote-tracking branch 'origin/master' into fix/artwork-provenance-update-scan 2026-08-29 19:21:27 -04:00
Sam Dornan
b2e3de4772 Merge branch 'master' into claude/steam-metadata-provider
Resolves the additive conflicts against master:

- config, handler registry and the roms endpoint imports keep both the
  Steam and the new UPC-lookup entries.
- Renumbers the Steam migration to 0113 (master took 0109) and rebases it
  onto 0112_publisher_developer_split.
- Syncs the migration's pre-Steam facet mirror list with 0112, which added
  publishers/developers to the roms_facets triggers.
- Groups SteamMetadata's publishers/developers with the shared provider
  keys, now that master has made them a shared field.
2026-08-29 16:36:58 -05:00
nendo
7e824d4977 Merge remote-tracking branch 'upstream/master' into feature/sigil-title-ids 2026-08-28 10:58:01 +09:00
Georges-Antoine Assi
c78424b2a8 fix: reject a duplicate physical game instead of suffixing its name
build_physical_fs_name probed for an existing row and appended " (2)", " (3)"
and so on, which silently minted a second entry for a title the platform
already had. Two copies of one physical game on one platform is not a library
anyone owns, and the unique index on (platform_id, fs_name) already says so.

Drop the loop and its per-creation SELECT: the sanitized name is the fs_name,
and a duplicate falls through to the IntegrityError handler the endpoint
already had. Reword its 409 accordingly, since a duplicate is now the ordinary
way to reach it rather than a race. The add-physical-game dialog already
surfaces `detail` in an error snackbar, so it needs no change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 07:32:18 -04:00
nendo
5425a227ab Merge upstream master into feature/sigil-title-ids
Upstream took 0108 through 0110, so the four sigil migrations rechain
onto 0110_walkthrough_docs as 0111 through 0114. RomFile keeps both the
title id index and upstream's new rom_id/category composite, and
models/rom.py keeps SaveUsage alongside the new document types.
2026-08-26 19:40:48 +09:00
Georges-Antoine Assi
08901ca3a9 cleanup: reuse, simplify and trim the physical-games feature
Backend:

- Drop the post-scan re-assert of is_physical/upc/fs_path in
  create_physical_rom; scan_rom already forwards them in rom_attrs. The test
  fake was written to drop those fields to exercise the dead path, so it now
  matches the real scan_rom contract.
- Extract build_hashless_fs_rom() and use it from both the physical endpoint
  and the scan socket, which built the same FSRom literal by hand.
- Return added_rom instead of re-fetching it; add_rom is already decorated
  with @with_details, so get_rom repeated the whole eager-load fan-out.
- Pair invalidate_filter_values_cache() with refresh_affected_smart_collections(),
  as every other rom-mutating endpoint does.
- Reword the 409 detail: build_physical_fs_name uniquifies the name, so an
  IntegrityError can only mean a concurrent add.
- upc_handler: inline the single-use base_url and hoist the minimum title
  length to a module constant.

Frontend:

- Load BarcodeScannerDialog lazily. GlobalDialogs is mounted on every page, so
  the static import chain put ZXing (~438 KB) in the eager layout chunk. The
  scanner's watcher now runs immediate/post so it still starts when mounted
  behind a v-if.
- Guard the scanner against a teardown that races the decodeFromConstraints
  await; closing during the permission prompt left the camera on and the
  decode loop running.
- Render the UPC scan trigger through RTextField's append-inner adornment
  instead of a hand-built flex row.
- Type the createPhysicalRom payload with the generated PhysicalRomCreateForm
  and drop the metadataSources argument, which had no caller.
- Declare @zxing/library directly; it was imported but resolved transitively.
- Drop two write-only refs, scope the reader local to startCamera, and trim
  comments that restate the code.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-25 20:47:56 -04:00
Georges-Antoine Assi
69938b1cee add support for physical (DB only) games 2026-08-25 20:19:05 -04:00
Sam Dornan
ba00e0f270 refactor(steam): extract resolve_steam_rom so the match choice is testable
The ID-vs-filename decision sat in a closure inside scan_rom, out of reach
of a unit test. Lifts it to a module-level resolver, as LaunchBox already
does, and covers both scan types plus the stored-ID case.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-22 13:37:53 -05:00
Sam Dornan
16d9b361d8 fix(steam): refetch by stored app ID instead of re-searching
An UPDATE scan re-ran the fuzzy filename search even when the ROM already
carried a Steam ID, so a different app scoring above the similarity floor
could replace a match a user had pinned by hand. Refetch the stored ID
instead, as moby, ss, sgdb and flashpoint already do.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-22 13:37:53 -05:00
Sam Dornan
6a8cb34645 feat(steam): add the Steam storefront as a metadata provider
Steam covers the PC platforms RomM otherwise has thin metadata for, and
its store payload is provider-grade on its own: title, description,
portrait capsule art, screenshots, genres, developers, publishers,
release date and Metacritic score, with no API key.

Valve documents no storefront API, so this reads the two endpoints that
back the store's own search box and app pages, paced well under the ~200
requests per 5 minutes they tolerate. Every failure path degrades to "no
match" rather than aborting a scan, and the provider is opt-in behind
STEAM_API_ENABLED, matching HowLongToBeat and Flashpoint.

Matching is gated on the platform slug so the three PC platforms are the
only ones that spend a request. The storefront's search index carries
DLC, soundtracks and tools alongside games, so hits are filtered by type
and then confirmed against the app page, which is the only place a demo
or a video is distinguishable from a game. A (steam-12345) filename tag
pins a match by hand when the title is ambiguous.

SteamMetadata reuses the key names the other providers already use for
the values they share, so wiring Steam into the generated facet columns
later is a SQL change with no stored-row reshaping.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-22 13:35:42 -05:00
Georges-Antoine Assi
7f8f87e538 refactor(hltb): inline the HowLongToBeat match resolution
The helper had a single caller, so the stored-ID branch now sits in
fetch_hltb_rom like the Flashpoint and MobyGames fetchers. Its tests move
with it and drive the same six cases through scan_rom.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 11:27:54 -04:00
Sam Dornan
3b9acc3e34 docs(hltb): state which scans resolve by stored ID
The docstring read as though a stored ID always wins, but the ID branch is
scoped to UPDATE and to UNMATCHED with no metadata. Say so, and cover the
COMPLETE fall-through with a test so the exclusion reads as deliberate.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 18:26:31 -05:00
Sam Dornan
6932abc5a9 fix(hltb): keep a pinned HowLongToBeat match through a rescan
fetch_hltb_rom called the fuzzy filename search unconditionally, so an
UPDATE scan re-guessed the match even when rom.hltb_id was already set. Any
other game scoring above the similarity floor replaced an ID the user had
pinned by hand in Edit ROM.

get_rom_by_id has existed since #2926 was fixed, but only the Edit ROM path
called it. Extract resolve_hltb_rom as a module-level function, following
resolve_launchbox_rom, so the ID-first branch is covered by tests rather
than trapped in a closure over scan_rom's frame.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 18:06:07 -05:00
Sam Dornan
5289899aae fix(scan): record hand-supplied artwork explicitly
The upload marker was inferred: an artwork upload stores the file and
clears url_cover, so a stored cover path with no url meant "user
supplied this". That signal cannot survive. get_cover returns no path
when the file is missing and the scan writes that straight back to
path_cover_s, so a single scan run while the resources volume is
unavailable erases it. The next scan reads the row as having no cover at
all, adopts the provider url, and replaces the user's cover with
provider art once storage returns. A resources volume left out of a
container recreate is enough to lose every uploaded cover in a library.

path_cover_s cannot carry this. It tracks the filesystem and is
reconciled on every scan; provenance has to outlive the file.

locked_fields records it durably instead. Uploading artwork or a manual
locks the field, and removing it, redownloading it, or naming a source
url releases it again. A complete rescan clears the locks along with the
resource files it deletes, so a lock can't point at a file that is gone
and block its replacement.

The migration backfills the old inferred marker, which is the last point
at which it can still be read. Without it the first scan after upgrading
would replace every uploaded cover. Manuals are deliberately not
backfilled: an uploaded manual and a scraped one share a path and
neither clears url_manual, so any guess would be wrong for half the
rows. Manuals stay pinned by the scan and are marked from here on.

Backfill verified on MariaDB and PostgreSQL against rows in the old
shape, covering uploaded, scraped, coverless, and null-url cases.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 10:11:19 -05:00
Sam Dornan
7a3b67e094 fix(scan): let update scans replace provider-written artwork urls
An update scan pinned url_cover to the stored value whenever a cover file
existed, and pinned url_screenshots whenever any were stored. Because
scan.py gates the download on `_added_rom.url_cover != rom.url_cover`,
forcing those equal made the gate structurally unreachable, so a freshly
resolved url could never reach the download step.

Uploading artwork clears url_cover while keeping path_cover_s, so that
pairing distinguishes a hand-supplied cover from a scraped one. Test for
it directly instead of for file existence, which is true of scraped
covers too. Screenshots have no upload path, so the fresh set always
wins.

name, summary and url_manual stay pinned: none of them can yet tell a
hand-edited value from a provider-written one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 10:11:15 -05:00
Axel Quack
45bcb2bed3 feat(metadata): add Demozoo, Pouët, and CSDb handlers
Identify demoscene productions as ROMs via filename tags, Edit-ROM
id/URL paste, Demozoo ?title= + rank, unique Pouët search.php 302,
and CSDb XML by id (no HTML scrape). Scene ids lock name/summary/cover
so game catalogs cannot attach a similarly titled box.

CSDb XML is parsed with defusedxml and capped; screenshot and extra
links are stored only when they are http(s).

Fixes rommapp/romm#1796 (Phase 0–2).
2026-08-17 08:59:54 +01:00
Sam Dornan
f22aadf77a fix(scan): re-read filename tags on a complete rescan
A rom parsed its filename tags when it was first inserted and never again,
so a change to parse_tags only reached rows scanned after it. The freshly
parsed values were built for every rom but only consumed on the insert
path, and scan_rom reseeded the tag columns from the existing row, so no
scan type could refresh them.

A complete rescan (or an explicit per-rom selection) now writes them back.
A hashes rescan still doesn't, since it is scoped to re-reading file bytes.

scan_rom also carries "version" forward now. It was the one tag column
missing from its attrs, so a re-parsed version would have been dropped, as
the value written by the reassociation path already was.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-16 21:38:12 -05:00
nendo
95f30b409c Merge upstream master into feature/sigil-title-ids
Resolve conflicts:
- rom_files/roms indexes: union the title-id index with upstream's new
  hash-search indexes.
- scan.py: keep upstream's ScreenScraper scan refactor, retaining the
  LIBRARY_BASE_PATH and UniversalPlatformSlug imports the body still uses.
- cleanup_orphaned_resources tests: take upstream's version.
- Renumber the sigil migrations onto upstream's 0107 head as 0108/0109/0110
  so the alembic chain stays single-headed.
2026-08-17 03:57:25 +09:00
Sam Dornan
ff2026c66d fix(launchbox): retry by filename when a Playmatch ID resolves to nothing
A scan preferred the LaunchBox ID Playmatch reports and, when the metadata
store could not resolve it, stopped there. Playmatch answers with an ID for
nearly every ROM on some platforms (38/40 sampled N64 dumps, 39/40 SNES,
against 4/40 GBA), so those platforms never reached the filename lookup and
were left with no LaunchBox metadata at all, while a manual match still
found the game.

The branch moves out of the scan closure into `resolve_launchbox_rom` so it
can be tested without a database. An ID already stored on the ROM is still
never traded for a filename guess: it usually came from a manual match.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:50:24 -05:00
Georges-Antoine Assi
117f420dca Merge pull request #4013 from rommapp/fix/hashes-scan-rematches-hasheous
fix(backend): re-run the Hasheous hash lookup on a hashes scan
2026-07-30 19:23:56 -04:00
Georges-Antoine Assi
50d4372b2b refactor(backend): drop redundant comment on the hashes scan gate
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 19:18:40 -04:00
Georges-Antoine Assi
11f570fede fix(backend): clear a stale Hasheous match when a rehash no longer matches
A rehashed ROM whose new hashes no longer match Hasheous kept its old
`hasheous_id` and `hasheous_metadata`: the merge loop only writes truthy
values, so an empty match cannot overwrite the values seeded from the
existing ROM, and the verification flags stayed on a ROM that no longer
earned them.

Clearing on any empty match would be wrong, though: `lookup_rom` returns the
same empty fallback whether Hasheous answered "unknown hashes" or was simply
unreachable (#2236), so an outage would silently de-verify a whole library.
Have `lookup_rom` return whether it reached a definitive answer, mirroring
`meta_ss_handler.lookup_rom`, and only clear the match on a conclusive miss.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 19:13:57 -04:00
Georges-Antoine Assi
6fd2d9576c fix(backend): re-run the Hasheous hash lookup on a hashes scan
A ROM's "verified" state comes entirely from the Hasheous signature match
flags in `hasheous_metadata`, but `ScanType.HASHES` was missing from both
Hasheous gates in `scan_rom`. A rehash recomputed the file hashes and then
never re-asked Hasheous about them, so the verification chips stayed dark
(#4001). RetroAchievements was already gated in, which is why its provider
icon appeared while nothing lit up.

A follow-up update scan didn't help either: that branch is gated on
`rom.hasheous_id`, which is never set for a ROM that has yet to match.

Add `HASHES` to `fetch_hasheous_hash_match` and `fetch_hasheous_rom`, and
to the "don't overwrite existing base fields" branch: Hasheous now returns
a name/cover/summary on a rehash, and `_identify_rom` short-circuits before
the cover download, so a changed `url_cover` would point at an image that
is never fetched.

Fixes #4001

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 14:53:46 -04:00
Spinnich
c2786429fd fix(screenscraper): address review feedback on quota awareness
Four points from the PR review:

- Leave the process-global ScreenScraper state alone when a scan does not use
  ScreenScraper. DEV_MODE runs scans in-process, so overlapping scans could
  otherwise clear each other's learned limits and skipped ROMs.
- Return pacing to the defaults when the per-scan state resets. Priming re-reads
  the account moments later; should that fail, the conservative default is safe
  for whatever account the credentials now name, whereas the previous scan's
  allowance may be more than this one is entitled to.
- Stop a rate-limited ROM from trying the next lookup. A refusal that survives
  the retry now propagates out of the handler and is caught once per ROM in
  fetch_ss_rom, instead of being swallowed per call site and sending the caller
  on to spend another retried request against a budget that is already gone.
  _is_daily_quota_error excludes the rate-limit 429 so the two stay distinct.
- Hand the request slot back before inspecting and re-encoding a cover, so
  local image work no longer holds a ScreenScraper thread.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 13:55:19 +00:00
nendo
6042a1c56b Merge upstream master into feature/sigil-title-ids
Re-integrate the sigil title-id feature on top of upstream's scan
reconciliation refactor and migration additions.

Scan reconciliation:
- _identify_rom now persists rom files via db_rom_handler.sync_rom_files
  instead of purge_rom_files + per-file add_rom_file. The obsolete
  RomFile copy-list (title_id/save_id/title_version) is removed; those
  fields now ride along through ROM_FILE_SCANNED_COLUMNS.
- Add title_id, save_id, title_version to ROM_FILE_SCANNED_COLUMNS so
  sync_rom_files copies them onto reconciled rows. Without this the
  extracted ids/version silently drop to NULL on rescan.
- Single-file embedding rename (renamed_rom_fs_name) preserved in both
  the new-entry and update paths of _identify_rom.

Migrations renumbered to chain after the new upstream head:
- 0102_sigil_title_ids -> 0104_sigil_title_ids (down: 0103_roms_facets_provider_ids)
- 0103_sigil_title_version -> 0105_sigil_title_version (down: 0104_sigil_title_ids)

Tests:
- Reworked TestIdentifyRomPersistsFileTitleVersion to capture
  sync_rom_files and assert the scanned RomFile carries title_id and
  title_version; added a direct assertion that ROM_FILE_SCANNED_COLUMNS
  includes the sigil columns.
2026-07-24 07:20:10 +09:00
nendo
ccf43ed87e Add binary title ID extraction via sigil during scans
New SigilService adapter wraps the optional sigil cffi binding (guarded
import, degrades to a no-op when absent) and extracts platform-native
title/save IDs from ROM binaries during the scan's file pass, gated to
nine platforms and independent of the hashable-platform gate. Switch
resolves prod.keys from the platform's scanned firmware. Per-file
title_id/save_id land on rom_files, rom-level title_id/save_id and a
SaveUsage enum land on roms (base Switch ID derived arithmetically when
only update/DLC files exist). Config flag
filesystem.skip_title_id_extraction mirrors skip_hash_calculation.
2026-07-24 02:54:20 +09:00
Georges-Antoine Assi
559cc7f7ea fix(scan): keep a soundtrack cover path when its unlink fails
remove_persisted_cover swallowed OSError, so clearing cover_path
regardless dropped the only reference to a file still on disk. It now
reports whether the file is gone, and the path is kept for the next scan
to retry when it isn't.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 10:41:30 -04:00
Georges-Antoine Assi
21cc044bf1 fix(scan): clear a soundtrack cover that's gone from the audio file
Reusing the file row across rescans meant a track that kept its tags but
lost its embedded cover held on to the old cover_path, so the music API
kept serving an obsolete image and its file was never removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 09:24:19 -04:00
Georges-Antoine Assi
096346a981 feat(scan): per-field artwork priority overrides
Add optional scan.priority.cover / screenshot / manual keys that each
override scan.priority.artwork for a single artwork field, falling back
to the shared artwork priority when omitted. This lets users, for
example, keep original box art for covers while sourcing screenshots
from a different provider.

Backward compatible: absent keys leave behavior unchanged. Config-only
(no UI), read-only exposure via GET /api/config.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 18:56:47 -04:00
VoidHandler
efa5945f03 fix(backend): validate embedded cover format and surface extraction failures
Restrict extracted audio cover bytes to JPEG/PNG via magic-byte sniffing
instead of trusting the declared MP4 imageformat, so a GIF (or missing
format) is no longer mislabeled and persisted as image/jpeg.
2026-07-08 00:33:43 -04:00
Georges-Antoine Assi
a2f3573c65 Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-07-05 17:11:51 -04:00
Georges-Antoine Assi
4d9bef4d6e refactor(scan): handle SS daily-quota 429 in the handler
Move the quota-skip decision out of scan_handler and into the SS handler:
lookup_rom, get_rom, and get_rom_by_id now catch the daily-quota 429 and
return an empty SSRom, so the scan degrades to the other providers with no
quota-specific code at the call site. Non-429 errors still propagate.

scan_handler keeps only the fault-tolerant provider gather. The service
breaker still short-circuits repeat calls and manual search still surfaces
the 429 (it does not go through these swallow paths for name search).

Generated-By: PostHog Code
Task-Id: 77dff3d9-6120-4156-bb25-1556a50a75e4
2026-07-05 17:09:03 -04:00
Georges-Antoine Assi
1ac31e9ff0 refactor(scan): move quota breaker into ScreenScraper service
Track the ScreenScraper daily quota where the knowledge lives: a breaker
in the service, tripped on the first HTTP 430/431 and reset at the start
of each scan. When tripped, _request() short-circuits the API call but
still raises the 429, so manual search keeps its clear "quota exhausted"
message while the scan catches it and falls back to the other providers.

Replaces the handler-level skip flag with this service-scoped breaker.

Generated-By: PostHog Code
Task-Id: 77dff3d9-6120-4156-bb25-1556a50a75e4
2026-07-05 16:40:04 -04:00
Georges-Antoine Assi
1338999ae9 refactor(scan): track provider skip state on the handler, reset per scan
Move the "skip this provider for the rest of the scan" state off a set
threaded through scan_rom and onto the MetadataHandler base class, so each
provider tracks it internally. The state is cleared for every provider at
the start of each scan via reset_metadata_handlers_scan_state().

Generated-By: PostHog Code
Task-Id: 77dff3d9-6120-4156-bb25-1556a50a75e4
2026-07-05 16:22:04 -04:00
Georges-Antoine Assi
fc938179e6 refactor(scan): drop user-facing warning for skipped provider
Background scans usually run with RomM closed, so the scan:warning toast
would rarely be seen. Keep the backend skip/fallback behavior and the log
line, and remove the socket event, its frontend handler, and the i18n key.

Generated-By: PostHog Code
Task-Id: 77dff3d9-6120-4156-bb25-1556a50a75e4
2026-07-05 14:56:22 -04:00
Georges-Antoine Assi
ba208efff7 fix(scan): fall back to other providers when ScreenScraper quota is exhausted
When a user hit ScreenScraper's daily API quota mid-scan, the whole scan
stopped matching ROMs against every provider instead of just skipping SS.
The 429 raised for SS quota (HTTP 430/431) propagated out of the per-ROM
provider gather (which lacked return_exceptions), discarding the other
providers' results, and every subsequent ROM re-hit the exhausted API.

- Skip ScreenScraper for the rest of the scan on the first quota hit,
  tracked in a shared per-scan set, so remaining ROMs stop hammering it.
- Keep the current ROM's other-provider data when SS quota is hit.
- Make the provider gather fault-tolerant (return_exceptions) so one
  provider raising never discards the others' results.
- Notify the user once via a non-fatal scan:warning socket toast.

The manual-search path still surfaces the 429 quota message unchanged.

Fixes #3620

Generated-By: PostHog Code
Task-Id: 77dff3d9-6120-4156-bb25-1556a50a75e4
2026-07-05 14:16:21 -04:00
Georges-Antoine Assi
7c578dbfd5 docs(scan): trim placeholder-name comments
Generated-By: PostHog Code
Task-Id: 987bb9c1-1bfb-43f2-adc7-c26e69f06a39
2026-07-05 08:02:52 -04:00
Georges-Antoine Assi
6bf9a947cd fix(scan): discard placeholder from seeded name before parsed fallback
rom_attrs["name"] is seeded from rom.name earlier, so on the no-provider-match
path it still holds the raw filename placeholder. That made the
`or rom_attrs.get("name")` branch win over the fs_name_no_tags fallback,
retaining the raw filename as the title. Treat the seeded name as a placeholder
too, so the parsed filename fallback applies when no provider matched.

Generated-By: PostHog Code
Task-Id: 987bb9c1-1bfb-43f2-adc7-c26e69f06a39
2026-07-05 07:57:32 -04:00