Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Data-Horde/gdrivac into main
Browse files Browse the repository at this point in the history
  • Loading branch information
madprogramer committed Sep 13, 2021
2 parents efbcce9 + 41e4510 commit 4eeb428
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions subscripts/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
class GDRIVAC_Exception(Exception): pass
class NAGDError(GDRIVAC_Exception): pass
class DoAError(GDRIVAC_Exception): pass
class InvalidURLError(GDRIVAC_Exception): pass
class FileUnavailableError(GDRIVAC_Exception): pass

#Singleton Class for checking cookie shapes
#TODO: Write functions to check different cookie shapes
Expand Down Expand Up @@ -85,13 +87,14 @@ def immunize(self,args,visit_queue, cookie_payload):
SAPISIDHASH = hashlib.sha1(SAPISIDHASH_tohash).digest().hex()
self.HEADERS["Authorization"] = "SAPISIDHASH " + SAPISIDHASH

#TODO: there might be more types of gdrive links
url_id_list = re.findall("id=([a-zA-Z0-9_-]*)|/folders/([a-zA-Z0-9_-]*)|/file/d/([a-zA-Z0-9_-]*)", URL)
url_id = None
for i in url_id_list[0]:
if i:
url_id = i
break
if match := re.search(r'(/folder/d/|/drive/(mobile/)?folders?/|folderview\?id=)(?P<id>[a-zA-Z0-9\-_]{7,70})', URL):
#Folders
url_id = f"{match.group('id')}"
elif match := re.search(r'(/file/d/|(uc|open|abuse|thumbnail|vt)\?(export=[a-z]+&)?id=)(?P<id>[a-zA-Z0-9\-_]{7,70})', URL):
#Files
url_id = f"{match.group('id')}"
else:
raise InvalidURLError
rq_url = f"https://clients6.google.com/drive/v2internal/files/{url_id}?fields=id%2Ckind,resourceKey,lastViewedByMeDate&modifiedDateBehavior=NO_CHANGE&supportsTeamDrives=true&enforceSingleParent=true&key=AIzaSyDVQw45DwoYh632gvsP5vPDqEKvb-Ywnb8"

r = requests.put(rq_url,stream=True,cookies=cookie_payload, headers=self.HEADERS)
Expand All @@ -108,6 +111,8 @@ def immunize(self,args,visit_queue, cookie_payload):
#print(r.text)
#CHECK IF non-200 status
if r.status_code < 200 or r.status_code >= 300:
if r.status_code in [404, 403]:
raise FileUnavailableError
with self.print_lock: log("\033[94mRequeuing...\033[0m")
self.visit_queue.put(URL)
continue
Expand All @@ -126,9 +131,13 @@ def immunize(self,args,visit_queue, cookie_payload):
raise NAGDError("\033[91mERROR: '{}' is not a Google Drive file URL!\nPass -ignoreNonDrive flag to ignore\033[0m".format(URL))

#If the URL is invalid
except requests.exceptions.MissingSchema:
except (requests.exceptions.MissingSchema, InvalidURLError):
with self.print_lock: log("\033[91mERROR: '{}' is not a properly formatted URL!\033[0m".format(URL))
#Do NOT add back into the queue
#If the status is 404 or 403
except FileUnavailableError:
with self.print_lock: log("\033[91mERROR: '{}' is not available!\033[0m".format(URL))
#Do NOT add back into the queue
#If the Connection is DEAD
except requests.exceptions.ConnectionError:
with self.print_lock: log("\033[91mERROR: No Connection\n\033[94mRequeuing {}\033[0m".format(URL))
Expand Down

0 comments on commit 4eeb428

Please sign in to comment.