Name the reset timezone by its shortcode, and drop comments that either
restate the code or explain a change rather than the behaviour.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The account limits, the two one-shot advisory flags and the daily-quota
breaker all reset together at the start of a scan, so they now live
together in a _ScanState instance. Mutating its attributes needs no
global statement, and reset() walks the dataclass fields so a new one
cannot be left out.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ScreenScraper's FAQ gives the per-minute budget as `threads x 50`, while
`maxrequestspermin` came back as `1024 x (threads + 1)` on every account
measured. Reading the field as the unreliable one, pacing took the lower of
the two, pinning a 9-thread account to 450 requests per minute against a real
allowance of 10240.
ScreenScraper confirms the API was changed without the documentation
following it, and that the reported field is the authoritative one, so pace
at it and drop the formula.
That leaves no basis for a default rate either. Until the account reports,
the one-thread default is the guard: a single in-flight request cannot outrun
any budget ScreenScraper hands out, and priming reads the account before the
first ROM, so at most one request is ever unpaced.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
SteamGridDB does not remove assets taken down under DMCA; it returns them
with "lock": true and strips the URL signature, so the CDN serves a
placeholder image reading "This asset has been removed in response to a
DMCA takedown notice" for both the full asset and its thumbnail.
Filter locked grids in _get_game_covers, the single funnel for scan
matching, ID lookups and the manual cover picker.
Closes#4003
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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>
ScreenScraper's FAQ defines the per-minute budget, and the reported
maxrequestspermin field, as threads x 50. The field does not follow it. Two
accounts report 1024 x (threads + 1) instead:
threads 9 -> 10240 (threads x 50 = 450)
threads 6 -> 7168 (threads x 50 = 300)
At those rates the limiter never engages, so pacing did nothing for either
account. Every neighbouring field does match its documented rule (both thread
counts and both maxdownloadspeed values reconcile exactly with the FAQ's
participation ladder plus the donation bonus), so the outlier is treated as
unreliable and the lower of the two budgets wins.
Also: state the maxdownloadspeed unit as fact now the FAQ confirms Kb/s per
thread, and say when the daily quotas actually reset (midnight French time)
rather than "tomorrow".
The limits ride along on every response, so learning them from the first
scrape response meant the opening requests of a scan ran at the default one
thread and 50 requests per minute, and the quota only became visible once a
platform finished.
ssuserInfos.php reports the same ssuser block up front. Unlike the scraping
endpoints it does not consume the daily quota (measured: two reads 90s apart
moved requeststoday by 0), so a scan can ask once at startup and pace itself
correctly from the first request, logging the quota and the SCAN_WORKERS
advisory before the first ROM is touched.
Best effort: a refused or unreachable lookup logs a warning and the scan
carries on.
ScreenScraper returns the account's allowances on every response, but only
maxthreads was read. Use the rest:
- Pace requests against the reported maxrequestspermin (falling back to the
documented threads x 50), so fast lookups can no longer overrun the
per-minute budget without ever exceeding the thread cap.
- Report the remaining daily and unrecognized-ROM quotas after each platform
and at the end of a scan, and warn once when either drops below 10%.
- Hint once per scan when SCAN_WORKERS is below the thread allowance (scans
slower than the account allows) or above it (extra workers just queue).
- Raise a distinct error when a request is refused twice for exceeding the
rate, so the ROM is reported as skipped in the scan summary instead of being
saved with no ScreenScraper data.
- Route ScreenScraper media downloads (covers, screenshots, manuals, mixed
media) through the same limiters, since they are api2 endpoints that count
against the same allowances, and derive their timeout from the account's
advertised download speed.
Fixes#3978
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Adds client-side filters to the v2 manual cover-search dialog so users
can narrow SteamGridDB results without endless scrolling:
- Source (SteamGridDB / each metadata provider)
- Resolution (dynamically built from the results present)
- Style (alternate / blurred / material / no logo / white logo)
- Uploader (searchable list of contributors)
- Content toggles (NSFW / humor / epilepsy, NSFW off by default)
- Sort by relevance or most votes
Backend surfaces the rich per-cover metadata SGDB already returned but
was discarding: SGDBResource / SearchCoverSchema now carry width,
height, style, author, score and content flags, and the cover-search
path fetches every content variant so the picker can toggle them
client-side. Auto-scan cover selection is unchanged and stays
safe-by-default.
New keys translated across all 18 locales.
Closes#3749
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
RAHasher only decompresses .zip archives itself; any other container
(.7z, .rar, .gz, .bz2, .xz, .tar, ...) was hashed as its raw archive
bytes, silently storing a well-formed hash that matches nothing on
RetroAchievements (issue #3808).
Non-zip archives on buffer-hash platforms are now extracted to a temp
file via the bundled 7zz binary and the extracted ROM is hashed instead.
The new extract_largest_archive_member helper follows the existing 7zz
subprocess patterns, handles single-stream formats whose listings carry
no Attributes line (.gz/.xz), and unwraps one level of nesting so
compressed tarballs (.tgz) reach the ROM inside the inner tar.
Arcade is exempt: its RA hash is computed from the file's basename, so
any container format already hashes correctly and extraction (which
renames the file) would break it. Disc platforms keep their existing
archive skip.
When extraction fails (corrupt archive, or a codec the 7zz build lacks,
e.g. RAR) no hash is stored at all and the 7zz stderr reason is logged
at error level, so scan logs explain the missing hash instead of
silently storing a garbage one.
Fixes#3808
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Folder-based multi-disc ROMs resolve their /* glob to the .m3u playlist,
but RAHasher can only follow a playlist to formats it can read. When the
first playlist entry is a container we hash natively (RVZ/WIA on
GameCube/Wii, compressed ISO on PSP), resolve the playlist to that disc
so the native-hash dispatch sees it.
Fixes#3797
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ScreenScraper occasionally returns malformed JSON with raw, unescaped
backslashes in text fields (e.g. synopses), which the strict parser
rejects with "Invalid \escape". The whole response was then discarded as
{}, so ScreenScraper found no match even for trivially-matchable titles
while other providers matched fine.
Parse leniently: on a decode error, double any backslash that isn't a
valid JSON escape and retry, instead of dropping the entire response.
Fixes#3764
Generated-By: PostHog Code
Task-Id: bbb1e2a8-bcb0-45a3-840e-86ce39f906a9
Remove the hardcoded (base64-obfuscated) ScreenScraper developer
credentials from the source tree and read them from the
SCREENSCRAPER_DEV_ID / SCREENSCRAPER_DEV_PASSWORD environment variables
instead.
The official images bake the values in at build time from CI secrets via
Docker build args; local builds and source runs read them from the
environment. env.template documents the vars (commented out) so an empty
value never overrides the image's built-in credentials.
Generated-By: PostHog Code
Task-Id: 05a9b58b-4c64-4f75-af3e-d27cc4c5702f
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
The review suggestion collapsing the dispatch into a conditional
expression landed with a mis-indented line, which broke module parsing.
Keep the conditional-expression form, formatted.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
RAHasher can't read the block-compressed RVZ/WIA containers Dolphin
creates, so GameCube and Wii games stored as .rvz/.wia never matched on
RetroAchievements ("Not a Gamecube disc" / "Not a supported Wii file").
Add utils/rvz_hasher.py, which reconstructs only the disc byte ranges
the RA hash covers, mirroring rcheevos:
- An RVZ/WIA reader with random access over raw-data and partition
groups (NONE/bzip2/LZMA/LZMA2/Zstandard codecs, RVZ packing with the
lagged-Fibonacci junk PRNG, and stored hash exceptions).
- GameCube: MD5 of the boot header, apploader and main.dol segments.
- Wii: the hash additionally covers encrypted cluster bytes, so the
reader recalculates the H0/H1/H2 hash tree, applies the container's
hash exceptions and re-encrypts clusters with the embedded title key
(AES-128-CBC) to reproduce the exact retail disc bytes.
RAHasherService tries the native path for .rvz/.wia on the GameCube and
Wii platforms and falls back to RAHasher on any failure.
Verified against Mario Kart: Double Dash!! (USA) and Super Mario Galaxy
(USA) RVZ dumps: the computed hashes are present in the official RA
hash lists (games 7693 and 189), and RAHasher 1.8.3 produces identical
hashes when run on disc images reconstructed by the same reader.
Closes#3649Closes#3650
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
SuperGrafx games never matched against RetroAchievements: the supergrafx
slug had no RA platform ID, so RA hashing was skipped during scans and
matching bailed out early.
RetroAchievements has no separate SuperGrafx console; its games share the
PC Engine/TurboGrafx-16 console, ID 8, same as tg16. Map supergrafx to
that console in both RA tables, mirroring the existing tg16 entries.
Fixes#3651.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Famicom Disk System (FDS) games never matched against RetroAchievements:
the fds slug had no RA platform ID, so RA hashing was skipped during scans
and matching bailed out early.
RetroAchievements lists the FDS as its own console, ID 81, separate from
the NES/Famicom console (ID 7). Map fds to that console in both RA tables,
mirroring the existing platform entries.
Fixes#3646.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
MSX2 games never matched against RetroAchievements: the msx2 slug had no
RA platform ID, so RA hashing was skipped during scans and matching
bailed out early.
RetroAchievements has no separate MSX2 console; it groups MSX2 under the
MSX console, ID 29. Map msx2 to that console in both RA tables, mirroring
the existing msx entry.
Fixes#3644.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
PSP games stored as .cso (and .ciso/.zso/.dax) never matched on
RetroAchievements because RomM hands these files to the external RAHasher
binary, which can't read CSO/ZISO/DAX compressed-ISO containers and fails
with "Could not open track". The game was then left without an RA link.
The PSP RA hash does not depend on the whole disc: rcheevos computes it as
MD5(PSP_GAME/PARAM.SFO + PSP_GAME/SYSDIR/EBOOT.BIN), each file capped at
64 MiB. Those containers are block-indexed, so we can decompress just the
blocks those two files occupy and hash them in-process, producing the
identical hash RA stores (and PPSSPP computes).
Add utils/psp_hasher.py: a seekable block-decoder for CISO/ZISO (deflate
and LZ4) and DAX containers, a minimal ISO9660 reader to locate the two
files, and calculate_psp_ra_hash(). RAHasherService now computes the hash
natively for PSP .cso/.ciso/.zso/.dax files, falling back to RAHasher on
any failure. Raw .iso PSP discs still go to RAHasher, which reads them fine.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KsyrT6n8WYWWxR2XGoEASs
Folder-stored disc games (the standard Redump .cue + .bin layout, .gdi
sets, multi-bin, etc.) never matched RetroAchievements. roms_handler
builds an `ra_path` ending in `/*` when the folder has no .chd, and
RAHasherService only rescued that glob for folders containing archives.
A folder of plain uncompressed tracks fell through, so the literal `*`
reached RAHasher via create_subprocess_exec (no shell to expand it),
which failed with "Could not open track" and stored an empty ra_hash.
Resolve the `/*` glob to a single real file before spawning RAHasher:
prefer a disc descriptor (.cue/.gdi/.m3u), which RAHasher follows to the
referenced tracks, otherwise fall back to the largest file in the folder
(raw .iso/.bin, or the main file of a multi-file cartridge set). This
mirrors the existing "pick the largest .chd" handling for CHD folders.
Fixes#3497.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ScreenScraper enforces a per-account *thread* (concurrency) cap rather than
a request rate. Requests can take several seconds, so spacing out request
starts at 1/s could still leave multiple requests overlapping in flight,
exceeding the cap and getting rejected with ScreenScraper's custom HTTP codes.
- Add ConcurrencyLimiter: a runtime-resizable, loop-agnostic limiter that
bounds simultaneous in-flight operations (held for the whole request via
async context manager), instead of spacing request starts.
- Switch the ScreenScraper service from the req/s RateLimiter to a module-level
ConcurrencyLimiter defaulting to a single thread.
- Recognize contributor/donor accounts: parse `ssuser.maxthreads` from each
response and raise the concurrency allowance to match, so supporters scrape
with their full thread count instead of the conservative default.
Adds unit tests for the limiter (blocking, wake-on-release, runtime resize)
and for the ScreenScraper slot-holding and thread-allowance updates.
https://claude.ai/code/session_01133QQuWvq8Zm25DZMP9PVr
Wire the existing RateLimiter into the IGDB, ScreenScraper, MobyGames and
RetroAchievements services so requests are spaced under each provider's
documented req/s cap, instead of only reacting to HTTP 429 after the fact.
- IGDB: 4 req/s (documented hard limit)
- MobyGames: 1 req/s (free-tier burst cap)
- ScreenScraper: 1 req/s (free-tier throttle)
- RetroAchievements: 4 req/s (conservative; no published hard limit)
A slot is acquired before both the initial request and the timeout/429
retry. The reactive 2s 429 backoff is kept as a fallback. Tests neutralize
the shared limiters via an autouse fixture and assert acquire() is awaited.
https://claude.ai/code/session_01133QQuWvq8Zm25DZMP9PVr
The archive branch of get_rom_files (introduced in #3412) was missing
the RAHasherService.calculate_hash call that exists in the non-archive
branch, causing all archive-format ROMs to produce an empty ra_hash
during scanning regardless of platform.
The RA hash call is now made for archive ROMs, mirroring the existing
non-archive behaviour. The RA_BUFFER_HASH_UNSUPPORTED skip logic in
RAHasherService already handles disc-based platforms (PSX, PS2, PSP,
Saturn, Dreamcast, etc.) so those continue to be excluded automatically.
Also improves handling of folder-based multi-file ROMs whose directories
contain compressed files. RAHasher cannot process archives via the /*
glob and fails with "Could not open file". The fix mirrors the existing
CHD folder logic: for cartridge platforms the largest archive in the
folder is passed directly to RAHasher for buffer hashing; for disc
platforms the call is skipped as buffer hashing is unsupported.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix several issues in ScreenScraper API request/response handling:
- Correctly handle SS-specific HTTP error codes (KO responses, 429, 431,
and the SS-quirk of returning 401 when server CPU >60%).
- Construct requests with proper parameter encoding so jeuInfos lookups
and search queries return the expected results.
- Store media URLs returned by SS as-is, preserving the dev credential
query parameters required for media playback. Removing them broke
downstream media fetches.
To keep dev credentials out of log output, add a redacting formatter in
the logger pipeline that scrubs ssid/sspassword/devid/devpassword query
parameters from any URL it sees.
Test coverage added for the new HTTP error paths and the as-is URL
storage behaviour.
Callers now pass the full platform dict and rom.fs_extension; the service
normalizes the extension (optional leading dot, case-insensitive) before
checking the compressed-archive skip set, so ROMs stored with bare
extensions like "zip" correctly hit the skip path.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
RAHasher was being spawned for every hashable ROM regardless of file
type. When the source file is a zip/7z/tar and the RA platform needs
an on-disk disc image (PSX, PS2, PSP, Saturn, Dreamcast, Sega CD,
3DO, PC-FX, Neo Geo CD, TurboGrafx CD, Atari Jaguar CD, Wii), the
subprocess fails with "Unsupported console for buffer hash: {id}"
after paying full process-spawn overhead per ROM — a serious slowdown
when indexing large zipped collections (e.g. myrient PS2/PSP sets).
calculate_hash now short-circuits those combinations with a debug log
and no subprocess. Raw disc images (.iso, .chd, .cue/.bin) and
archives on cartridge platforms still go through RAHasher as before.
Also centralize COMPRESSED_FILE_EXTENSIONS in utils/filesystem.py so
roms_handler (is_compressed_file / hashing), rahasher (skip logic),
and feeds (PKGi passthrough) share one source of truth. The shared
set adds .rar, which is_compressed_file now recognizes too.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds the libretro thumbnail repository as a first-class artwork source so
region-correct box art (PAL/Europe, Japan, etc.) can be matched directly
to ROM filenames, addressing rommapp/romm#3239.
Implementation follows the SGDB handler pattern (artwork-only, no game
metadata): MetadataSource enum entry, scan-time fetch wired into the
SCAN_ARTWORK_PRIORITY loop, /search/roms integration, MatchRom dialog
chip + cover selection, and a heartbeat flag.
Matching is exact case-insensitive against the directory listing first
(so a ROM named "(Europe)" lands on the (Europe) artwork), with a
JaroWinkler fuzzy fallback at 0.8 that strips parenthetical tags from
both sides. Listings are cached in Redis with a 24h TTL.
`libretro_id` is persisted on the Rom model as the SHA1 hex of the
matched libretro filename — stable across scans, distinct per region,
indexed for lookup. Migration 0077 adds the column.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>