DEV Community

Frank
Frank

Posted on

Parse an osu! skin.ini with Python and check that every referenced prefix still has files

A skin.ini can name prefixes and files that you later renamed or forgot to pack. The failure is quiet: osu!stable just falls back to the default skin, and you only notice in-game. This script reads skin.ini, prints every section and key, and then checks the usual prefix keys (HitCirclePrefix, ScorePrefix, ComboPrefix) and a short list of well-known filenames to see whether the corresponding PNGs are actually in the folder.

It uses only the Python standard library. Point it at the root of a skin (the folder that contains skin.ini).

#!/usr/bin/env python3
"""Parse skin.ini and check prefix / known-file references on disk."""
import sys
from pathlib import Path

PREFIX_KEYS = {
    "hitcircleprefix": "hit-circle digits",
    "scoreprefix": "score digits",
    "comboprefix": "combo counter",
}
KNOWN_STEMS = [
    "hitcircle",
    "hitcircleoverlay",
    "approachcircle",
    "cursor",
    "cursortrail",
    "sliderfollowcircle",
    "sliderscorepoint",
    "reversearrow",
    "scorebar-bg",
    "scorebar-colour",
]


def parse_ini(path: Path):
    sections = []
    current = ("(preamble)", [])
    sections.append(current)
    for raw in path.read_text(errors="replace").splitlines():
        line = raw.split("//", 1)[0].strip()
        if not line:
            continue
        if line.startswith("[") and line.endswith("]"):
            current = (line[1:-1], [])
            sections.append(current)
            continue
        if ":" in line:
            key, val = line.split(":", 1)
            current[1].append((key.strip(), val.strip()))
    return sections


def exists_any(root: Path, stem: str):
    found = []
    for name in (
        stem + ".png",
        stem + "@2x.png",
        stem + "-0.png",
        stem + "-0@2x.png",
    ):
        if (root / name).is_file():
            found.append(name)
    return found


def check_prefix(root: Path, prefix: str):
    missing = []
    for i in range(10):
        sd = prefix + "-" + str(i) + ".png"
        hd = prefix + "-" + str(i) + "@2x.png"
        if not (root / sd).is_file() and not (root / hd).is_file():
            missing.append(sd + " (and no @2x)")
    return missing


def main():
    root = Path(sys.argv[1] if len(sys.argv) > 1 else ".").expanduser()
    ini = root / "skin.ini"
    print("skin:", root.resolve())
    if not ini.is_file():
        print("No skin.ini in that folder.")
        return
    sections = parse_ini(ini)
    prefixes = {}
    for name, keys in sections:
        print("[" + name + "]", len(keys), "keys")
        for k, v in keys:
            print("  " + k + ": " + v)
            if k.lower() in PREFIX_KEYS:
                prefixes[k.lower()] = v
    print("--- file checks ---")
    for key, label in PREFIX_KEYS.items():
        prefix = prefixes.get(key, None)
        if not prefix:
            print(label + ": prefix not set (engine default will be used)")
            continue
        missing = check_prefix(root, prefix)
        if missing:
            print(label + " prefix " + repr(prefix) + ": missing " + ", ".join(missing))
        else:
            print(label + " prefix " + repr(prefix) + ": 0-9 present")
    for stem in KNOWN_STEMS:
        found = exists_any(root, stem)
        print(stem + ": " + (", ".join(found) if found else "MISSING"))


if __name__ == "__main__":
    main()
Enter fullscreen mode Exit fullscreen mode

What it checked on a sample folder

I ran the script on a temporary folder that contained a minimal skin.ini (HitCirclePrefix: default, ScorePrefix: score, ComboPrefix: combo), digits default-0.png through default-9.png, score-0.png through score-9.png, combo-0.png only (no 1–9), plus hitcircle.png and approachcircle.png. Cursor and slider files were left out on purpose.

The output reported the three sections as parsed, marked the combo prefix as missing combo-1.png through combo-9.png, listed hitcircle and approachcircle as present, and listed cursor, cursortrail, sliderfollowcircle, sliderscorepoint, reversearrow and the scorebar stems as MISSING. That is the kind of report you want before you pack an .osk: the ini is valid, but the folder is not complete.

How to use it

Copy the script, make it executable if you like, and run:

python3 check_skin_ini.py /path/to/YourSkin
Enter fullscreen mode Exit fullscreen mode

It does not try to be a full linter (the osu-skin-lint notes and the skins on osuskins.org cover a lot more). It only answers two questions: what did the ini actually set, and do the prefix digits and a handful of core PNGs exist on disk? If a key is set and the files are missing, fix that before you upload.

Top comments (0)