-
Notifications
You must be signed in to change notification settings - Fork 0
/
osu-lazer-export.py
46 lines (37 loc) · 1.27 KB
/
osu-lazer-export.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import json
import subprocess
import osu
# set your osu-lazer/files folder
PARENT_DIR = os.path.abspath("../")
DOWNLOAD_DIR = os.path.abspath("../../Songs")
osu_beatmaps = {}
def get_files(path):
for item in os.listdir(path):
sub = os.path.join(path, f"{item}")
if os.path.isdir(sub):
get_files(sub)
else:
file_handler(sub)
def file_handler(file_path):
print(f"Handling {file_path}")
try:
beatmap = osu.OSUFile(file_path)
except ValueError:
print("Not a beatmap.")
return
except UnicodeDecodeError:
print("Not a text file.")
return
else:
if beatmap.Metadata["BeatmapSetID"] in osu_beatmaps.keys():
osu_beatmaps[beatmap.Metadata["BeatmapSetID"]].append(beatmap.Metadata["BeatmapID"])
else:
osu_beatmaps[beatmap.Metadata["BeatmapSetID"]] = [beatmap.Metadata["BeatmapID"]]
subprocess.run(
["wget", "-O", f"{DOWNLOAD_DIR}/{beatmap.Metadata["BeatmapSetID"]}.osz",
f"https://txy1.sayobot.cn/beatmaps/download/full/{beatmap.Metadata["BeatmapSetID"]}?server=auto"],
stdout=subprocess.PIPE)
get_files(PARENT_DIR)
with open("beatmaps", "w") as f:
json.dump(osu_beatmaps, f)