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()