@@ -331,6 +331,61 @@ async def scan_firmware(
331331 return Firmware (** firmware_attrs )
332332
333333
334+ async def resolve_launchbox_rom (
335+ * ,
336+ rom : Rom ,
337+ fs_name : str ,
338+ platform_slug : str ,
339+ scan_type : ScanType ,
340+ playmatch_rom : PlaymatchRomMatch ,
341+ remote_enabled : bool ,
342+ ) -> LaunchboxRom :
343+ """Resolve a ROM's LaunchBox match, by ID where one is known, else by filename."""
344+ # An ID already on the ROM is a decision (often a manual match), so it is
345+ # never traded for a filename guess.
346+ if (
347+ remote_enabled
348+ and rom .launchbox_id
349+ and (
350+ scan_type == ScanType .UPDATE
351+ or (scan_type == ScanType .UNMATCHED and not rom .launchbox_metadata )
352+ )
353+ ):
354+ return await meta_launchbox_handler .get_rom_by_id (
355+ rom .launchbox_id ,
356+ remote_enabled = True ,
357+ fs_name = fs_name ,
358+ platform_slug = platform_slug ,
359+ )
360+
361+ launchbox_rom = LaunchboxRom (launchbox_id = None )
362+
363+ if playmatch_rom ["launchbox_id" ] is not None and remote_enabled :
364+ log .debug (
365+ f"{ hl (fs_name )} identified by Playmatch as LaunchBox "
366+ f"{ hl (str (playmatch_rom ['launchbox_id' ]), color = BLUE )} { emoji .EMOJI_ALIEN_MONSTER } " ,
367+ extra = LOGGER_MODULE_NAME ,
368+ )
369+ launchbox_rom = await meta_launchbox_handler .get_rom_by_id (
370+ playmatch_rom ["launchbox_id" ],
371+ remote_enabled = True ,
372+ fs_name = fs_name ,
373+ platform_slug = platform_slug ,
374+ )
375+
376+ # Playmatch suggests an ID the metadata store may not hold, and on some
377+ # platforms it answers for nearly every ROM. Letting that miss stand would
378+ # strand the whole platform unmatched, so the filename lookup still runs.
379+ if not launchbox_rom .get ("launchbox_id" ):
380+ launchbox_rom = await meta_launchbox_handler .get_rom (
381+ fs_name ,
382+ platform_slug ,
383+ remote_enabled = remote_enabled ,
384+ )
385+
386+ return launchbox_rom
387+
388+
334389async def scan_rom (
335390 scan_type : ScanType ,
336391 platform : Platform ,
@@ -726,48 +781,14 @@ async def fetch_launchbox_rom(
726781 and rom .platform_slug in LAUNCHBOX_PLATFORM_LIST
727782 )
728783 ):
729- if (
730- scan_type == ScanType .UPDATE
731- and rom .launchbox_id
732- and launchbox_remote_enabled
733- ):
734- launchbox_rom = await meta_launchbox_handler .get_rom_by_id (
735- rom .launchbox_id ,
736- remote_enabled = True ,
737- fs_name = rom_attrs ["fs_name" ],
738- platform_slug = platform_slug ,
739- )
740- elif (
741- scan_type == ScanType .UNMATCHED
742- and rom .launchbox_id
743- and not rom .launchbox_metadata
744- and launchbox_remote_enabled
745- ):
746- # ID was set manually but metadata was never fetched
747- launchbox_rom = await meta_launchbox_handler .get_rom_by_id (
748- rom .launchbox_id ,
749- remote_enabled = True ,
750- fs_name = rom_attrs ["fs_name" ],
751- platform_slug = platform_slug ,
752- )
753- elif playmatch_rom ["launchbox_id" ] is not None and launchbox_remote_enabled :
754- log .debug (
755- f"{ hl (rom_attrs ['fs_name' ])} identified by Playmatch as LaunchBox "
756- f"{ hl (str (playmatch_rom ['launchbox_id' ]), color = BLUE )} { emoji .EMOJI_ALIEN_MONSTER } " ,
757- extra = LOGGER_MODULE_NAME ,
758- )
759- launchbox_rom = await meta_launchbox_handler .get_rom_by_id (
760- playmatch_rom ["launchbox_id" ],
761- remote_enabled = True ,
762- fs_name = rom_attrs ["fs_name" ],
763- platform_slug = platform_slug ,
764- )
765- else :
766- launchbox_rom = await meta_launchbox_handler .get_rom (
767- rom_attrs ["fs_name" ],
768- platform_slug ,
769- remote_enabled = launchbox_remote_enabled ,
770- )
784+ launchbox_rom = await resolve_launchbox_rom (
785+ rom = rom ,
786+ fs_name = str (rom_attrs ["fs_name" ]),
787+ platform_slug = platform_slug ,
788+ scan_type = scan_type ,
789+ playmatch_rom = playmatch_rom ,
790+ remote_enabled = launchbox_remote_enabled ,
791+ )
771792
772793 metadata = launchbox_rom .get ("launchbox_metadata" )
773794 if metadata :
0 commit comments