-
Notifications
You must be signed in to change notification settings - Fork 1
/
sharedrive_dl.py
87 lines (67 loc) · 2.76 KB
/
sharedrive_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
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
import requests
from urllib.parse import urlparse
link = "" #file url
'''
NOTE:
DO NOT use the logout button on website. Instead, clear the site cookies manually to log out.
If you use logout from website, cookies will become invalid. This cookie will be expired automatically after
a month, so you will need to regrenerate cookie every month.
'''
PHPCKS = ""
#=====================================================================================================================================================================
def shareDrive(url,directLogin=True):
successMsgs = ['success', 'Success', 'SUCCESS']
scrapper = requests.Session()
#retrieving session PHPSESSID
cook = scrapper.get(url)
cookies = cook.cookies.get_dict()
PHPSESSID = cookies['PHPSESSID']
headers = {
'authority' : urlparse(url).netloc,
'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin' : f'https://{urlparse(url).netloc}/',
'referer' : url,
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.35',
'X-Requested-With ' : 'XMLHttpRequest'
}
if directLogin==True:
cookies = {
'PHPSESSID' : PHPSESSID
}
data = {
'id' : url.rsplit('/',1)[1],
'key' : 'direct'
}
else:
cookies = {
'PHPSESSID' : PHPSESSID,
'PHPCKS' : PHPCKS
}
data = {
'id' : url.rsplit('/',1)[1],
'key' : 'original'
}
resp = scrapper.post(f'https://{urlparse(url).netloc}/post', headers=headers, data=data, cookies=cookies)
toJson = resp.json()
if directLogin==True:
if toJson['message'] in successMsgs:
driveUrl = toJson['redirect']
return driveUrl
else:
if len(PHPCKS)>0:
shareDrive(url,directLogin=False)
else:
raise Exception("Unable to retrieve link using Direct Login and You haven't provided 'PHPCKS' var")
else:
if toJson['message'] in successMsgs:
driveUrl = toJson['redirect']
return driveUrl
else:
raise Exception(toJson['message'])
gDriveURL = shareDrive(link)
print(gDriveURL)
#==============================================================================================================================================================
''' Sample Output of respone json file
{'error': '0', 'message': 'Success', 'redirect': 'https://drive.google.com/uc?id=1l_CLYBX2tdhtrhrt1eQhiaJjMvyw7Yb'}
*NOTE: This Script by default returns Google Drive URL, json response sample is provided only for knowledge purpose.
'''