-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
157 lines (129 loc) · 5.35 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
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
import requests
import random
import os, sys, subprocess
import shutil
import colorama
from colorama import Fore, init
colorama.init()
def clear_console():
if sys.platform.startswith('win'):
_ = subprocess.call('cls', shell=True)
elif sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
_ = subprocess.call('clear', shell=True)
else:
print('Unsupported platform. Cannot clear console.')
def set_terminal_title(title):
if sys.platform.startswith('linux'):
sys.stdout.write(f"\x1b]2;{title}\x07")
elif sys.platform.startswith('darwin'):
sys.stdout.write(f"\033]0;{title}\007")
elif sys.platform.startswith('win'):
import ctypes
ctypes.windll.kernel32.SetConsoleTitleW(title)
else:
raise ValueError("Unsupported platform")
def print_centered(text):
console_width, _ = shutil.get_terminal_size()
padding = (console_width - len(text)) // 2
print(' ' * padding + text)
def input_centered(prompt):
console_width, _ = shutil.get_terminal_size()
prompt_lines = prompt.split('\n')
padding = (console_width - max(len(line) for line in prompt_lines)) // 2
centered_prompt = '\n'.join(' ' * padding + line for line in prompt_lines)
user_input = input(centered_prompt)
return user_input
Red = Fore.RED
Blue = Fore.BLUE
Green = Fore.GREEN
Yellow = Fore.YELLOW
Reset = Fore.RESET
Debug = ''
def end():
clear_console()
Choice = input_centered(f'''{Green}Installed{Reset}, Do you want to {Green}import{Reset} all the maps on {Green}Osu!{Reset} ?
[{Green}1{Reset}] {Green}Yes{Reset} ({Green}Will{Reset} import and after that Quit)({Red}Epileptical{Reset} warning)
[{Green}2{Reset}] {Green}No{Reset} ({Green}Quit{Reset})
->''')
if Choice == '1':
Launch()
quit()
else:
quit()
def Launch():
files = os.listdir('OsuSong')
files.sort(key=lambda x: os.path.getmtime(os.path.join('OsuSong', x)), reverse=True)
for file in files:
file_path = os.path.join('OsuSong', file)
os.startfile(file_path)
print(f'{Green}Started{Reset} {file_path}')
def main():
if not os.path.exists('OsuSong'):
os.makedirs('OsuSong')
print_centered(f'{Red}Warning{Reset}, Because of downloading random map, it may be able to download very {Red}bad{Reset} song with ({Red}P*rn{Reset}, {Red}Horror{Reset} and other Be {Red}AWARE{Reset}')
min_star = float(input_centered(f'Enter the minimum {Yellow}star{Reset} rating: '))
max_star = float(input_centered(f'Enter the maximum {Yellow}star{Reset} rating: '))
First = int(input_centered(f'How many songs do you want to {Yellow}download?{Reset} '))
Debug = input_centered(f"""Do you want to get more {Yellow}information{Reset} (Beatmaps that's are not downloaded and some other stuff\n
[{Yellow}1{Reset}] {Yellow}Yes{Reset}
[{Yellow}2{Reset}] {Yellow}No {Reset}
->""")
if Debug == '1':
Debug = 'True'
else: Debug = 'False'
Debug2 = ''
if Debug == 'True':
Debug2 = f"{Green}True"
else:
Debug2 = f"{Red}False"
clear_console()
print(f'Minimun {Yellow}star{Reset} : {Green}{min_star}{Reset}')
print(f'Minimun {Yellow}star{Reset} : {Green}{max_star}{Reset}')
print(f'Debug {Yellow}Mode{Reset} : {Debug2}\n\n')
print_centered(f'{Yellow}Downloading{Reset}, please be {Yellow}patient{Reset} (This can take {Yellow}some{Reset} time)\n')
Second = 0
while True:
if First == Second:
end()
else:
pass
random_number = str(random.randint(1, 200000))
url = f"https://api.chimu.moe/v1/download/{random_number}?n=1"
if Debug == 'True':
print_centered(f'{Green}Generating{Reset} new link...')
beatmap_url = f"https://api.chimu.moe/v1/map/{random_number}"
response = requests.get(beatmap_url)
if Debug == 'True':
print_centered(f'Checking the {Green}Chimu-Moe API{Reset} if the map exist..')
try:
data = response.json()
star_rating = data["DifficultyRating"]
song_name = data["OsuFile"]
except KeyError:
continue
if star_rating < min_star or star_rating > max_star:
continue
song_name = song_name.replace(".", "_")
star_rating = f"{star_rating}".replace(".","")
# Check if file already exists
filename1 = f"{star_rating} TheCuteOwl-Github {song_name}.osz"
if os.path.isfile(os.path.join('OsuSong', filename1)):
continue
try:
response = requests.get(url, stream=True)
response.raise_for_status()
filename2 = os.path.join('OsuSong', filename1)
with open(filename2, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
if Debug == 'True':
print_centered(f'{Green}Map founded{Reset}...')
print_centered(f"{Yellow}Downloaded:{Reset} {filename1} in {Yellow}OsuSong Folder{Reset}")
Second += 1
if Debug == 'True':
print_centered(f'{Green}{Second}/{First} Downloaded{Reset}...')
except:
pass
if __name__ == '__main__':
main()