Merge branch 'master' into fix/scan-log-overflow

This commit is contained in:
Georges-Antoine Assi
2024-03-14 22:02:02 -04:00
2 changed files with 40 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import os
import re
import sys
import time
import unicodedata
from typing import Final, Optional
import pydash
@@ -166,7 +167,6 @@ class IGDBHandler:
return wrapper
def _request(self, url: str, data: str, timeout: int = 120) -> list:
try:
res = requests.post(
@@ -227,6 +227,34 @@ class IGDBHandler:
def _normalize_cover_url(url: str) -> str:
return f"https:{url.replace('https:', '')}" if url != "" else ""
# This is expensive, so it should be used sparingly
@staticmethod
def _normalize_exact_match(name: str) -> str:
name = (
name.lower() # Convert to lower case,
.replace("_", " ") # Replace underscores with spaces
.replace("'", "") # Remove single quotes
.replace('"', "") # Remove double quotes
.strip() # Remove leading and trailing spaces
)
# Remove leading and trailing articles
name = re.sub(r"^(a|an|the)\b", "", name)
name = re.sub(r",\b(a|an|the)\b", "", name)
# Remove special characters and punctuation
converted_name = "".join((re.findall(r"\w+", name)))
# Convert to normal form
normalized_name = unicodedata.normalize("NFD", converted_name)
# Remove accents
canonical_form = "".join(
[c for c in normalized_name if not unicodedata.combining(c)]
)
return canonical_form
def _search_rom(
self, search_term: str, platform_idgb_id: int, category: int = 0
) -> dict:
@@ -251,8 +279,14 @@ class IGDBHandler:
exact_matches = [
rom
for rom in roms
if rom["name"].lower() == search_term.lower()
or rom["slug"].lower() == search_term.lower()
if (
rom["name"].lower() == search_term.lower()
or rom["slug"].lower() == search_term.lower()
or (
self._normalize_exact_match(rom["name"])
== self._normalize_exact_match(search_term)
)
)
]
return pydash.get(exact_matches or roms, "[0]", {})

View File

@@ -108,7 +108,7 @@ export function regionToEmoji(region: string) {
return "🇨🇳";
case "e":
case "eu":
case "eur":
case "eur":
case "europe":
return "🇪🇺";
case "f":
@@ -261,6 +261,7 @@ export const platformSlugEJSCoreMap = {
"neo-geo-pocket-color": "mednafen_ngp",
nes: "fceumm",
famicom: "fceumm",
fds: "fceumm",
"game-televisison": "fceumm",
"new-style-nes": "fceumm",
// n64: "mupen64plus_next", Disabled until emujs 4.0.12 is released
@@ -304,6 +305,6 @@ export const platformSlugEJSCoreMap = {
"turbografx16--1": "mednafen_pce",
virtualboy: "beetle_vb",
wonderswan: "mednafen_wswan",
"swancrystal": "mednafen_wswan",
swancrystal: "mednafen_wswan",
"wonderswan-color": "mednafen_wswan",
} as const;