Back to Blog

How to Download YouTube Subtitles Programmatically

6 min read

Downloading YouTube subtitles used to require browser extensions, sketchy websites, or brittle Python scripts that break every few months. YouTubeTranscripts.co provides a clean, programmatic way to download subtitles from any YouTube video. Get subtitles in SRT, plain text, or structured JSON format with a single API call.

Why Download Subtitles Programmatically

Manual subtitle downloads do not scale. If you need subtitles for video editing, content analysis, accessibility compliance, or language learning applications, you need an automated solution. Our API lets you integrate subtitle downloads into your existing workflow or application.

Download SRT Subtitles

SRT is the universal subtitle format. Download it directly from the API.

import httpx

response = httpx.get(
    "https://api.youtubetranscripts.co/v1/transcript",
    params={
        "url": "https://youtube.com/watch?v=VIDEO_ID",
        "format": "srt",
    },
    headers={"x-api-key": "YOUR_API_KEY"},
)

# Save to file
with open("video_subtitles.srt", "w", encoding="utf-8") as f:
    f.write(response.json()["srt"])

Download Plain Text

Get just the text without timestamps for reading, analysis, or AI processing.

response = httpx.get(
    "https://api.youtubetranscripts.co/v1/transcript",
    params={
        "url": "https://youtube.com/watch?v=VIDEO_ID",
        "format": "text",
    },
    headers={"x-api-key": "YOUR_API_KEY"},
)

text = response.json()["text"]
with open("video_text.txt", "w", encoding="utf-8") as f:
    f.write(text)

Download as JSON

The default format returns structured JSON with timestamps, perfect for building interactive subtitle displays.

import json

response = httpx.get(
    "https://api.youtubetranscripts.co/v1/transcript",
    params={"url": "https://youtube.com/watch?v=VIDEO_ID"},
    headers={"x-api-key": "YOUR_API_KEY"},
)

data = response.json()
with open("video_subtitles.json", "w") as f:
    json.dump(data, f, indent=2)

Batch Subtitle Download Script

Download subtitles for multiple videos with a reusable script.

import httpx
import re
import os

API_KEY = "YOUR_API_KEY"
OUTPUT_DIR = "subtitles"
os.makedirs(OUTPUT_DIR, exist_ok=True)

def download_subtitles(urls: list[str], format: str = "srt"):
    for url in urls:
        resp = httpx.get(
            "https://api.youtubetranscripts.co/v1/transcript",
            params={"url": url, "format": format},
            headers={"x-api-key": API_KEY},
        )
        data = resp.json()
        slug = re.sub(r"[^a-z0-9]+", "-", data["title"].lower()).strip("-")
        ext = "srt" if format == "srt" else "txt"
        content = data.get("srt", data.get("text", ""))
        filepath = os.path.join(OUTPUT_DIR, f"{slug}.{ext}")

        with open(filepath, "w", encoding="utf-8") as f:
            f.write(content)
        print(f"Saved: {filepath}")

download_subtitles([
    "https://youtube.com/watch?v=V1",
    "https://youtube.com/watch?v=V2",
])

Using cURL for Quick Downloads

Download subtitles from the command line without writing any code.

# Download SRT
curl -s -H "x-api-key: YOUR_API_KEY" \
  "https://api.youtubetranscripts.co/v1/transcript?url=https://youtube.com/watch?v=VIDEO_ID&format=srt" \
  | jq -r '.srt' > subtitles.srt

# Download plain text
curl -s -H "x-api-key: YOUR_API_KEY" \
  "https://api.youtubetranscripts.co/v1/transcript?url=https://youtube.com/watch?v=VIDEO_ID&format=text" \
  | jq -r '.text' > transcript.txt

Conclusion

Downloading YouTube subtitles should be simple, and with YouTubeTranscripts.co it is. One API call gets you subtitles in SRT, text, or JSON format from any video. Build it into your tools or use cURL for quick downloads. Get started with 150 free requests at youtubetranscripts.co.

Ready to start extracting YouTube transcripts?

Get 150 free API requests. No credit card required.

Get Your Free API Key