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):
+2
View File
@@ -545,6 +545,7 @@ function renderModal(g) {
$("#modalBody").innerHTML = `
<div class="modal-grid">
<div class="modal-cover" id="modalCover">
<div class="cover-blur" id="modalCoverBlur"></div>
<img data-appid="${g.appid}" src="${coverUrl(g.appid)}" alt="">
<div class="fallback">${esc(g.name)}</div>
</div>
@@ -575,6 +576,7 @@ function renderModal(g) {
</div>
</div>`;
$("#modalCoverBlur").style.backgroundImage = `url("${coverUrl(g.appid)}")`;
attachCoverFallback($("#modalCover img"));
$("#modalClose").addEventListener("click", () => $("#modal").close());
+21 -3
View File
@@ -554,11 +554,29 @@ textarea { resize: vertical; min-height: 54px; }
grid-template-columns: 300px minmax(0, 1fr);
max-height: calc(100vh - 36px);
}
.modal-cover { position: relative; background: var(--bg-2); }
.modal-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.modal-cover { position: relative; overflow: hidden; background: var(--bg-2); }
.modal-cover .cover-blur {
position: absolute;
inset: -24px;
background-size: cover;
background-position: center;
filter: blur(24px) saturate(1.2);
opacity: .48;
transform: scale(1.08);
z-index: 0;
}
.modal-cover img {
position: relative;
z-index: 1;
width: 100%;
height: 100%;
object-fit: contain;
display: block;
}
.modal-cover .fallback { display: none; }
.modal-cover.noimg .cover-blur { display: none; }
.modal-cover.noimg .fallback {
position: absolute; inset: 0; display: grid; place-items: center;
position: absolute; inset: 0; display: grid; place-items: center; z-index: 2;
background: linear-gradient(145deg, rgba(243, 180, 92, .25), rgba(94, 234, 212, .12)), var(--bg-2);
font-size: 22px; font-weight: 700; text-align: center; padding: 20px;
}