-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautodl.py
41 lines (35 loc) · 1.16 KB
/
autodl.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
from pyperclip import paste
from waiting import wait
from re import findall
import subprocess
import requests
s = paste()
def get_filename_from_cd(cd):
if not cd:
return None
fname = findall('filename=(.+)', cd)
if len(fname) == 0:
return None
name = fname[0].maketrans('"/\:*?<>|', ' ')
return fname[0].translate(name)
def main(mapid):
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, 'wb').write(r.content)
subprocess.call(f'start "" "{filename}"', shell=True)
def getid(url):
mapid = ''
for i in url[31:]:
if i.isdigit(): mapid += i
else: return mapid
def check():
global s
if s != paste():
s = paste()
if s.startswith('https://osu.ppy.sh/beatmapset'):
main(getid(s))
if s.startswith('https://osu.ppy.sh/b/') or s.startswith('https://osu.ppy.sh/beatmaps'):
resp = requests.Session().head(s, allow_redirects=True)
main(getid(resp.url))
wait(check)