-
Notifications
You must be signed in to change notification settings - Fork 1
/
gdrivac.py
123 lines (97 loc) · 5.05 KB
/
gdrivac.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
try:
import requests, argparse, os, json, random, time, datetime, re
except:
print("Hmm... import error. Did you remember to run\n$pip install -r requirements.txt")
#Internal Imports
from subscripts.classes import *
def timeRemaining():
DEADLINE = datetime.datetime(year=2021,month=9,day=13)
if datetime.datetime.now() > DEADLINE:
return "ANY MINUTE NOW"
else:
diff = DEADLINE - datetime.datetime.now()
return str(diff.days) + " days, " + str(diff.seconds//3600) + " hours, " + str((diff.seconds%3600)//60) + " minutes"
def main():
#CONSTANTS
COOKIEFILE = 'cookies.json'
IA = InteractiveAsker()
IM = Immmunizer()
CC = CookieChecker()
HELLOMESSAGE = "\033[93mWelcome to Google-Drivac!\nStarting up...\n\033[90m" + "\033[94mARCHIVE TEAM NEEDS YOU! \nPLEASE VISIT \nhttps://datahorde.org/help-archive-team-archive-public-google-drive-files-before-september-13/\n\033[90m"+random.choice([
"TIP: \033[93mGoogle Docs, Sheets, and Slides files are NOT impacted by the security update\033[90m",
"TIP: \033[93mYou can pass multiple .txt files to GDrivac with\n\033[92m$ gdrivac.py -f file1.txt file2.txt\033[90m",
"TIP: \033[93mYou can export your browser cookies as cookies.json into the gdrivac folder.\033[90m",
"TIP: \033[93mResource Keys for links you collect are logged to resourceKeys.log. Neato ain't it?\033[90m",
"TIP: \033[91mApproximate time remaining until September 13:\n{}\033[90m".format(timeRemaining()),
])
#PARSE ARGUMENTS
parser = argparse.ArgumentParser(description="""Google-Drivac: Vaccinate Against Link Rot!
On Sep 13 2021, Google Drive will forcibly private a lot of publicly shared URLs, details are available here:
https://workspaceupdates.googleblog.com/2021/06/drive-file-link-updates.html
Important Note: Google Docs, Sheets, and Slides files are NOT impacted by this change, see https://support.google.com/a/answer/10685032
Luckily, if you access a shared link before that date, your Google account will be able to continue accessing it after the deadline.
Google-Drivac is a tool to associate a Google account with a list of Google Drive links.
Install requirements with $pip install -r requirements.txt
""")
#ALLOW FOR MULTIPLE URLs
parser.add_argument("-url",nargs='+',type=str,help="Google Drive URL(s) to immunize against.\nMultiple URLs can be specified in succession.")
parser.add_argument("-files",nargs='+',type=str,help="Files with Drive URL(s) to immunize against.\nMultiple files can be specified in succession.\nSupported Formats:\n*.txt seperated by newlines.TBA")
parser.add_argument("-sid",type=str,help="Specify cookie value for SID")
parser.add_argument("-ssid",type=str,help="Specify cookie value for SSID")
parser.add_argument("-hsid",type=str,help="Specify cookie value for HSID")
parser.add_argument("-sapisid",type=str,help="Specify cookie value for SAPISID")
parser.add_argument("-apisid",type=str,help="Specify cookie value for APISID")
parser.add_argument("-tcount",type=int,help="Thread count (default = 6)")
parser.add_argument("-ignoreNonDrive",type=int,default=0,help="Requeue non-Google Drive URLs if a failure occurs. Not recommended unless you are repurposing the script.")
parser.add_argument("-dontCollectKeys",type=int,default=0,help="Set to non-zero to disable resource key extraction.")
args = parser.parse_args()
#UNPARSE
files = (args.files or [])
URLs = (args.url or [])
for file in files:
if file[-4:] == '.txt':
with open(file, 'r') as cookiefile:
nextline = cookiefile.readline()
while nextline:
URLs.append(nextline.strip())
nextline = cookiefile.readline()
#COOKIE PAYLOAD
if not os.path.exists(COOKIEFILE):
with open(COOKIEFILE, 'w') as cookiefile:
cookiefile.write('{}')
#Read Cookies
cookie_payload = {}
try:
with open(COOKIEFILE, 'r') as cookiefile:
cookie_payload = json.load(cookiefile)
except:
print("{} is corrupted, resetting cookie payload".format(COOKIEFILE))
#Update Session Cookies
if args.sid: cookie_payload['SID'] = args.sid
if args.ssid: cookie_payload['SSID'] = args.ssid
if args.hsid: cookie_payload['HSID'] = args.hsid
if args.hsid: cookie_payload['SAPISID'] = args.sapisid
if args.hsid: cookie_payload['APISID'] = args.apisid
#Check and ask interactively for MISSING user session cookies
if not cookie_payload.get('SID'): cookie_payload['SID']= IA.askFor('SID')
if not cookie_payload.get('SSID'): cookie_payload['SSID'] = IA.askFor('SSID')
if not cookie_payload.get('HSID'): cookie_payload['HSID'] = IA.askFor('HSID')
if not cookie_payload.get('SAPISID'): cookie_payload['SAPISID'] = IA.askFor('SAPISID')
if not cookie_payload.get('APISID'): cookie_payload['APISID'] = IA.askFor('APISID')
#TODO: Check for cookies shape using CookieChecker CC
#CC.()
#Save cookies file
with open(COOKIEFILE, "w") as cookiefile:
json.dump(cookie_payload, cookiefile)
#print(args.sid, args.ssid, args.hsid)
#print (cookie_payload)
#SHOW TODAY'S HELLO MESSAGE
print(HELLOMESSAGE)
time.sleep(5)
#GET IMMUNIZED
if len(URLs):
IM.request(args,URLs,cookie_payload)
else:
print("\033[91mNo URLs provided.\nStopped.\033[0m")
if __name__ == '__main__':
main()