def download_file(service, fileid, filetypes, outp, test=False):
    """
    https://developers.google.com/drive/api/v3/ref-export-formats
    """
    from googleapiclient.http import MediaIoBaseDownload
    from os import makedirs
    from os.path import dirname
    import io
    for mimeType in filetypes:
        request = service.files().export_media(fileId=fileid, mimeType=mimeType
            )
        outp_ = (outp if '.' in outp else
            f"{outp}.{mimeType.split('/')[1].split('+')[0]}")
        makedirs(dirname(outp), exist_ok=True)
        fh = io.FileIO(file=outp_, mode='w')
        downloader = MediaIoBaseDownload(fh, request)
        done = False
        while done is False:
            status, done = downloader.next_chunk()
            if test:
                print(f'Downloading {outp_}: {int(status.progress() * 100)}')
