-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosudl.py
66 lines (54 loc) · 1.31 KB
/
osudl.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
import tkinter as tk
import base64
import os
import subprocess
import requests
import re
def get_filename_from_cd(cd):
if not cd:
return None
fname = re.findall('filename=(.+)', cd)
if len(fname) == 0:
return None
return fname[0]
def main():
mapid = text.get('1.0', 'end')[:-1]
url = 'https://chimu.moe/d/' + mapid
r = requests.get(url, allow_redirects=True, stream=True)
filename = str(get_filename_from_cd(r.headers.get('content-disposition')))
open(filename.strip('"'), 'wb').write(r.content)
subprocess.call(f'start "" {filename}', shell=True)
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
window = tk.Tk()
window.iconbitmap(resource_path('icon.ico'))
window.geometry('100x100')
window.resizable(False, False)
window.title('chimudl')
window.configure(bg='grey')
message = tk.Label(
window,
text='Enter beatmap ID:'
)
message.pack()
text = tk.Text(
window,
height=1,
width=10
)
text.pack()
download = tk.Button(
window,
text='Download',
command=main
)
download.pack(
ipadx=5,
ipady=5,
expand=True
)
window.mainloop()