From 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 13 Apr 2025 18:48:02 +0100 Subject: initial --- site/sound/refresh_map.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 site/sound/refresh_map.py (limited to 'site/sound/refresh_map.py') diff --git a/site/sound/refresh_map.py b/site/sound/refresh_map.py new file mode 100644 index 0000000..74b9dff --- /dev/null +++ b/site/sound/refresh_map.py @@ -0,0 +1,31 @@ +import json +import os +import re + +base_url = "/sound" + +def refresh(): + items = dict() + for item in os.listdir("."): + if os.path.isdir(item): + sounds = list() + first = True + coltype = "generic" + for sound in os.listdir(item): + if os.path.splitext(sound)[1].lower() == ".mp3": + if first: + first = False + if re.search(r"[0-9]{2}.[0-9].mp3", sound): + coltype = "melsys" + soundobj = {"path": os.path.join(base_url, item, sound)} + if coltype == "melsys": + soundobj["note"] = int(re.match(r"([0-9]{2}).[0-9].mp3", sound).group(1)) + sounds.append(soundobj) + items[item] = {"type": coltype, "sounds": sounds} + + with open("map.json", "w") as f: + json.dump(items, f) + +if __name__ == "__main__": + refresh() + -- cgit v1.2.3