-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
81 lines (63 loc) · 2.33 KB
/
main.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
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
# load modules
import asyncio
import json
import os
import BSAPI.beatsaver as beatsaver
import pandas as pd
from version import VERSION
os.environ['USER_AGENT'] = f'{VERSION} (+contact twitter/@aruru_bs discord/あるる#1137)'
async def main():
rate_criteria = [
[0, 0.1],
[0.1, 0.15]
]
for minRating, maxRating in rate_criteria:
# init
page = 0
IDs = []
songs = []
while (True):
# increment
page += 1
print(
f'minRating={int(minRating*100)}%, maxRating={int(maxRating*100)}%, page={page:03}')
# get ranked maplist
searchResponse = await beatsaver.search_maps(minRating=minRating, maxRating=maxRating, page=page)
# set songs
if searchResponse is not None:
if (searchResponse.docs is not None) and len(searchResponse.docs) > 0:
# get
IDs += [x.id for x in searchResponse.docs]
songs += [{
"songName": x.metadata.songName,
"levelAuthorName": x.metadata.levelAuthorName,
"hash": x.versions[0].hash,
"levelid": f"custom_level_{x.versions[0].hash}"
} for x in searchResponse.docs]
else:
break
else:
break
await asyncio.sleep(1/200)
# del duplicated element
slct_index = [not b for b in list(pd.Index(IDs).duplicated())]
songs = [e for e, i in zip(songs, slct_index) if i]
# read image
with open('imgs/u20.txt', 'r') as f:
img = f.read()
# gen playlist
fname = f'rating-{int(minRating*100)}percent-to-{int(maxRating*100)}percent-playlist.bplist'
playlist = {
"customData": {
"syncURL": f"https://github.com/jundoll/bs-bad-rating-playlist/releases/latest/download/{fname}"
},
"playlistTitle": f'rating-{int(minRating*100)}percent-to-{int(maxRating*100)}percent',
"playlistAuthor": "",
"songs": songs,
#"image": img
}
# save
with open(f'out/{fname}', 'w') as f:
json.dump(playlist, f)
if __name__ == '__main__':
asyncio.run(main())