aboutsummaryrefslogtreecommitdiff
path: root/site/sound/refresh_map.py
blob: 74b9dff3f69911d41abbf172d4d2cc4ef1e1ad32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()