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

+49 -36
View File
@@ -25,17 +25,36 @@ import db
import steam_source
CDN = "https://cdn.cloudflare.steamstatic.com/steam/apps"
NAMES = ("library_600x900.jpg", "header.jpg")
CACHE_NAMES = steam_source.COVER_ORDER
CDN_NAMES = (
"library_600x900.jpg",
"library_capsule.jpg",
"header.jpg",
"library_header.jpg",
"library_hero.jpg",
"logo.png",
)
def has_any(paths):
for directory, names in paths:
if not directory:
continue
for name in names:
if os.path.isfile(os.path.join(directory, name)):
return True
return False
def has_cached(path):
return any(os.path.isfile(os.path.join(path, name)) for name in CACHE_NAMES)
def download(url, path):
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 not data:
return False
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 True
except Exception:
return False
def main():
@@ -56,8 +75,13 @@ def main():
con = db.connect(args.db)
db.init(con)
rows = con.execute("""SELECT appid, name FROM games
WHERE LOWER(type)='game' ORDER BY review_pct DESC""").fetchall()
rows = con.execute("""
SELECT g.appid, g.name, d.header_image
FROM games g
LEFT JOIN game_details d ON d.appid = g.appid
WHERE LOWER(g.type) = 'game'
ORDER BY COALESCE(g.review_pct, 0) DESC
""").fetchall()
if not args.all and args.limit:
rows = rows[: args.limit]
print(f"Games: {len(rows)}")
@@ -66,31 +90,24 @@ def main():
for row in rows:
appid = row["appid"]
cached = os.path.join(cache_dir, str(appid))
steam_art = os.path.join(lib_cache, str(appid)) if lib_cache else None
if has_any([(cached, NAMES), (steam_art, steam_source_names())]):
if has_cached(cached) or steam_source.find_cover(appid, lib_cache):
skipped += 1
continue
got = False
for name in NAMES:
url = f"{CDN}/{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 not data:
continue
os.makedirs(cached, exist_ok=True)
path = os.path.join(cached, name)
tmp = path + ".tmp"
with open(tmp, "wb") as f:
f.write(data)
os.replace(tmp, path)
got = True
break
except Exception:
continue
finally:
header_image = row["header_image"]
if header_image:
got = download(header_image, os.path.join(cached, "header.jpg"))
time.sleep(args.delay)
if not got:
for name in CDN_NAMES:
url = f"{CDN}/{appid}/{name}"
got = download(url, os.path.join(cached, name))
time.sleep(args.delay)
if got:
break
if got:
downloaded += 1
else:
@@ -100,9 +117,5 @@ def main():
print(f"cache: {cache_dir}")
def steam_source_names():
return ("library_600x900.jpg", "header.jpg", "library_hero.jpg", "logo.png")
if __name__ == "__main__":
main()