Skip to content

feat(backend): categorize Switch rom files by title ID - #3876

Closed
lucid-void wants to merge 2 commits into
rommapp:masterfrom
lucid-void:feat/switch-title-id-categorization
Closed

feat(backend): categorize Switch rom files by title ID#3876
lucid-void wants to merge 2 commits into
rommapp:masterfrom
lucid-void:feat/switch-title-id-categorization

Conversation

@lucid-void

@lucid-void lucid-void commented Jul 22, 2026

Copy link
Copy Markdown

Description
Automatically categorizes Nintendo Switch / Switch 2 ROM files as base game, update, or DLC based on the title ID in their filename, so base + update(s) + DLC belonging to the same game can live loose in a single game folder and still be tagged individually, without requiring update/ or dlc/ subfolders.

Today, a file's RomFileCategory is derived only from the folder it sits in (e.g. a file under update/ becomes an UPDATE). This PR adds a fallback: when a Switch/Switch-2 file isn't already categorized by its directory layout, its 16-hex Nintendo title ID is parsed from the filename and classified per the rules from #2526:

  • 4th-to-last nibble odd → DLC
  • low 12 bits == 0x800 → UPDATE
  • otherwise (low 12 bits cleared, even 4th-to-last nibble) → GAME

Example (Breath of the Wild):

┌────────┬──────────────────┬──────────┐
│ File │ Title ID │ Category │
├────────┼──────────────────┼──────────┤
│ Base │ 01007EF00011E000 │ GAME │
├────────┼──────────────────┼──────────┤
│ Update │ 01007EF00011E800 │ UPDATE │
├────────┼──────────────────┼──────────┤
│ DLC 1 │ 01007EF00011F001 │ DLC │
├────────┼──────────────────┼──────────┤
│ DLC 2 │ 01007EF00011F002 │ DLC │
└────────┴──────────────────┴──────────┘

Notes / scope:

  • Folder-based categorization still wins. Title-ID classification is only a fallback when the directory layout doesn't already assign a category, so existing update//dlc/ layouts are unchanged.
  • Grouping onto a single game entry already works via RomM's multi-part ROM model (a directory = one Rom, its inner files = RomFiles). This change makes the loose-files-in-one-folder layout viable by tagging each file correctly.
  • Tinfoil integration is unaffected. The Tinfoil feed emits one download URL per RomFile (filtered by extension, not category), so grouping/tagging files under one ROM entry doesn't change what Tinfoil sees.
  • Gated strictly to the switch and switch-2 platforms; reuses the existing SWITCH_PRODUCT_ID_REGEX.

Implementation: a switch_title_id_category() helper plus a fallback branch in _build_rom_file, both in backend/handler/filesystem/roms_handler.py.

▎ AI assistance disclosure: This change was implemented with AI assistance (Claude Code). The title-ID classification logic, the fallback wiring in _build_rom_file, and the accompanying tests were AI-generated and reviewed/verified by me before submitting.

Closes #2526

Checklist

  • I've tested the changes locally
  • I've updated relevant comments
  • I've assigned reviewers for this PR
  • I've added unit tests that cover the changes

Assign base game / update / DLC categories to Nintendo Switch and
Switch 2 rom files from the title ID in their filename, so files sharing
a game folder are tagged individually without needing update/ or dlc/
subfolders. Falls back to this only when the directory layout doesn't
already categorize the file, and reuses the existing title ID regex.

Closes rommapp#2526

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR categorizes loose Nintendo Switch ROM files from title IDs in their filenames. The main changes are:

  • Adds title-ID classification for games, updates, and DLC.
  • Applies classification only when folder-based categorization finds no category.
  • Limits the fallback to Switch and Switch 2 platforms.
  • Adds helper and integration tests for uppercase title IDs.

Confidence Score: 4/5

The filename parsing path needs to recognize lowercase title IDs before merging.

  • Folder-based category precedence remains intact.
  • The classification rules handle the supplied uppercase examples.
  • Valid lowercase hexadecimal IDs bypass the new fallback and remain unclassified.

backend/handler/filesystem/roms_handler.py

Important Files Changed

Filename Overview
backend/handler/filesystem/roms_handler.py Adds Switch title-ID classification and fallback integration, but valid lowercase hexadecimal IDs are not recognized.
backend/tests/handler/filesystem/test_roms_handler.py Covers uppercase game, update, DLC, and unmatched filenames, but omits lowercase title IDs.

Fix All in Claude Code

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
backend/handler/filesystem/roms_handler.py:126
**Lowercase Title IDs Stay Unclassified**

`SWITCH_PRODUCT_ID_REGEX` accepts only uppercase hexadecimal characters, so a valid filename such as `Zelda [01007ef00011e800].nsp` produces no match. The fallback then leaves the update uncategorized instead of assigning `UPDATE`.

```suggestion
    match = SWITCH_PRODUCT_ID_REGEX.search(file_name.upper())
```

Reviews (1): Last reviewed commit: "feat(backend): categorize Switch rom fil..." | Re-trigger Greptile

Comment thread backend/handler/filesystem/roms_handler.py Outdated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@gantoine gantoine added the on-hold Pending further research or blocked by another issue label Jul 22, 2026
@tmgast

tmgast commented Jul 24, 2026

Copy link
Copy Markdown
Member

Same story as #3883: I went with native binary extraction (sigil) that categorizes Switch base, update, and DLC from the content metadata instead of the filename, and it covers serials and title ids for most platforms where that's useful. It's all in #3925.

@gantoine gantoine closed this Jul 24, 2026
@lucid-void
lucid-void deleted the feat/switch-title-id-categorization branch July 30, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on-hold Pending further research or blocked by another issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Additional Info on Switch TitleIDs

3 participants