fix: support new Steam cover layout

This commit is contained in:
strsv committed 2026-11-06 06:35:33 +03:00
1 parent e433ca3842
commit 0784d4c143
12 files changed
+212 -88

No files matched your search

+61 -34
View File
@@ -44,8 +44,15 @@ except SystemExit:
LIB_CACHE = os.path.join(STEAM_ROOT, "appcache", "librarycache") if STEAM_ROOT else None
CACHE_DIR = os.path.join(BASE, "cache", "covers")
IMAGE_LOCK = threading.Lock()
COVER_NAMES = ("library_600x900.jpg", "header.jpg")
STEAM_COVER_NAMES = ("library_600x900.jpg", "header.jpg", "library_hero.jpg", "logo.png")
CACHE_COVER_NAMES = steam_source.COVER_ORDER
CDN_COVER_NAMES = (
"library_600x900.jpg",
"library_capsule.jpg",
"header.jpg",
"library_header.jpg",
"library_hero.jpg",
"logo.png",
)
STATIC = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
STATUSES = {"backlog", "playing", "played", "tribute", "nostalgia", "ignore"}
@@ -424,45 +431,65 @@ class Handler(BaseHTTPRequestHandler):
self._send(200, data, CONTENT_TYPES.get(ext, "image/jpeg"),
cache=True, max_age=2592000)
def _download_cover(self, url, path):
with IMAGE_LOCK:
if os.path.isfile(path):
with open(path, "rb") as f:
return f.read()
try:
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(req, timeout=20) as resp:
data = resp.read()
if data:
os.makedirs(os.path.dirname(path), exist_ok=True)
tmp = path + ".tmp"
with open(tmp, "wb") as f:
f.write(data)
os.replace(tmp, path)
return data
except Exception:
return None
return None
def _cover(self, appid):
# 1. our own cache
for name in COVER_NAMES:
path = os.path.join(CACHE_DIR, str(appid), name)
app_cache = os.path.join(CACHE_DIR, str(appid))
# 1. our own cache (including new-style names)
for name in CACHE_COVER_NAMES:
path = os.path.join(app_cache, name)
if os.path.isfile(path):
self._serve_image(path)
return
# 2. art already downloaded by the Steam client
if LIB_CACHE:
for name in STEAM_COVER_NAMES:
path = os.path.join(LIB_CACHE, str(appid), name)
if os.path.isfile(path):
self._serve_image(path)
return
# 3. download once from the CDN and keep it on disk
for name in COVER_NAMES:
path = os.path.join(CACHE_DIR, str(appid), name)
data = None
with IMAGE_LOCK:
if os.path.isfile(path):
with open(path, "rb") as f:
data = f.read()
else:
url = f"https://cdn.cloudflare.steamstatic.com/steam/apps/{appid}/{name}"
try:
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(req, timeout=20) as resp:
data = resp.read()
if data:
os.makedirs(os.path.dirname(path), exist_ok=True)
tmp = path + ".tmp"
with open(tmp, "wb") as f:
f.write(data)
os.replace(tmp, path)
except Exception:
data = None
# 2. art already downloaded by the Steam client (old and new layout)
local = steam_source.find_cover(appid, LIB_CACHE)
if local:
self._serve_image(local)
return
# 3. header_image from the cached store details (new hashed CDN URL)
con = connect()
try:
row = con.execute(
"SELECT header_image FROM game_details WHERE appid = ? AND COALESCE(header_image, '') <> ''",
(appid,)).fetchone()
finally:
con.close()
if row:
data = self._download_cover(row["header_image"], os.path.join(app_cache, "header.jpg"))
if data:
self._send(200, data, "image/jpeg", cache=True, max_age=2592000)
return
# 4. legacy CDN names, kept on disk
for name in CDN_COVER_NAMES:
path = os.path.join(app_cache, name)
url = f"https://cdn.cloudflare.steamstatic.com/steam/apps/{appid}/{name}"
data = self._download_cover(url, path)
if data:
self._send(200, data, "image/jpeg", cache=True, max_age=2592000)
return
self._error(404, "no cover")
def _api_get(self, path, qs):