# Google Drive public download for audio transcription

Use this when a user sends a Google Drive `file/d/.../view` link to an audio/video file.

## Access check

A Drive link may be visible to the user but still private to the agent. Try the direct download endpoint; if the response is HTML from `accounts.google.com` or a sign-in page, the file is not public enough.

Ask the user to:

1. Open the file in Google Drive.
2. Click **Share / Поделиться**.
3. Set access to **Anyone with the link / Все, у кого есть ссылка**.
4. Set role to **Viewer / Читатель**.
5. Send the link again.

## Direct download pattern

Extract the file ID from:

```text
https://drive.google.com/file/d/FILE_ID/view?usp=...
```

Then request:

```text
https://drive.google.com/uc?export=download&id=FILE_ID
```

For large-file confirmation pages, carry cookies forward and retry with the `confirm` token / `uuid` parsed from the HTML form. Save the response only if the content type is not HTML or the HTML is known to be the confirmation page.

## Practical notes

- If the content type is `audio/mp4`, `audio/mpeg`, `video/mp4`, etc., stream to disk in chunks.
- Preserve the filename from `Content-Disposition` when present.
- After download, verify with `ffprobe` before transcribing.
- The original chat platform may have a 20 MB upload limit, but Drive direct download can handle larger files.
