main init
This commit is contained in:
101
Itch/itch_check.py
Normal file
101
Itch/itch_check.py
Normal file
@@ -0,0 +1,101 @@
|
||||
"""Pre-flight check of an itch.io package folder (docs/itchio) before uploading.
|
||||
|
||||
py -3.12 itch_check.py docs/itchio [--upload release/game-web.zip] [--upload release/Game.exe]
|
||||
|
||||
Checks: cover size/ratio, banner/background, screenshot count and size, description.html
|
||||
(no <script>, size, links), README fields filled, uploads exist (zip has index.html at the top,
|
||||
size limits). Prints OK / WARN / FEHLT lines - short on purpose.
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import zipfile
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("folder")
|
||||
ap.add_argument("--upload", action="append", default=[])
|
||||
a = ap.parse_args()
|
||||
f = a.folder
|
||||
out = []
|
||||
ok = lambda s: out.append("OK " + s)
|
||||
warn = lambda s: out.append("WARN " + s)
|
||||
miss = lambda s: out.append("FEHLT " + s)
|
||||
|
||||
def img(name):
|
||||
p = os.path.join(f, name)
|
||||
return Image.open(p).size if os.path.exists(p) else None
|
||||
|
||||
c = img("cover.png")
|
||||
if not c:
|
||||
miss("cover.png (630x500)")
|
||||
elif c[0] < 315 or abs(c[0] / c[1] - 630 / 500) > 0.03:
|
||||
warn(f"cover.png {c[0]}x{c[1]} - empfohlen 630x500 (mind. 315x250, Verhältnis 1.26)")
|
||||
else:
|
||||
ok(f"cover.png {c[0]}x{c[1]}")
|
||||
for n in ("banner_960x256.png", "background_1920x1200.jpg"):
|
||||
(ok if img(n) else warn)(n + ("" if img(n) else " fehlt (nur für Edit theme)"))
|
||||
|
||||
shots = []
|
||||
for d in ("screenshots", "promo", "screens"):
|
||||
p = os.path.join(f, d)
|
||||
if os.path.isdir(p):
|
||||
shots += [os.path.join(p, x) for x in os.listdir(p) if x.lower().endswith((".png", ".jpg", ".gif")) and not x.startswith("raw_")]
|
||||
raws = [x for d in ("screenshots",) if os.path.isdir(os.path.join(f, d)) for x in os.listdir(os.path.join(f, d)) if x.startswith("raw_")]
|
||||
if len(shots) < 3:
|
||||
miss(f"Screenshots: {len(shots)} (mind. 3, gut 5-8)")
|
||||
else:
|
||||
small = [os.path.basename(s) for s in shots if Image.open(s).size[0] < 1280]
|
||||
big = [os.path.basename(s) for s in shots if os.path.getsize(s) > 3 * 1024 * 1024]
|
||||
ok(f"{len(shots)} Screenshots")
|
||||
if small:
|
||||
warn("klein (<1280 breit): " + ", ".join(small[:5]))
|
||||
if big:
|
||||
warn("über 3 MB (itch-Limit ok, aber langsam): " + ", ".join(big[:5]))
|
||||
if raws:
|
||||
warn(f"{len(raws)} raw_*.png aus itch_capture noch nicht aussortiert")
|
||||
|
||||
desc = os.path.join(f, "description.html")
|
||||
if not os.path.exists(desc):
|
||||
miss("description.html")
|
||||
else:
|
||||
t = open(desc, encoding="utf-8-sig").read()
|
||||
body = re.sub(r"(?is)^.*<body[^>]*>|</body>.*$", "", t)
|
||||
if re.search(r"<script|<iframe|<style", body, re.I):
|
||||
warn("description.html: <script>/<iframe>/<style> - itch entfernt das")
|
||||
if len(re.sub(r"<[^>]+>", "", t)) < 400:
|
||||
warn("description.html sehr kurz")
|
||||
if re.search(r"TODO|XXX|\{\{", t):
|
||||
warn("description.html enthält Platzhalter")
|
||||
ok(f"description.html ({len(t)} Zeichen)")
|
||||
|
||||
readme = os.path.join(f, "README.md")
|
||||
if not os.path.exists(readme):
|
||||
miss("README.md (Felder für Edit game)")
|
||||
else:
|
||||
t = open(readme, encoding="utf-8-sig").read()
|
||||
holes = re.findall(r"\|\s*([^|\n]+?)\s*\|\s*(?:_[^_]*_|…|TODO|\?)\s*\|", t)
|
||||
(warn("README: offene Felder: " + ", ".join(h.strip("* ") for h in holes[:8])) if holes else ok("README.md Felder ausgefüllt"))
|
||||
|
||||
for u in a.upload:
|
||||
if not os.path.exists(u):
|
||||
miss(f"Upload {u}")
|
||||
continue
|
||||
mb = os.path.getsize(u) / 1024 / 1024
|
||||
if u.lower().endswith(".zip"):
|
||||
with zipfile.ZipFile(u) as z:
|
||||
names = z.namelist()
|
||||
if "index.html" not in names:
|
||||
warn(f"{u}: kein index.html auf oberster Ebene (für Browser-Spiele nötig)")
|
||||
if len(names) > 1000:
|
||||
warn(f"{u}: {len(names)} Dateien (itch: max. 1000 für HTML-Spiele)")
|
||||
(warn if mb > 1000 else ok)(f"Upload {os.path.basename(u)} {mb:.1f} MB" + (" - über 1 GB: butler nötig" if mb > 1000 else ""))
|
||||
|
||||
print("\n".join(out))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user