57 Commits

Author SHA1 Message Date
Matt Kaatman
d8d9fa7884 fix(igdb): let region_mode decide the localized title (#5785)
* fix(igdb): let region_mode decide the localized title

get_igdb_preferred_locale ignored scan.priority.region_mode, so a rom
tagged (Japan) always got IGDB's ja-JP localized title, even with
prefer_config and us first in scan.priority.region. Under prefer_config
the configured regions now come first and the rom's own tags are the
fallback, matching the ScreenScraper handler since #4413. The default
prefer_rom_tags ordering is unchanged.

Fixes #5784

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(igdb): fold the region_mode note into one docstring sentence

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Log a missing IGDB locale at debug: under prefer_config every ROM asks
for the first config locale, so a missing one is routine, not a warning.
Pin SCAN_REGION_MODE in the multi-region locale test instead of relying
on MagicMock's auto attribute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Drop the IGDB-locale filter on the ROM's region codes; the final
lookup loop already skips codes IGDB has no locale for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: prose

Spell out the USA region in the prefer_config test docstring so it
does not read as the pronoun, untangle the fallback test docstring, and
finish the clipped Returns line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(metadata): share one region order across IGDB, ScreenScraper and LaunchBox

IGDB now tries every preferred locale in order, up to the first region
that uses the default title, instead of only the first. Under
prefer_config with [eu, jp], a (Japan) ROM whose game has no EU
localization gets the Japanese title again rather than the default.

preferred_region_codes in the filesystem base handler builds the region
order once. ScreenScraper, IGDB and LaunchBox all read it, so LaunchBox
artwork follows region_mode too, and uppercase config codes match the
ROM's tags for every provider.

European country codes map to IGDB's EU locale and ScreenScraper's ss
to the default title, so a (France) ROM no longer falls through to the
next configured region.

An unquoted no (Norway, Norwegian) in scan.priority.region or
scan.priority.language loads as false from YAML and crashed every IGDB
match. The config loader now turns it back into "no" and drops other
non-string entries with a warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(igdb): drop _string_codes and spell out the EU region codes

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>
2026-11-26 20:11:48 -05:00
Marcello Pichini
13e1a612d8 fix(launchbox): read the YouTube id from watch URLs wherever v sits and without a fragment (#5764)
* fix(launchbox): read the YouTube id from watch URLs wherever v sits and without a fragment

A video URL with v after another parameter yielded no id, and a #t= fragment was kept as part of it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* fix(launchbox): ignore a trailer URL that cannot be parsed

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: simplify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(metadata): share one YouTube id parser across LaunchBox, Demozoo and Pouet

LaunchBox now also reads ids from embed, shorts, live, /v/ and
youtube-nocookie links, and Demozoo and Pouet now accept URLs without
a scheme. Ids are checked against the 11-character format at parse time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-26 08:41:27 -05:00
danielcopper
b3673fb1a7 fix(platforms): point Apple II at LaunchBox platform 111 (#5507) 2026-11-09 07:42:49 -05:00
Georges-Antoine Assi
d15cd9e7a1 fix: keep summary line breaks and strip provider HTML (#5413)
* fix(ui): keep line breaks in the game summary

Normalize CRLF and bare CR to LF and render the summary with
white-space: pre-line so multi-line summaries keep their structure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(metadata): turn HTML in provider summaries into plain text

Add utils.html_text.html_to_text, a parser-based helper that drops known
HTML tags, maps paragraphs, line breaks and list items to newlines, and
unescapes entities. Unknown tags such as "<Start>" stay as literal text.
Moby, ScreenScraper, Steam, Flashpoint and LaunchBox summaries go through it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(metadata): separate table cells and keep bullets on their text

Addresses Greptile review on #5413: adjacent td/th cells now get a space
between them, and a list item wrapping its text in a paragraph keeps the
bullet on the same line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 10:49:17 -04:00
Spinnich
60703be09c chore(platforms): split arcade aliases into per-emulator-family slugs (#5273)
* 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>
2026-10-28 19:53:06 -04:00
Sam Dornan
552ac3a393 fix(platforms): share provider entries across duplicate platform slugs (#5359)
* fix(platforms): share provider entries across duplicate slugs and rename system-32

Three consoles have two RomM slugs, each used by different providers, so a
library folder only matched the providers that knew its spelling:
vc-4000 / interton-vc-4000, apple-pippin / pippin and tandy-vis / vis.
DUPLICATE_PLATFORM_SLUGS lists them once, and fill_duplicate_slugs gives
each slug the other's entry in every provider table. pippin and
interton-vc-4000 now get an IGDB platform id, and IGDB's family override
also applies to a listed duplicate so both VC 4000 slugs stay in the
Interton family.

The system-32 slug mapped to Namco System 22 in ScreenScraper and
LaunchBox, easy to confuse with Sega System 32 (system32). It is now
namco-system-22. Folders and config bindings named system-32 still
resolve to it, and migration 0154 renames existing platform rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh

* fix(platforms): resolve bindings to a renamed slug back to their folder

resolve_platform_slug already maps a binding to system-32 onto
namco-system-22, but resolve_fs_slug compared the raw binding with the
new slug, so a moved folder bound to the old slug was never found.
Both now go through the same renamed-slug lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh

* fix(platforms): drop the system-32 slug backfill migration

Every scan resolves a platform's slug from its folder again, so the next
scan renames system-32 rows through the renamed-slug alias without a
migration, as the backend guide asks for normalizations the parser now
handles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh

* chore(platforms): reword two comments so the product isn't the actor

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh

* revert(platforms): leave system-32 to the arcade slug split

rommapp/romm#5273 retires system-32 as an alias of arcade and resolves
aliases in config bindings in both directions, which covers what the
namco-system-22 rename and the renamed-slug lookup did here. This PR now
only shares provider entries across duplicate slugs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XGA3D2oZ1hq3QUdnubMNXh

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 14:28:30 -05:00
Sam Dornan
6735a318e6 refactor(metadata): share heartbeats, filename id tags and the Moby rom builder (#5134) 2026-10-04 17:01:39 -04:00
Sam Dornan
b23bc79b46 feat(launchbox): scrape box front, back, spine and 3D box art (#5129) 2026-10-04 16:25:41 -04:00
Sam Dornan
02663721c7 fix(metadata): five provider fixes; test UPC, LaunchBox media, Demozoo, ScreenScraper and HLTB (#5126) 2026-10-04 15:28:09 -04:00
Sam Dornan
9e4b080403 fix(metadata): one UTC helper for release dates, a lint rule against local-time parsing, and Flashpoint tests (#5114) 2026-10-04 11:47:54 -04:00
Sam Dornan
7c2b049b70 chore(mypy): drop warn_return_any and validate provider responses with strict JSON (#4826) 2026-09-26 20:13:55 -04:00
Sam Dornan
5a6c895d33 chore(mypy): give every generic its type arguments (#4818)
* chore(mypy): switch to strict mode with listed exceptions

Replace the hand-picked flags with `strict = True`, turning off only the
four flags that aren't clean yet (disallow_any_generics,
warn_return_any, disallow_untyped_calls, disallow_untyped_decorators).
Any other strict flag, including those future mypy releases add to the
preset, is on by default.

That turns on no_implicit_reexport, strict_equality and extra_checks:
- Import each name from the module that defines it. About 240 test
  sites patched a dependency through the module that imported it
  (`scan_module.fs_rom_handler`); they now import the same object from
  its source, so every patch targets what it did before. Tests that
  replace a module attribute are unchanged.
- handler.streaming.memory_cards re-exports store_memory_card_version
  explicitly, since endpoints call it there and tests patch it there.
- mutagen gets implicit_reexport, as it re-exports without __all__.
- Test comparisons build typed values (CoverResult, a typed expected
  dict, enum .value) and the CORS lookup casts for its identity check.
- One ss_handler ** spread keeps a coded ignore: extra_checks wants its
  NotRequired dump_* keys spelled out, and the media dict never has them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G

* chore(mypy): give every generic its type arguments

Drop disallow_any_generics from the strict-mode exceptions and fix the
347 bare generics it reports, 230 of them in app code.

- Bare `dict` becomes `dict[str, Any]`: update payloads, raw provider
  JSON and endpoint bodies map string keys to mixed values, so the Any is
  real and now written down. The OpenAPI document is unchanged.
- Rom query filters take and return RomSelect; _music_facet_joins and
  _exclude_hidden are generic over the Select they're given, and
  _build_hash_selects returns id-only selects.
- Redis clients are typed by what they return: the decoding caches are
  Redis[str], the RQ connection and binary cache Redis[bytes].
- The rest get explicit parameters: Row, Pattern, ColumnElement,
  QueryableAttribute, SpooledTemporaryFile, Task, Future and friends.

Precise types reached callers that had been getting Any, which surfaced:
- The LaunchBox cache writer is fed binary-cache pipelines.
- The flashpoint and IGDB request helpers return raw JSON of varying
  shape, not always a dict.
- The rom search endpoint returned dicts under a list[SearchRomSchema]
  annotation; it now validates them into that schema.
- The audit filter's id subquery selects strings.
- In tests the binary cache is the non-decoding fake shared with
  async_cache, so it is cast to Redis[bytes] rather than changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G

* test(upload): assert cleanup against the patched upload directory

The 409 test checked config's ROM_UPLOAD_TMP_BASE while the fixture patches
the endpoint's copy to tmp_path/uploads, so it passed even if cleanup failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G

* chore(mypy): keep the row type through the ROM filter helpers

filter_roms and its helpers also receive select(Rom.id) membership queries,
so they now take and return the caller's Select type instead of narrowing to
RomSelect. merged_ra_metadata mixes scalar and list values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 16:32:29 -05:00
Sam Dornan
4ffc7c5ce1 style: apply the formatting requires-python already implies (#4638) 2026-09-19 12:33:45 -04:00
Sam Dornan
130ea73c23 perf(metadata): compress the cache-only metadata dump records (#4426)
* perf(metadata): compress the cache-only metadata dump records

The LaunchBox and Switch TitleDB stores are read by exact key and never
scanned, so each value can be compressed on its own. On a full import of
both real dumps into the bundled valkey, `used_memory` drops from 539.1MB
to 335.9MB and RSS from 553.3MB to 350.2MB, a 38% saving.

Values are zstd level 3, which costs 3-6us per record read, less than the
`json.loads` that follows it. A payload under 256 bytes is stored as plain
JSON: below that a frame header and a poor ratio on a short payload cost
more than they save, which is what leaves the id-valued title and product
id indexes untouched. `tools/measure_dump_cache.py --sweep` finds the real
records flat between 64 and 256 bytes.

Reads detect the zstd frame rather than trusting the key, so a store
written by an earlier import keeps answering until the next update
rewrites it. No re-import is required to upgrade.

A zstd frame is not UTF-8, so the dump keys move to a cache client that
leaves values as bytes. `async_cache` still serves everything else,
including the existence checks on these keys.

The new tool measures per-store size with `MEMORY USAGE ... SAMPLES 0`,
which walks every field. The default of five samples extrapolates, and on
a hash of this size it is wrong by enough that per-key figures stop
adding up to `used_memory`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* test(metadata): assert the writer stores through the dump codec

`test_values_are_json_encoded` pinned the exact string `json.dumps`
produced with default separators. The writer now hands the pipeline
compact bytes from `encode`, so the test asserts the contract that
matters instead: the value is bytes, and it decodes back to the record.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* fix(tools): stop the dump measurement wiping the whole cache server

`flushall` between passes would erase every database on whatever
`--redis-url` names, and RomM's sessions and RQ queues share that
database with the dump stores, so pointing the tool at a live instance
cost far more than the stores it meant to reset.

It now deletes only the ten keys it writes, and refuses a server holding
anything else unless forced, since a running RomM would have to
re-import what it drops. Each pass records what the server uses without
those stores and reports figures net of it, so a non-empty server still
measures what the dumps themselves cost.

Reported by Greptile on #4426.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* fix(tools): report field counts and bytes off the stores, not the writes

Two accounting errors in the measurement tool, both reported by Copilot
on #4426.

Field counts and byte totals were tallied while writing, so they counted
write attempts. `HSET` overwrites, and the dump repeats a title on one
platform and an alternate name across platforms, so 8,997 of the writes
landed on a field another record already held: the alternate name store
reported 70,297 fields against 62,384 actually stored. Both figures now
come from `HLEN` and a scan of each hash, which cannot drift from what
the store holds.

`used_memory_rss` was offset by a `used_memory` baseline, mixing two
metrics. Netting RSS turns out to be wrong however the baseline is
captured, because the pages a delete frees stay resident, which made the
encoded pass report -56.1MB. RSS is now reported absolute, and `--only`
loads a single encoding so it can be read off a server started fresh for
that pass: 555.8MB plain against 348.9MB encoded, measured that way.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* style(tools): cut the measurement tool's docstrings to the repo's limit

CLAUDE.md allows a docstring one sentence plus `Args:`/`Returns:`, and the
module docstring ran to four paragraphs. The non-obvious reasons move to
one-line comments at the code they explain, which is where a reader needs
them, and the operational detail was already carried by `--force` and
`--only`'s help text and by the refusal message itself.

Reported by Copilot on #4426.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* fix(tools): fold titles the way production does, and stop echoing the URL

Four more Copilot findings on #4426, three of them in the measurement tool
and one in the codec module.

The folded-title stand-in kept only ASCII alphanumerics, the exact thing
`fold_title`'s docstring warns against: it reduced `Astérix` to `astrix`
and `三國立志傳2` to `2`, and dropped titles that fold to nothing, so the
folded index measured smaller than it is. The tool now mirrors
`fold_title` character for character, verified against the real function
extracted from its module over 40,000 dump titles with no mismatch. The
store grows by 244 fields and 0.1MB, so the totals barely move.

The refusal path printed the target URL, which RomM builds with the
password inline, so it could have carried a credential into a CI log. It
now names the server generically and keeps the key count and the remedy.

`dump_cache`'s module docstring and its threshold comment both ran past
the one-to-two-line limit in CLAUDE.md. The benchmark numbers behind the
threshold live in the PR description, not the source.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* refactor(cache): give the dump store keys one home

The measurement tool carried its own copies of the ten store key strings,
against the single-source rule in CLAUDE.md. That matters more now the
tool deletes those keys: a production rename would have left it deleting
stale hashes, missing the new ones, and counting the real stores as
foreign data in its own safety guard.

The keys move to `handler/dump_cache.py`, which already holds the codec
that reads and writes them and depends on nothing but the cache client,
so the importers, the lookups and the tool all take them from there.
`DUMP_STORE_KEYS` is the list the tool measures and clears.

`base_handler` was reaching into `tasks/scheduled/update_switch_titledb`
for two constants, so a handler depended on a task module; that import is
gone. `launchbox_handler/types.py` keeps the initial-import flag, which
marks an import in progress rather than naming a store.

Measurement is unchanged: 538.0MB to 334.8MB, per-store figures identical.

Reported by Copilot on #4426.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* fix(tests): import the store keys from where the merge left them

Two test modules still took the keys from `handler.dump_cache`, which the
merge emptied of them, so collection failed with an ImportError on both
databases and mypy flagged nine missing attributes. They read them from
`launchbox_handler/types.py` and the TitleDB task now, as the code does.

Also reverts formatting the merge dragged into four files this change has
no business touching: running isort over everything the merge listed
reclassified `tests.*` and `startup` out of the block master keeps them
in, and black rewrote two `except (A, B)` clauses into the unparenthesized
form. Those files go back to master's copy.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* style(tests): restore both metadata test files to master's formatting

Running the formatters over everything the merge touched had reordered
imports trunk keeps in another block. Both files go back to master's copy,
with the compressed-store read test re-added by hand and its import placed
in the first-party block where the other `handler.*` imports sit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* fix(tools): report bad input rather than dividing by zero

A zip with none of the four XML files loads no records, and every ratio
the report prints then divides by a zero total.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* refactor(tools): match the yields to their siblings, type the serializer

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

* style: trim the comments and tighten the names review-polish flags

Cut the version notes to what version 2 is, drop the two comments that
repeated a neighbour, rename the tool's `measure` to `store_memory` beside
`store_stats`, and annotate the codec tests' parametrized arguments.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQNNQHk7uyS3eoB9yAxoM9

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 16:09:32 -05:00
Georges-Antoine Assi
decd5c61c4 refactor(cache): make the versioned store a type rather than three constants
The schema key, its version and the keys they cover were three constants per
store, retyped at each of the six places that used them and interchangeable
enough that one store's version could be checked against another's keys. They
are a `VersionedCacheStore` now, so a store is declared once and the startup
drop is a loop over a table.

The two reader gates were the same four lines, and a third read path was
still checking the data key without the stamp, so the LaunchBox entry points
disagreed about what populated meant. All three call one helper.

The drop probed each key before deleting it, spending a round trip per key to
learn what `unlink` reports anyway, and `delete` freed the store on the main
thread. Both imports also merge into their hashes, so each now drops a stale
store itself rather than trusting the drop to have happened at startup.

The alternate name index holds the bare id its reader wants, like the two
title indexes beside it, and follows through the same helper.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-10 16:10:09 -04:00
Georges-Antoine Assi
721197476a perf(metadata): rebuild a metadata store an older release wrote
The readers tolerated both the old and the new shape of every index this
branch changed, which left two shapes supported forever and, on an install
whose scheduled update is off, meant the old store answered every lookup
and the saving never landed at all.

Each store now carries a schema stamp. A store whose stamp is missing or
stale reads as unpopulated, is dropped at startup, and has its import
queued the way the WebP backfill is, so the shape change causes the
rebuild instead of being worked around. The readers know one shape again.

The projection each store is written with moves next to its key, and the
three stores that had none get one: Mame.xml kept 24 fields per record to
serve `Name`, Files.xml kept the platform and filename its cache key
already carries, and an alternate name entry kept the name it is stored
under. Together with the image list that is ~135MB.

Measured against the real dump: the eight LaunchBox hashes hold 385MB, and
a store stamped by an earlier release is dropped at startup for 386MB of
`used_memory` reclaimed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-10 15:45:32 -04:00
Georges-Antoine Assi
13aaf54921 docs(metadata): trim the cache index comments to the fact each carries
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-10 13:19:30 -04:00
Georges-Antoine Assi
ea44dfd9cf refactor(metadata): fold the index follows into one lookup each
The title index reader now takes the key and field it reads, so the two
call sites lose their intermediate hit variable, and the alternate name
path follows its id through `get_by_id` like the other two. The Switch
titleID read is shared between the two lookups that do it.

The LaunchBox import reads the `Game` fields with `findtext`, and the
Switch import queues both indexes from one pass over the batches. The
image projection moves next to the `LaunchboxImage` type it fills.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-10 13:17:44 -04:00
Georges-Antoine Assi
d4f3d8be83 perf(metadata): stop storing the metadata dumps twice over in the cache
The LaunchBox import wrote the whole game record into three hashes: once
under its database id, and again under its title and folded title. The
Switch TitleDB import wrote every entry twice, once per id it is looked up
by. Both title indexes and the product id index now hold the id of the
record they point at, and the reader follows it.

Image lists also carried a `DatabaseID` repeating the field they are stored
under, plus a `CRC32` no lookup reads.

Measured on a full import of both dumps into the bundled valkey:
941MB -> 466MB of `used_memory`.

An index written by an earlier import still holds whole records, so a
lookup keeps answering off it until the next update rewrites the store.

Fixes #4395

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-09 20:25:42 -04:00
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
42ebaaec49 feat: split company metadata into publishers and developers
Metadata providers (ScreenScraper, RetroAchievements, LaunchBox,
Flashpoint, gamelist, IGDB) distinguish the publisher from the developer
of a game, but RomM amalgamated both into a single `companies` list at
ingestion, so the distinction was unrecoverable. This adds `publishers`
and `developers` as new, refined fields end to end while keeping
`companies` (the merged union) working exactly as before.

Backend:
- Handlers now emit publishers/developers alongside the unchanged
  companies list; IGDB requests the involved_companies developer/
  publisher flags to split by role.
- Migration 0112 adds generated_publishers/generated_developers columns
  on roms, projects them through the roms_metadata view, mirrors them
  into roms_facets, and adds publisher/developer virtual-collection
  types (triggers/functions rebuilt for MariaDB/MySQL + PostgreSQL).
- Filters, facets, endpoints, smart collections and the gamelist/pegasus
  exporters all carry the new fields; exporters prefer the explicit
  split and fall back to the companies heuristic for un-rescanned ROMs.

Frontend (v2):
- Shared filter store + API service, gallery filter drawer, URL
  persistence, game detail display (Developers/Publishers with a
  Companies fallback), edit dialog, smart-collection criteria, and a
  publisher/developer "group virtual collections by" option.
- Also relabels the confusing "company"->"Developer" group-by option
  to "Company" now that a proper Developer option exists.

Fixes #3518

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-27 14:44:30 -04:00
Sam Dornan
1cd29d7285 Match LaunchBox dumps that separate words with underscores
The LaunchBox name lookup rewrites a search term before hitting the
metadata index: " - " becomes ": ", and a trailing article is moved back
to the front. Both rewrites are anchored on literal spaces, so a dump
named with underscores reaches neither, and the folded fallback cannot
recover it either because the article is left in the wrong position.

Legend_of_Zelda,_The_-_A_Link_to_the_Past.smc missed every index stage
while its space-separated equivalent matched. Swap underscores for
spaces before the rewrites so both forms resolve to the same term.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 07:45:05 -05:00
Sam Dornan
9e92e325f7 chore: drop review-flagged comments
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 08:11:09 -05:00
Sam Dornan
e1fe2caf0f fix(launchbox): keep marks the script spells with when folding
A mark was dropped whenever it was not alphanumeric, and the accent strip
before it removed every mark carrying a combining class. Between them they
took the vowel signs and viramas Indic and Thai scripts spell with, so
"हिन्दी गेम" folded to "हनदगम" and titles differing only in those marks
collided.

A mark now only goes when it sits on a Latin letter, which is the case it
was meant for. Collisions across the dump are unchanged at 551 of 186505
keys, none differing in their digits, and the PlayStation 2 gain still
measures 96.7%.

Also build each game's dict once rather than per index write.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 17:19:57 -05:00
Sam Dornan
4929151048 fix(launchbox): keep letters of every script when folding a title
Folding to ASCII alone reduced a title written in another script to
whatever digits it carried, so "三國立志傳2" and "忍者村大战2" shared one key
and four Windows titles collapsed onto "2". Keeping every alphanumeric
character instead separates them and gives the 208 titles that folded to
nothing a key of their own.

Measured over all 187067 named games in the dump, colliding folded keys
drop from 597 to 551 and the PlayStation 2 gain is unchanged at 96.7%.
Every surviving collision is a punctuation variant of one game, and none
differ in their digits, so no entry in a series folds onto another.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 17:05:31 -05:00
Sam Dornan
6ce0a2f528 fix(launchbox): match titles differing only by punctuation
LaunchBox titles carry colons, diacritics and characters a filesystem
forbids that a ROM filename cannot, so an exact-key lookup misses games
the dump holds: "Burnout Revenge" against "Burnout: Revenge", "Asterix"
against "Astérix", "AC-DC" against "AC/DC".

Index every title under a folded form as well, and consult it only once
every exact form has missed so an exact hit still wins.

Measured over the 2585 Redump-style PlayStation 2 titles the dump names,
this lifts matching from 89.8% to 96.7%. All five colliding folded keys
are LaunchBox's own duplicate records for a single game.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 16:51:42 -05:00
Georges-Antoine Assi
4b574ee284 refactor: share one article list across sort and launchbox matching
The sort key and the launchbox inverted-title matcher each carried their
own copy of the same 16 articles. Build both patterns from a single
ARTICLES tuple, and point the frontend's hand-synced copy at it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 08:42:14 -04:00
Sam Dornan
94f6b16ec1 fix(launchbox): match dump filenames against the metadata store
LaunchBox lookups are exact key reads, so a filename that doesn't already
read like a LaunchBox title misses. Three gaps closed:

- No-Intro inverts leading articles ("Legend of Zelda, The - Ocarina of
  Time"), LaunchBox keeps them in front, so the de-inverted form is now
  tried against the name and alternate-name indexes as well. Measured over
  the No-Intro sets: N64 unmatched 200 -> 171, SNES 461 -> 318, Genesis
  285 -> 191, GBA 683 -> 576.
- Files.xml, a filename-to-title index the dump already ships and the
  update task already caches, was never read by any lookup. It now runs
  ahead of the name search, which is the only route to titles whose files
  are named nothing like them (MS-DOS, Amiga, Arcade). Its cache key gains
  the platform, since the same dump filename exists on several systems.
- A local LaunchBox install was only reachable by an exact filename,
  extension included, or by a stem equal to the title. A library of `.zip`
  archives could never match an install pointing at `.z64`, and a No-Intro
  stem still carries region tags. Both sides now reduce to shared forms.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:50:24 -05:00
Georges-Antoine Assi
57f4fd21d0 cleanup 2026-07-28 23:01:07 -04:00
Georges-Antoine Assi
8c12ac86a1 fix(launchbox): keep the heartbeat honest during a first import
The store is written in batches, so an initial import answers for the
names committed so far long before it holds the whole dump. Checking
that the name index exists reported the provider healthy off a fraction
of the entries, and a run that died partway left it that way for good.

Flag the initial import and clear it once a run completes, so only a
finished import counts as healthy. A refresh keeps serving the previous
dump, so it is not flagged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 22:22:06 -04:00
Georges-Antoine Assi
52940ea3d4 fix(launchbox): stop the cloud provider from silently matching nothing
LaunchBox cloud lookups read from a Redis store that only the metadata
update task fills, but nothing surfaced when that store was empty. The
provider reported healthy, every search returned zero results, and the
logs said nothing.

- heartbeat now reports unhealthy until the store is populated, and an
  empty store logs what to set to fix it
- the update task can be run manually whenever LAUNCHBOX_API_ENABLED is
  on, instead of also requiring the scheduled-update flag
- the ~600k entry dump was buffered into a single pipeline, peaking at
  1.7GB of RSS and writing nothing at all if the job was killed part way
  through. Writes now go out in batches and parsed elements are dropped
  as they are consumed, which caps the run at ~260MB. The task also gets
  its own timeout, since the default 5 minutes does not cover a 100MB
  download plus a 500MB parse
- alternate name lookups ignored the platform, so "Super Mario World" on
  PlayStation matched Super Mario Bros.
- Coleco ADAM was spelled wrong, and Famicom / Super Famicom pointed at
  platform names LaunchBox does not use

Fixes #3981

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 19:55:16 -04:00
Georges-Antoine Assi
081ebfb6b6 Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-07-09 13:36:13 -04:00
Georges-Antoine Assi
f1df8a6ca9 Update backend/handler/metadata/launchbox_handler/media.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-07-09 13:35:59 -04:00
Georges-Antoine Assi
84332b5c63 fix(launchbox): match remote cover art region to ROM region
LaunchBox remote covers were selected by image type only, picking the
first image of the best type regardless of region. A ROM tagged "(USA)"
could get a Europe box even when a North America box existed.

Derive the ROM's preferred region shortcodes from its filename, map
LaunchBox region names ("North America" -> "us") to the same shortcodes,
and use region as a tiebreaker within the winning cover type.

Fixes #3706

Generated-By: PostHog Code
Task-Id: 1e53a6d4-2d71-413d-8b2a-aa94b01b7e63
2026-07-08 23:23:27 -04:00
Georges-Antoine Assi
3348d9bb29 cleanup 2026-07-06 22:17:56 -04:00
Georges-Antoine Assi
90945685e4 Stuff 2026-05-17 12:43:33 -04:00
Georges-Antoine Assi
8999b66574 Preserve local LaunchBox data on UPDATE scans and video extensions
UPDATE scans with a known launchbox_id were calling get_rom_by_id(),
which only returns remote data and bypassed get_rom()'s local-first
merge — so local-only fields like Notes were getting clobbered and
local media matching fidelity dropped. get_rom_by_id() now optionally
takes fs_name/platform_slug and merges the local entry when its
DatabaseID matches the requested id.

Also fixes populate_rom_specific_paths writing every video as
video.mp4 regardless of source extension; since store_media_file is a
byte copy, .mkv/.webm contents would be served as .mp4 and break MIME
sniffing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 14:32:34 -04:00
Georges-Antoine Assi
91d6928281 Lift LaunchBox video extensions to module constant
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 14:40:36 -04:00
Georges-Antoine Assi
fad2e5c77d Use correct LaunchBox MameFile schema
The sample_metadata.zip test fixture used invented tag names
(<Description>, FileName ending in .zip). Real LaunchBox Mame.xml
(see backend/tasks/fixtures/launchbox/mame.xml) uses <Name> as the
full title and keys MameFile entries by the stem (e.g. wrlok_l3),
no extension. Read Name instead of Description, and fall back to
the stem when the raw fs_name lookup misses.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 14:31:16 -04:00
Georges-Antoine Assi
f33844be40 Find local LaunchBox media for remote-only rom matches
remote_media_req built a MediaRequest with platform_name=None, which
made _build_local_media_context bail and never search on-disk
Images/Manuals/Videos. Any rom that matched only via Metadata.xml (no
local XML entry) ended up with images: [] even though LaunchBox art
was sitting on disk. Thread platform_name and fs_name into
remote_media_req, falling back to the remote entry's Platform field
when no slug is available (e.g. lookups by database id).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 12:32:54 -04:00
Georges-Antoine Assi
8fc426b35c Import local LaunchBox videos
LaunchBox stores videos under /romm/launchbox/Videos/<Platform>/<Game>.<ext>
but the handler only extracted YouTube IDs; LAUNCHBOX_VIDEOS_DIR was
defined and unused. Add _get_video() to surface local videos as
launchbox-file:// URLs, thread a populate_rom_specific_paths() through
the scan pipeline to set video_path once the rom is known, and mirror
the SS/gamelist branch in the scan socket so store_media_file actually
copies the video into the rom's resource directory. Rom.path_video now
also reads from launchbox_metadata.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 12:13:42 -04:00
Georges-Antoine Assi
a83f3bdca7 Wire up LaunchBox MAME arcade lookups
The scheduled task populated LAUNCHBOX_MAME_KEY from Mame.xml but no
handler code ever read it, so arcade ROMs like pacman.zip never matched
against Metadata.xml (which keys on full titles like "Pac-Man"). Add
RemoteSource.get_mame_entry() and an ARCADE branch in get_rom() that
resolves the MAME filename to its Description before name lookup.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 12:00:26 -04:00
Georges-Antoine Assi
40689d7e39 Fix LaunchBox local-media file:// paths resolving under library root
LaunchBox produced file:// URIs relative to /romm/launchbox, but the
resources handler resolved them under /romm/library via fs_rom_handler,
so local images/manuals/screenshots were never found. Switch LaunchBox
to a distinct launchbox-file:// scheme and add FSLaunchboxHandler +
_resolve_local_file_uri to route each scheme to the correct root.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 22:59:00 -04:00
Georges-Antoine Assi
f2e8e337b2 Merge branch 'master' into save-sync 2026-04-05 21:47:53 -04:00
Georges-Antoine Assi
6abf60b0fe last fixes 2026-04-03 11:49:32 -04:00
Georges-Antoine Assi
ceddf2f9e9 changes from bot review 2026-04-03 11:24:02 -04:00
Georges-Antoine Assi
55ca39cacb fix deprecations in pydantic 2026-03-15 09:34:48 -04:00
Georges-Antoine Assi
207f8a3c85 [ROMM-3067] Always sub dash with colon for launchbox matching 2026-03-08 17:26:53 -04:00
Georges-Antoine Assi
a977b39192 update famicom ID in launchbox 2026-03-08 16:22:15 -04:00
Georges-Antoine Assi
aa4abe6b7c end me 2026-03-07 23:43:58 -05:00