mirror of
https://github.com/moraroy/NonSteamLaunchers-On-Steam-Deck.git
synced 2026-06-13 04:04:59 +03:00
Refactor Steam AppList lookup and caching logic
Release Please / release-please (push) Has been cancelled
Release Please / release-please (push) Has been cancelled
This commit is contained in:
+28
-11
@@ -453,23 +453,40 @@ def get_steam_store_appid(steam_store_game_name):
|
||||
# Fallback using Steam AppList (cached)
|
||||
global steam_applist_cache
|
||||
if steam_applist_cache is None:
|
||||
steam_applist_cache = {}
|
||||
|
||||
def normalize_name(name):
|
||||
name = name.lower()
|
||||
name = re.sub(r'[®™]', '', name)
|
||||
name = ' '.join(name.split())
|
||||
return name
|
||||
|
||||
if steam_store_game_name not in steam_applist_cache:
|
||||
time.sleep(0.5) # Small delay to avoid spamming Steam
|
||||
query = urllib.parse.quote(steam_store_game_name)
|
||||
url = f"https://store.steampowered.com/api/storesearch/?term={query}&l=english&cc=US"
|
||||
try:
|
||||
STEAM_BASE_URL = "https://api.steampowered.com"
|
||||
app_list_url = f"{STEAM_BASE_URL}/ISteamApps/GetAppList/v2/"
|
||||
response = requests.get(app_list_url)
|
||||
response = requests.get(url, timeout=10)
|
||||
response.raise_for_status()
|
||||
steam_applist_cache = response.json()['applist']['apps']
|
||||
print("Cached Steam app list from Steam API.")
|
||||
data = response.json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Steam AppList fallback failed for {steam_store_game_name}: {e}")
|
||||
print(f"Fallback Steam lookup failed for {steam_store_game_name}: {e}")
|
||||
return None
|
||||
|
||||
for app in steam_applist_cache:
|
||||
if steam_store_game_name.lower() in app['name'].lower():
|
||||
print(f"Found App ID for {steam_store_game_name} via cached Steam AppList: {app['appid']}")
|
||||
return app['appid']
|
||||
target = normalize_name(steam_store_game_name)
|
||||
fallback_appid = None
|
||||
for item in data.get("items", []):
|
||||
if normalize_name(item.get("name", "")) == target:
|
||||
fallback_appid = str(item.get("id"))
|
||||
break
|
||||
|
||||
print(f"No App ID found for {steam_store_game_name} in cached Steam AppList.")
|
||||
steam_applist_cache[steam_store_game_name] = fallback_appid
|
||||
|
||||
if steam_applist_cache[steam_store_game_name]:
|
||||
print(f"Found App ID for {steam_store_game_name} via fallback Steam search API: {steam_applist_cache[steam_store_game_name]}")
|
||||
return steam_applist_cache[steam_store_game_name]
|
||||
|
||||
print(f"No App ID found for {steam_store_game_name} in fallback Steam search API.")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user