From c60ec614249f63720be77bcb09ec660c922b377c Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Tue, 2 Jan 2024 16:57:14 -0500 Subject: [PATCH] Support for switch update and DLC files --- backend/handler/igdb_handler.py | 18 +++++++++++++++--- .../src/components/Details/VersionSwitcher.vue | 4 +--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/backend/handler/igdb_handler.py b/backend/handler/igdb_handler.py index 6a207f2e3..d0f8eb843 100644 --- a/backend/handler/igdb_handler.py +++ b/backend/handler/igdb_handler.py @@ -165,18 +165,21 @@ class IGDBHandler: @staticmethod async def _ps2_opl_format(match: re.Match[str], search_term: str) -> str: serial_code = match.group(1) + with open(PS2_OPL_INDEX_FILE, "r") as index_json: opl_index = json.loads(index_json.read()) index_entry = opl_index.get(serial_code, None) if index_entry: search_term = index_entry["Name"] # type: ignore + return search_term @staticmethod async def _switch_titledb_format(match: re.Match[str], search_term: str) -> str: - title_id = match.group(1) titledb_index = {} + title_id = match.group(1) + try: with open(SWITCH_TITLEDB_INDEX_FILE, "r") as index_json: titledb_index = json.loads(index_json.read()) @@ -192,12 +195,19 @@ class IGDBHandler: index_entry = titledb_index.get(title_id, None) if index_entry: search_term = index_entry["name"] # type: ignore + return search_term @staticmethod async def _switch_productid_format(match: re.Match[str], search_term: str) -> str: - product_id = match.group(1) product_id_index = {} + product_id = match.group(1) + + # Game updates have the same product ID as the main application, except with bitmask 0x800 set + product_id = list(product_id) + product_id[-3] = '0' + product_id = ''.join(product_id) + try: with open(SWITCH_PRODUCT_ID_FILE, "r") as index_json: product_id_index = json.loads(index_json.read()) @@ -218,6 +228,7 @@ class IGDBHandler: @staticmethod async def _mame_format(search_term: str) -> str: mame_index = {"menu": {"game": []}} + try: with open(MAME_XML_FILE, "r") as index_xml: mame_index = xmltodict.parse(index_xml.read()) @@ -240,6 +251,7 @@ class IGDBHandler: search_term = get_search_term( index_entry[0].get("description", search_term) ) + return search_term @check_twitch_token @@ -268,7 +280,7 @@ class IGDBHandler: search_term = await self._ps2_opl_format(match, search_term) # Support for switch titleID filename format - match = re.match(SWITCH_TITLEDB_REGEX, file_name) + match = re.search(SWITCH_TITLEDB_REGEX, file_name) if platform_idgb_id == SWITCH_IGDB_ID and match: search_term = await self._switch_titledb_format(match, search_term) diff --git a/frontend/src/components/Details/VersionSwitcher.vue b/frontend/src/components/Details/VersionSwitcher.vue index 1f5643af3..eccea1b05 100644 --- a/frontend/src/components/Details/VersionSwitcher.vue +++ b/frontend/src/components/Details/VersionSwitcher.vue @@ -11,7 +11,7 @@ function formatItem(rom) { const langs = rom.languages.map((l) => languageToEmoji(l)).join(" "); const regions = rom.regions.map((r) => regionToEmoji(r)).join(" "); const tags = rom.tags.map((t) => `(${t})`).join(" "); - return `${langs} ${regions} ${tags}`; + return `${langs} ${regions} ${tags}` || rom.file_name; } function updateVersion() { @@ -42,8 +42,6 @@ function updateVersion() {