def METHOD_NAME(files: object, docid: str,
                 extension: str, mime_type: str,
                 output_dir: str) -> str:
    metadata = files.get(fileId=docid).execute()
    name = metadata['name']
    clean_name = re.sub('_-_', '-',
                        re.sub('_+', '_',
                               re.sub('[^A-Za-z0-9=-]', '_', name)))
    filename = path.join(output_dir, docid, '{}.{}'.format(clean_name, extension))
    os.makedirs(path.dirname(filename), exist_ok=True)
    if path.exists(filename) and path.getsize(filename):
        logging.warning("File already present: %s; skipping", filename)
        return filename
    try:
        with open(filename, 'wb') as outfile:
            exported = files.export(fileId=docid,
                                    mimeType=mime_type).execute()
            outfile.write(exported)
    except apiclient.errors.HttpError as exc:
        logging.error("Skipping; Error downloading: %s", exc)
        filename = None
    return filename