# Instagram Reel Transcription — Research & Next Steps

**Goal:** When James shares an Instagram reel URL, batch-process it overnight into a transcript that feeds the wiki ingestion pipeline — cheaply and reliably.

---

## The core problem: audio extraction

The transcript pipeline has two stages: (1) get the audio out of Instagram, (2) convert audio → text. Stage 1 is the hard part.

### Why yt-dlp alone won't cut it
yt-dlp can theoretically extract Instagram audio but is unreliable in practice — Instagram changes their protection mechanisms frequently, it requires live browser cookies, and it gets rate-blocked in batch pipelines. Not suitable as a primary approach.

### Better extraction options

**Option A: agent-browser (recommended)**
Vercel Labs' `agent-browser` is a Rust CLI browser automation tool built for AI agent workflows. It controls Chrome via CDP, supports JS-heavy pages, and has a built-in credential vault for handling logins. For Instagram:
- Navigate to the reel page (logged-in session via credential vault)
- Extract the video/audio source URL from the accessibility tree or network interception (HAR recording feature)
- Download audio directly
- No per-command Node.js startup overhead — batch-friendly

Cost: free (after install). Requires a personal Instagram session stored in agent-browser's encrypted credential vault.

See: [[Agent Browser]] wiki page.

**Option B: Apify Instagram scraper**
Paid API service (~$0.005/query) that handles Instagram auth and returns media URLs. No setup, fully managed. Good fallback if agent-browser becomes unreliable.

**Option C: yt-dlp + browser cookies (fallback)**
```bash
yt-dlp --extract-audio --audio-format mp3 \
  --cookies-from-browser firefox \
  https://www.instagram.com/reel/XXXXX/
```
Brittle. Use only if other options fail.

---

## Stage 2: Audio → Transcript

**Recommended: OpenAI gpt-4o-mini-transcribe**
- $0.003/minute
- A 60-second reel = ~$0.003
- 100 reels/month = ~$0.30

```bash
curl https://api.openai.com/v1/audio/transcriptions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -F "file=@audio.mp3" \
  -F "model=gpt-4o-mini-transcribe"
```

Alternative: **local faster-whisper** (free after setup, needs GPU for speed). Only worth it at >1,000 reels/month.

**AssemblyAI / Deepgram:** More expensive for basic transcription. Skip unless speaker diarization is needed.

---

## Recommended pipeline

```
[James sends reel URL]
        ↓
[Queue to ingest-queue.md with source URL + context note]
        ↓
[Overnight batch task fires]
        ↓
[agent-browser navigates to reel, extracts audio URL]
        ↓
[yt-dlp or curl downloads audio as .mp3]
        ↓
[OpenAI gpt-4o-mini-transcribe → transcript text]
        ↓
[Nano reads transcript + James's context note → writes wiki pages]
        ↓
[Sends James summary in morning]
```

**Estimated cost per reel:** ~$0.003–$0.008 (transcription + possible Apify fallback)
**Estimated cost per month (10 reels):** < $0.10

---

## Next steps

1. **[ ] Install agent-browser** — `npm install -g agent-browser && agent-browser install`
   - Store Instagram credentials in agent-browser's encrypted vault
   - Test navigating to a reel and extracting the audio URL

2. **[ ] Write the extraction script** — `/workspace/agent/scripts/extract-reel-audio.sh`
   - Input: Instagram reel URL
   - Output: `.mp3` file path

3. **[ ] Write the transcription script** — `/workspace/agent/scripts/transcribe-audio.sh`
   - Input: `.mp3` file path
   - Output: transcript `.txt` file

4. **[ ] Wire into overnight ingest task** — modify the scheduled task prompt to:
   - Check ingest-queue.md for reel URLs
   - Run extraction + transcription scripts before calling Nano
   - Pass transcript as context alongside the URL

5. **[ ] Test end-to-end** with the existing reel: https://www.instagram.com/reel/DYAnUJCpCep/

---

## Open questions
- Does James want to store his Instagram session in agent-browser's credential vault on his local machine, or run this pipeline in the NanoClaw container? (Container approach would need credentials provisioned separately.)
- Is OpenAI API access already available via the OneCLI gateway, or does it need to be connected?
