-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
182 lines (155 loc) · 5.99 KB
/
index.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html>
<!-- https://github.com/iodide-project/pyodide/issues/679#issuecomment-637519913 -->
<head>
<script type="text/javascript">window.languagePluginUrl = 'https://cdn.jsdelivr.net/pyodide/v0.16.1/full/pyodide.js';</script>
<script src="https://cdn.jsdelivr.net/pyodide/v0.16.1/full/pyodide.js"></script>
</head>
<body>
<p>Osu stream map detector, drag and drop .osu beatmap to Browse... button , or click to select manually </p>
<p>------</p>
<input type="file" onchange="doit();" id="file">
<div id = "result_id"> </div>
<script type="text/javascript">
var content = null;
function doit() {
var file = document.getElementById("file").files[0];
var reader = new FileReader();
reader.readAsText(file);
reader.onload = evt => {
content = evt.target.result;
pyodide.runPython(`
import operator
from js import content
from js import result_id
min_bpm = 140
max_bpm = 9999
def adjust_beat_length(beat_length, new_bpm):
current_bpm = new_bpm
whole = beat_length
half = whole / 2
quarter = half / 2
return current_bpm, whole, half, quarter
def _check(of, min_bpm=min_bpm, max_bpm=max_bpm):
raw_map = of.splitlines()
if raw_map[0] != "osu file format v14":
return False
timing_points_index = raw_map.index("[TimingPoints]")
objects_index = raw_map.index("[HitObjects]")
metadata_index = raw_map.index("[Metadata]")
beatmap = {
"bpm": {"default": {"time": 0, "bpm": 0, "beatLength": 0}, "changes": []}
}
for i in range(metadata_index + 1, len(raw_map)):
if raw_map[i] == '':
break
if raw_map[i].startswith("Title:"):
beatmap["title"] = raw_map[i][6:-1]
if raw_map[i].startswith("Artist:"):
beatmap["artist"] = raw_map[i][7:-1]
if raw_map[i].startswith("Version:"):
beatmap["difficulty"] = raw_map[i][8:-1]
# Determine BPM and BPM changes
for i in range(timing_points_index + 1, len(raw_map)):
if raw_map[i] == '':
break
point = raw_map[i].split(",")
time = int(float(point[0]))
beatLength = float(point[1])
if beatLength > 0:
default_bpm = beatmap["bpm"]["default"]
bpm = str(int(60000 // beatLength))
if default_bpm["bpm"] == 0:
default_bpm["time"] = time
default_bpm["bpm"] = bpm
default_bpm["beatLength"] = beatLength
else:
beatmap["bpm"]["changes"].append(
{"time": time, "bpm": bpm, "beatLength": beatLength}
)
first_object = objects_index + 1
previous_object = {"time": 0, "x": 0, "y": 0}
current_bpm = beatmap["bpm"]["default"]["bpm"]
whole = beatmap["bpm"]["default"]["beatLength"]
half = whole / 2
quarter = half / 2
quarter_note_count = 1
note_start_time = 0
burst_count = 0
stream_count = {}
total_stream_notes = 0
longest_stream = 0
for i in range(first_object, len(raw_map)):
raw_hit_object = raw_map[i].split(",")
if i != len(raw_map) - 1:
next_raw_hit_object = raw_map[i + 1].split(",")
else:
next_raw_hit_object = "000"
hit_object = {
"time": int(raw_hit_object[2]),
"x": int(raw_hit_object[0]),
"y": int(raw_hit_object[1]),
}
changes = beatmap["bpm"]["changes"]
for change in changes:
time_change = change["time"]
new_beatlength = change["beatLength"]
new_bpm = change["bpm"]
if time_change < previous_object["time"]:
continue
elif hit_object["time"] >= time_change:
current_bpm, whole, half, quarter = adjust_beat_length(
new_beatlength, new_bpm
)
break
# Determine if quarter length
if i != first_object:
time_difference = hit_object["time"] - previous_object["time"]
if quarter - 2 < time_difference < quarter + 2:
quarter_note_count += 1
if note_start_time == 0:
note_start_time = hit_object["time"]
else:
# Declare if stream
if 3 < quarter_note_count < 6:
burst_count += 1
total_stream_notes += quarter_note_count
elif quarter_note_count >= 6:
if current_bpm in stream_count:
stream_count[current_bpm] += 1
else:
stream_count[current_bpm] = 1
total_stream_notes += quarter_note_count
if quarter_note_count > longest_stream:
longest_stream = quarter_note_count
quarter_note_count = 1
note_start_time = 0
previous_object = hit_object
if len(stream_count) > 0:
main_bpm = int(max(stream_count.items(), key=operator.itemgetter(1))[0])
else:
main_bpm = int(beatmap["bpm"]["default"]["bpm"])
total_streams = 0
for bpm in stream_count:
total_streams += stream_count[bpm]
total_object_count = len(raw_map) - first_object
try:
stream_percentage = total_stream_notes / total_object_count * 100
except ZeroDivisionError:
stream_percentage = 0
if stream_percentage >= 25 and main_bpm >= min_bpm and main_bpm <= max_bpm:
result = f'{beatmap["artist"]} - {beatmap["title"]} [{beatmap["difficulty"]}] | Main BPM: {main_bpm} | Total Streams: {total_streams} ({int(stream_percentage)}% Streams)'
return result
return False
r = _check(content)
if r:
print(r)
result_id.innerHTML = r
else:
result_id.innerHTML = 'ERROR'
`);}}
languagePluginLoader.then(function () {
console.log('Ready');
});
</script>
</body>