INNER CODE UNIT · Python
download_google_drive
GaParmar/clean-fid · cleanfid/downloads_helper.py:55
def download_google_drive(file_id, out_path):
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith("download_warning"):
return value
return None
URL = "https://drive.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params={"id": file_id}, stream=True)
token = get_confirm_token(response)
if token:
params = {"id": file_id, "confirm": token}
response = session.get(URL, params=params, stream=True)
CHUNK_SIZE = 32768
with open(out_path, "wb") as f: