-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhubdrive_dl.py
56 lines (39 loc) · 1.32 KB
/
hubdrive_dl.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
import re
import requests
from urllib.parse import urlparse
url = "" # hubdrive url
crypt = "" # crypt cookie
'''
NOTE: [UNSTABLE] Needs more exception handling -_-
'''
# ==================================
def parse_info(res):
info_parsed = {}
title = re.findall('>(.*?)<\/h4>', res.text)[0]
info_chunks = re.findall('>(.*?)<\/td>', res.text)
info_parsed['title'] = title
for i in range(0, len(info_chunks), 2):
info_parsed[info_chunks[i]] = info_chunks[i+1]
return info_parsed
def hubdrive_dl(url):
client = requests.Session()
client.cookies.update({'crypt': crypt})
res = client.get(url)
info_parsed = parse_info(res)
info_parsed['error'] = False
up = urlparse(url)
req_url = f"{up.scheme}://{up.netloc}/ajax.php?ajax=download"
file_id = url.split('/')[-1]
data = { 'id': file_id }
headers = {
'x-requested-with': 'XMLHttpRequest'
}
try:
res = client.post(req_url, headers=headers, data=data).json()['file']
except: return {'error': True, 'src_url': url}
gd_id = re.findall('gd=(.*)', res, re.DOTALL)[0]
info_parsed['gdrive_url'] = f"https://drive.google.com/open?id={gd_id}"
info_parsed['src_url'] = url
return info_parsed
# ==================================
print(hubdrive_dl(url))