mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
fix(screenscraper): use internal filename as romnom for single-file archives
When sending a hash lookup to ScreenScraper, romnom was always set to the archive filename on disk (e.g. Mario.zip). For single-file archives, the hash is computed from the internal file (e.g. mario.n64), so sending the archive name sends slightly incorrect info to ss.fr during a KO scrape. When archive_members has exactly one entry, romnom now uses that member's name. Multi-file archives and non-archive files continue to use the filesystem filename unchanged. Closes #3444 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -713,7 +713,11 @@ class SSHandler(MetadataHandler):
|
||||
sha1=sha1_hash,
|
||||
crc=crc_hash,
|
||||
rom_size_bytes=fs_size_bytes,
|
||||
rom_name=first_file.file_name,
|
||||
rom_name=(
|
||||
first_file.archive_members[0]["name"]
|
||||
if first_file.archive_members and len(first_file.archive_members) == 1
|
||||
else first_file.file_name
|
||||
),
|
||||
rom_type=_get_rom_type(first_file),
|
||||
)
|
||||
if not res:
|
||||
|
||||
@@ -716,6 +716,93 @@ class TestLookupRom:
|
||||
assert result["ss_id"] is None
|
||||
assert is_not_game is True
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_romnom_uses_archive_member_name_for_single_file_archive(self):
|
||||
handler = SSHandler()
|
||||
mock_file = self._make_mock_file()
|
||||
mock_file.file_name = "Mario.zip"
|
||||
mock_file.archive_members = [
|
||||
{
|
||||
"name": "mario.n64",
|
||||
"size": 1024,
|
||||
"crc_hash": "",
|
||||
"md5_hash": "",
|
||||
"sha1_hash": "",
|
||||
}
|
||||
]
|
||||
captured = {}
|
||||
|
||||
async def capture(**kwargs):
|
||||
captured.update(kwargs)
|
||||
return None
|
||||
|
||||
with patch.object(handler.ss_service, "get_game_info", side_effect=capture):
|
||||
await handler.lookup_rom(MagicMock(platform_slug="n64"), 14, [mock_file])
|
||||
assert captured.get("rom_name") == "mario.n64"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_romnom_uses_archive_filename_for_multi_file_archive(self):
|
||||
handler = SSHandler()
|
||||
mock_file = self._make_mock_file()
|
||||
mock_file.file_name = "Mario.zip"
|
||||
mock_file.archive_members = [
|
||||
{
|
||||
"name": "mario.bin",
|
||||
"size": 1024,
|
||||
"crc_hash": "",
|
||||
"md5_hash": "",
|
||||
"sha1_hash": "",
|
||||
},
|
||||
{
|
||||
"name": "mario.cue",
|
||||
"size": 64,
|
||||
"crc_hash": "",
|
||||
"md5_hash": "",
|
||||
"sha1_hash": "",
|
||||
},
|
||||
]
|
||||
captured = {}
|
||||
|
||||
async def capture(**kwargs):
|
||||
captured.update(kwargs)
|
||||
return None
|
||||
|
||||
with patch.object(handler.ss_service, "get_game_info", side_effect=capture):
|
||||
await handler.lookup_rom(MagicMock(platform_slug="psx"), 57, [mock_file])
|
||||
assert captured.get("rom_name") == "Mario.zip"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_romnom_uses_archive_filename_when_no_archive_members(self):
|
||||
handler = SSHandler()
|
||||
mock_file = self._make_mock_file()
|
||||
mock_file.file_name = "mario.n64"
|
||||
mock_file.archive_members = None
|
||||
captured = {}
|
||||
|
||||
async def capture(**kwargs):
|
||||
captured.update(kwargs)
|
||||
return None
|
||||
|
||||
with patch.object(handler.ss_service, "get_game_info", side_effect=capture):
|
||||
await handler.lookup_rom(MagicMock(platform_slug="n64"), 14, [mock_file])
|
||||
assert captured.get("rom_name") == "mario.n64"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_romnom_uses_archive_filename_when_archive_members_empty(self):
|
||||
handler = SSHandler()
|
||||
mock_file = self._make_mock_file()
|
||||
mock_file.file_name = "Mario.zip"
|
||||
mock_file.archive_members = []
|
||||
captured = {}
|
||||
|
||||
async def capture(**kwargs):
|
||||
captured.update(kwargs)
|
||||
return None
|
||||
|
||||
with patch.object(handler.ss_service, "get_game_info", side_effect=capture):
|
||||
await handler.lookup_rom(MagicMock(platform_slug="n64"), 14, [mock_file])
|
||||
assert captured.get("rom_name") == "Mario.zip"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_returns_notgame_flag_on_zzz_prefix(self):
|
||||
notgame_response = {
|
||||
|
||||
Reference in New Issue
Block a user