Commit Graph

71 Commits

Author SHA1 Message Date
Georges-Antoine Assi
eec574b49b fix(metadata): give UniversalPlatformSlug a leaf home
Both CI failures came from one import cycle. RQ could no longer resolve
`endpoints.sockets.scan.scan_platforms`, and the e2e seed script failed the
same way, because `sigil` imports the platform slug enum, importing anything
under `handler.metadata` runs its `__init__`, that reaches `gamelist_handler`
which imports `handler.filesystem`, and `roms_handler` there imports `sigil`
back while it is still half-initialised.

The cycle predates this branch. It stayed hidden because `scan.py` reached
the enum through `utils.switch`, imported late enough that
`handler.filesystem` was already loaded; naming the adapter directly moved
that import to the top of the module and the ordering luck ran out.

So the enum moves to `utils/platform_slugs.py`, which imports nothing but
`enum`. Naming a platform no longer drags in httpx, redis and the titledb
task, and the 29 call sites point at the module that owns it rather than
picking it up from a 1000-line metadata handler that happens to re-export
it. `import adapters.services.sigil` now also works on its own, which it
did not before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 14:28:49 -04:00
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
e1de724421 chore: trim comments in moby_handler
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 11:33:34 -04:00
Justin
8f809a10a6 fix: remove double URL-encoding of MobyGames search terms
The MobyGames handler pre-encoded search terms with urllib's quote()
before passing them to MobyGamesService.list_games(), which encodes the
query itself via yarl's with_query(). Titles containing special
characters were therefore double-encoded and never matched:

    'Sonic & Knuckles'  -> title=Sonic+%2526+Knuckles
    '... World + Bowser's Fury' -> title=...+%252B+Bowser%2527s+Fury

Pass the raw (unidecoded) term and let the service layer encode it
exactly once, matching how the ScreenScraper handler already works.
Adds regression tests for both the scan path (_search_rom) and the
manual-search path (get_matched_roms_by_name).

Same bug class as reported for ScreenScraper in #3467.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 19:05:48 +02:00
TowyTowy
ae6e6adbe2 fix(metadata): search the whole filename for Sony serial codes
Pattern.search() takes pos as its second argument, not flags, so passing
re.IGNORECASE (value 2) started the serial scan at index 2. Filenames
that begin with the serial itself (e.g. SCUS-94163.bin) never matched,
and the PS1/PS2/PSP serial index resolution was silently skipped in the
IGDB, MobyGames, and ScreenScraper handlers.

The regex already matches both cases via [a-zA-Z], and the serial is
uppercased before the Redis lookup (#3621), so the intended flag added
nothing. Drop the stray argument so serials are found anywhere in the
filename, including at the start.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-18 12:11:29 +02:00
Georges-Antoine Assi
1610bf29de [HOTFIX] Set metadata fields as nullable 2026-01-03 17:42:18 -05:00
Georges-Antoine Assi
df68dc9bd9 Merge both odyssey 2 platform 2025-10-03 16:28:02 -04:00
Georges-Antoine Assi
8c33a95637 remove hartbeat from bh endpoint 2025-09-20 17:57:38 -04:00
Georges-Antoine Assi
3c4113f8a8 Merge branch 'master' into flashpoint-metadata-handler 2025-09-11 21:27:48 -04:00
Georges-Antoine Assi
34b4ef99bb fix comments 2025-09-07 23:05:01 -04:00
Georges-Antoine Assi
d7e85ba633 [ROMM-1333] Use metadata tag in filename to match game 2025-09-07 14:12:30 -04:00
Michael Manganiello
e4e3928d1b misc: Apply import sorting 2025-09-04 11:17:00 -03:00
Michael Manganiello
d216bad78b misc: Add MetadataHandler's is_enabled method
Convert `MetadataHandler` to an abstract base class and add an
`is_enabled` class method that allows every metadata handler to
independently report whether it is enabled based on its configuration.

This avoids the need for global variables in the config module, allowing
us to change the enabled state of a metadata handler at runtime if
needed.
2025-09-03 22:13:28 -03:00
Georges-Antoine Assi
ef2546ec08 fix base handler filename 2025-08-27 12:40:16 -04:00
Georges-Antoine Assi
5f4943c97b find_best_match handles split name search 2025-08-17 22:39:00 -04:00
Georges-Antoine Assi
d41a920c37 normalize split tiles for ssfr 2025-08-17 20:29:44 -04:00
Georges-Antoine Assi
f0574577c9 Prefer lower IDs when matching games with same title 2025-08-17 19:53:29 -04:00
Georges-Antoine Assi
d005dba90b fix a bunch of shit 2025-08-09 11:16:12 -04:00
Georges-Antoine Assi
659a3eb104 use jaro-winkler algo 2025-08-08 16:54:26 -04:00
Georges-Antoine Assi
1a2944806b Use best-match algo for more providers 2025-08-07 16:57:29 -04:00
Georges-Antoine Assi
90f10e8946 Fixed platform slugs that were missed 2025-08-06 17:28:10 -04:00
Georges-Antoine Assi
1955da78f2 finish all the handlers 2025-07-24 17:05:39 -04:00
Georges-Antoine Assi
59a2e5d5aa move away from explicit LIST use 2025-07-24 16:41:17 -04:00
Georges-Antoine Assi
8a76528815 finish translating keys 2025-07-24 16:09:49 -04:00
Georges-Antoine Assi
b431aa4d7e manual fixes 2025-07-24 15:43:03 -04:00
Georges-Antoine Assi
39e6fd3579 use ups keys for all lists 2025-07-24 15:30:03 -04:00
Georges-Antoine Assi
1cc01922d9 comlpete migration and transition 2025-07-24 10:25:41 -04:00
Georges-Antoine Assi
595c52bcab Unify singular slugs 2025-07-23 21:52:52 -04:00
Georges-Antoine Assi
5d6ae2c842 stop overwriting IDs on scan 2025-07-14 10:31:19 -04:00
Georges-Antoine Assi
c9b09e9ee1 better search term nomralization 2025-07-12 23:52:51 -04:00
Georges-Antoine Assi
c76caed145 normalized search results 2025-07-12 09:56:18 -04:00
Georges-Antoine Assi
24d19eb109 fix moby cover image 2025-07-11 21:54:43 -04:00
Georges-Antoine Assi
75b6ca9277 fix generating supported platforms 2025-07-09 15:57:48 -04:00
Georges-Antoine Assi
ca5f8eacb1 add more moby slugs 2025-07-09 15:08:45 -04:00
Georges-Antoine Assi
06d60fa0e3 start adding slugs to mobygames platforms 2025-07-09 11:18:08 -04:00
Michael Manganiello
4209ee4481 misc: Create MobyGames service adapter
Add a new service adapter for the MobyGames API, to separate concerns
with RomM's handler for metadata.

This adapter is agnostic to the handler and only provides methods to
interact with the API, and correctly return typed responses.
2025-06-27 01:15:49 -03:00
Georges-Antoine Assi
0609747c6c finish migration platforms 2025-06-16 14:13:23 -04:00
Georges-Antoine Assi
e7cfd02d24 Merge branch 'master' into romm-403 2025-06-12 09:57:57 -04:00
Georges-Antoine Assi
5e6229a59d Fix RA platform IDs for matching 2025-06-11 08:51:47 -04:00
Georges-Antoine Assi
fd705e41ce add and store fake launchbox IDs 2025-05-23 14:13:19 -04:00
Georges-Antoine Assi
016e6fb227 [ROMM-1770] Stop squashing old metadata props when manually matching 2025-04-23 22:04:54 -04:00
Georges-Antoine Assi
0592985e5c wrap all in json error checks 2025-02-24 20:48:58 -05:00
Georges-Antoine Assi
6932f864c6 reraise error 2025-02-24 19:52:35 -05:00
zurdi
9d96501b9e Merge remote-tracking branch 'origin/master' into feature/screenscraper-integration 2025-01-31 00:12:44 +00:00
Georges-Antoine Assi
696a1c6122 Merge branch 'master' into rom-hashing-background-task 2025-01-15 21:51:23 -05:00
zurdi
e7342ab457 Merge remote-tracking branch 'origin/master' into feature/screenscraper-integration 2025-01-06 12:53:38 +00:00
Michael Manganiello
1c7cbc2328 misc: Change signature for get_matched_rom_by_id function
The previous function name `get_matched_roms_by_id` was misleading as it
returned a list of matched ROMs, but searching by ID should always
return either one result or none.
2025-01-05 15:18:19 -03:00
zurdi
4aa2d49221 feat: fully integrated screenscrapper 2025-01-03 03:08:02 +00:00
Georges-Antoine Assi
55eee458a1 actaully complete backend 2024-12-21 00:37:37 -05:00