# Google Drive folder batch transcription

Use when the user sends a public Google Drive folder containing one or more audio/video files.

## Pattern

1. Create a dedicated job directory, with separate `downloads/`, `out/`, and final media-cache directories.
2. Download the folder with `gdown --folder` when available:

```bash
python3 -m venv /path/to/job/venv
/path/to/job/venv/bin/python -m pip install --quiet gdown
/path/to/job/venv/bin/python -m gdown --folder 'DRIVE_FOLDER_URL' -O /path/to/job/downloads
```

If the active Hermes runtime venv has no `pip`, create a throwaway task venv as above rather than changing the Hermes runtime environment.

2. Verify each downloaded file individually. For a long strategic/research corpus, also write an inventory manifest (filename, duration, size, format) before ASR so later progress can be measured in audio-hours rather than file count alone:

```bash
python3 - <<'PY'
import subprocess, pathlib
for p in pathlib.Path('/path/to/job/downloads').glob('*'):
    if p.is_file():
        print('\n###', p.name)
        print(subprocess.check_output([
            'ffprobe','-v','error',
            '-show_entries','format=duration,size,format_name:stream=codec_name,channels,sample_rate',
            '-of','json',str(p)
        ], text=True))
PY
```

Do not pass multiple media files to one `ffprobe` command; it treats extra paths as conflicting input arguments.

4. Transcribe all files sequentially in a tracked background process:

```bash
OUT=/path/to/job/out
mkdir -p "$OUT"
PY=/usr/local/lib/hermes-agent/venv/bin/python
SCRIPT=/home/spazio/.hermes/skills/media/audio-transcription/scripts/transcribe_with_faster_whisper.py
for f in /path/to/job/downloads/*; do
  [ -f "$f" ] || continue
  echo "=== TRANSCRIBING: $f ==="
  "$PY" "$SCRIPT" "$f" --language ru --model small --outdir "$OUT"
done
```

Start this via `terminal(background=true, notify_on_complete=true)` for long batches.

5. For long batches, verify completion mechanically after the worker exits: compare each source duration from `ffprobe` with the final SRT end timestamp, allow only a short trailing-silence gap, and write a manifest containing duration, final timestamp, gap, TXT/SRT sizes and pass/fail. When the user asks for status before completion, inspect both process state and the active SRT’s final timestamp; report completed files, active-file percentage, processed/remaining audio-hours, and keep synthesis time separate from ASR time.
6. Copy `.txt` and `.srt` outputs into `~/.hermes/media/transcripts/<job>/` before delivering via `MEDIA:`.

## Notes

- Google Drive folders often preserve filenames with spaces or non-Latin characters; quote paths everywhere.
- A public folder may contain files larger than Telegram's Bot API limit; direct Drive download is still fine.
- Drive folders may contain mixed assets: large `.ogg` voice files plus Google Docs exported by `gdown` as `.docx`. Transcribe media and separately extract/read document text before doing the synthesis the user asked for.
- When the user asks for “dоsловная транскрибация”, deliver the raw timestamped transcripts first before summaries or cleanup.
