Dev.to AI 🤖 Ai 👁 0 📖 3 min read

Get YouTube transcripts for hundreds of videos (for LLMs, search, or subtitles)

Transcripts are the cheapest way to turn video into something an LLM, a search index or a spreadsheet can use. For one video you can copy the transcript out of the YouTube UI. For a whole channel, you want a script. This

Transcripts are the cheapest way to turn video into something an LLM, a search index or a spreadsheet can use. For one video you can copy the transcript out of the YouTube UI. For a whole channel, you want a script. This post covers the free library route, why it often breaks at scale, and a managed alternative I built.

One video, for free

# pip install youtube-transcript-api
from youtube_transcript_api import YouTubeTranscriptApi

segments = YouTubeTranscriptApi().fetch("aircAruvnKk", languages=["en"])
text = " ".join(s.text for s in segments)
print(text[:300])

(The library's API has changed between versions; check its README for your version.) On your home connection this works for a handful of videos. Run it from a cloud server or in a loop over hundreds of videos and YouTube starts answering with "Sign in to confirm you're not a bot", because most datacenter IPs are challenged. The usual fix is a residential proxy, which is a cost and a setup of its own.

Many videos: the actor

My YouTube Transcript actor takes a list of video URLs or IDs and returns timestamped segments, full text or SRT, metadata and chapters. It uses Apify's residential proxy by default and retries a bot check on a new session up to three times.

No code: paste videos into videoUrls, set languages (priority list; manual captions are preferred over auto-generated), choose format (json, text or srt), Start, export.

Python:

# pip install apify-client
from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("bachiembmt/youtube-transcript-batch").call(run_input={
    "videoUrls": [
        "https://www.youtube.com/watch?v=aircAruvnKk",
        "https://youtu.be/9bZkp7q19f0",
        "dQw4w9WgXcQ",              # bare IDs work too
    ],
    "languages": ["en"],
    "format": "json",
    "includeChapters": True,
})
for v in client.dataset(run.default_dataset_id).iterate_items():
    if v["error"]:
        print("skip", v["videoId"], v["error"])
        continue
    print(v["title"], "-", v["channel"], f'({v["durationSec"]}s, {v["language"]})')
    print(v["fullText"][:200])

Output fields include videoId, title, channel, publishedAt, durationSec, language, isAutoGenerated, availableLanguages, segments (start, dur, text), fullText, srt, chapters and error.

Feeding an LLM: chunk by timestamp

The segments let you keep timestamps so answers can link back to the exact moment:

def chunks(v, size=60):
    buf, start = [], 0
    for s in v["segments"]:
        if s["start"] - start > size and buf:
            yield start, " ".join(buf); buf, start = [], s["start"]
        buf.append(s["text"])
    if buf: yield start, " ".join(buf)

for t, c in chunks(v):
    print(f'https://youtu.be/{v["videoId"]}?t={int(t)}', c[:80])

Embed each chunk and store the link as metadata; that is a minimal RAG index over a channel.

Honest limits

  • It only reads existing captions (manual or auto-generated). It does not do speech-to-text, so videos with no captions return no_captions.
  • Age-restricted and private videos need a login and come back as errors.
  • Some videos still hit a bot check after retries (bot_check); they are not charged and can be retried later.
  • translateTo depends on a YouTube endpoint that can be rate-limited; if it fails you get the original language and a warning. Check the language field.
  • Chapters are parsed from the description and need at least three timestamps starting at 0:00.
  • YouTube's internal API changes, which can temporarily break extraction.

Price

Pay per event: about $3 per 1,000 videos, charged only for videos where a transcript was returned. Errors are free. Residential proxy traffic is billed separately as platform usage, roughly 0.2 MB per video, so check the cost shown on the Store page and run a small test first. Disclosure: I built this actor. For a few videos, the free library is the right tool.

Try it: YouTube Transcript actor

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.