DEV Community

Resolver Data
Resolver Data

Posted on

How to get YouTube transcripts in bulk (for AI, research and repurposing)

If you build anything with LLMs, sooner or later you need the text of YouTube videos: to summarise a channel, to feed a RAG index, to find quotes, or to turn a talk into a blog post.

Copying captions by hand works for one video. For fifty, you want a script. Here is the simplest way I know that doesn't need a YouTube API key or a Google Cloud project.

What we'll use

A small hosted scraper on Apify: YouTube Transcript Scraper. You give it video links or IDs, and it returns one row per video with:

  • text: the full transcript as one clean string
  • segments: timed pieces (start, duration, text) if you want timestamps
  • title, channel, views, durationSeconds, publishDate
  • language and autoGenerated (manual captions vs YouTube's automatic ones)

It picks the caption language you ask for, falls back to another one if you allow it, and you are only charged for videos that actually have a transcript.

Step 1: get a free Apify token

Sign up at apify.com, then copy your API token from Settings → API & Integrations. The free plan includes monthly credit, which covers a lot of transcripts.

Step 2: run it from Python

pip install apify-client
Enter fullscreen mode Exit fullscreen mode
from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")

run = client.actor("resolver/youtube-transcript-scraper-fast").call(run_input={
    "videoUrls": [
        {"url": "https://www.youtube.com/watch?v=jNQXAC9IVRw"},
        {"url": "https://youtu.be/dQw4w9WgXcQ"},
    ],
    "languages": ["en", "any"],      # prefer English, else whatever exists
    "includeAutoGenerated": True,     # use automatic captions if needed
    "includeTimestamps": True,        # also return timed segments
})

for video in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(video["title"], "-", len(video["text"] or ""), "chars")
Enter fullscreen mode Exit fullscreen mode

That's it. Each item is a plain dict, so you can write it to JSON, CSV or straight into your vector store.

Step 3: do something useful with it

A few patterns that work well:

  • Summaries: send text to your LLM with a "summarise in 5 bullet points" prompt.
  • Search with timestamps: index segments, and link back to url + "&t=" + str(int(start)) so users jump to the exact moment.
  • Channel research: collect the video links of a channel, run them in one batch, and compare topics over time.

Tips

  • Shorts and youtu.be links work too. You can also pass bare 11-character IDs in videoIds.
  • Some videos have no captions at all. They come back with an error field and cost nothing.
  • Keep useProxy on when running on Apify. YouTube rate-limits datacenter IPs.

Price

$2.50 per 1,000 transcripts, charged only when a transcript is returned. No subscription.

If you hit an edge case, open an issue on the Actor page and I'll look at it.

Top comments (0)