-
Notifications
You must be signed in to change notification settings - Fork 0
/
osuDownloader.py
51 lines (41 loc) · 1.49 KB
/
osuDownloader.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
from selenium import webdriver
import os
osu = "C:\\Users\\matia\\AppData\\Local\\osu!\\"
downloads = "C:\\Users\matia\Downloads\\"
driver = webdriver.Chrome()
driver.get("https://osu.ppy.sh")
songList = []
import re
def updateSongs():
global songList
regex = re.compile('^\d+')
l = filter(regex.match, os.listdir(osu+"Songs"))
songList = [int(x.split(" ")[0]) for x in l]
updateSongs()
def openFiles():
for osuFile in os.listdir(downloads):
if osuFile.endswith(".osz"):
os.startfile(downloads+osuFile)
updateSongs()
def download(x,check=False):
if x not in songList:
driver.get("https://osu.ppy.sh/beatmapsets?m=0&q="+str(x))
if check:
try:
driver.find_element_by_class_name('beatmapsets__empty')
except:
driver.get("https://osu.ppy.sh/beatmapsets/"+str(x)+"/download")
else:
driver.get("https://osu.ppy.sh/beatmapsets/"+str(x)+"/download")
def topRanks(num=10):
driver.get("https://osu.ppy.sh/beatmapsets?m=0")
while len(driver.find_elements_by_class_name('beatmapset-panel__header'))<num:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
l = [int(x.get_attribute("href")[len("https://osu.ppy.sh/beatmapsets/"):]) for x in driver.find_elements_by_class_name('beatmapset-panel__header')]
for x in l[:num]:
download(x)
openFiles()
if len(sys.argv)==2:
topRanks(int(sys.argv[1]))
else:
topRanks()