Need to extract transcripts from YouTube videos programmatically? If you've tried before, you know it's surprisingly hard:
- The YouTube Data API doesn't actually give you transcripts (just metadata)
- youtube-transcript-api (Python package) breaks regularly and doesn't handle all videos
- Many videos don't have captions at all — no amount of scraping helps
- Rate limits, quotas, and API key management add friction
I built a solution that handles all of these cases with a single API call — including an AI fallback for videos without captions.
The Quick Version
curl "https://api.getcontentapi.com/api/v1/youtube/transcript?url=https://youtube.com/watch?v=dQw4w9WgXcQ" \
-H "X-API-Key: your_api_key"
That's it. You get back:
{
"success": true,
"data": {
"title": "Rick Astley - Never Gonna Give You Up",
"channel": "Rick Astley",
"duration": 212,
"language": "en",
"word_count": 284,
"full_text": "We're no strangers to love...",
"transcript": [
{"start": 0.0, "duration": 4.2, "text": "We're no strangers to love"},
{"start": 4.2, "duration": 3.8, "text": "You know the rules and so do I"},
...
]
}
}
How It Works
ContentAPI uses a multi-strategy approach to get transcripts:
Strategy 1: Native Captions
First, we check if the video has official captions (manual or auto-generated). This covers ~90% of videos and is the fastest method.
Strategy 2: Community Captions
Some videos have community-contributed subtitles. We check for these as a fallback.
Strategy 3: AI Transcription (Whisper)
For the remaining ~10% of videos with no captions at all, we extract the audio and run it through OpenAI's Whisper model. This works on any video in any language.
All of this happens automatically — you just make one API call.
Python Examples
Basic Transcript Extraction
import requests
API_KEY = "your_api_key"
BASE_URL = "https://api.getcontentapi.com/api/v1"
def get_transcript(video_url):
response = requests.get(
f"{BASE_URL}/youtube/transcript",
params={"url": video_url},
headers={"X-API-Key": API_KEY}
)
return response.json()["data"]
transcript = get_transcript("https://youtube.com/watch?v=dQw4w9WgXcQ")
print(f"Title: {transcript['title']}")
print(f"Words: {transcript['word_count']}")
print(f"Full text:\n{transcript['full_text']}")
Using the Python SDK
pip install contentapi
from contentapi import ContentAPI
client = ContentAPI(api_key="your_api_key")
# Get transcript
transcript = client.youtube_transcript("https://youtube.com/watch?v=...")
print(transcript.title)
print(transcript.full_text)
# Get with timestamps
for segment in transcript.segments:
minutes = int(segment.start // 60)
seconds = int(segment.start % 60)
print(f"[{minutes:02d}:{seconds:02d}] {segment.text}")
Get Video Summary Instead
Don't want the full transcript? Get an AI-generated summary:
response = requests.get(
f"{BASE_URL}/youtube/summary",
params={"url": "https://youtube.com/watch?v=..."},
headers={"X-API-Key": API_KEY}
)
summary = response.json()["data"]
print(summary["summary"])
print("Key points:", summary["key_points"])
print("Topics:", summary["topics"])
Get Video Chapters
response = requests.get(
f"{BASE_URL}/youtube/chapters",
params={"url": "https://youtube.com/watch?v=..."},
headers={"X-API-Key": API_KEY}
)
for chapter in response.json()["data"]["chapters"]:
print(f"{chapter['start_time']}s - {chapter['title']}")
Get Comments
response = requests.get(
f"{BASE_URL}/youtube/comments",
params={"url": "https://youtube.com/watch?v=..."},
headers={"X-API-Key": API_KEY}
)
for comment in response.json()["data"]["comments"]:
print(f"{comment['author']} ({comment['likes']} likes): {comment['text']}")
Real-World Use Cases
1. Build a YouTube Knowledge Base
from contentapi import ContentAPI
import json
client = ContentAPI(api_key="your_api_key")
# Process a playlist worth of videos
video_urls = [
"https://youtube.com/watch?v=video1",
"https://youtube.com/watch?v=video2",
"https://youtube.com/watch?v=video3",
]
knowledge_base = []
for url in video_urls:
transcript = client.youtube_transcript(url)
knowledge_base.append({
"title": transcript.title,
"channel": transcript.channel,
"content": transcript.full_text,
"url": url,
"duration": transcript.duration,
})
# Save for RAG pipeline
with open("youtube_kb.json", "w") as f:
json.dump(knowledge_base, f, indent=2)
2. Auto-Generate Blog Posts from Videos
from contentapi import ContentAPI
from openai import OpenAI
content_client = ContentAPI(api_key="your_contentapi_key")
openai_client = OpenAI(api_key="your_openai_key")
# Get transcript
transcript = content_client.youtube_transcript(
"https://youtube.com/watch?v=..."
)
# Generate blog post
response = openai_client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "Convert this video transcript into a well-structured "
"blog post with headers, key takeaways, and a summary."
},
{
"role": "user",
"content": f"Video: {transcript.title}\n\n{transcript.full_text}"
}
]
)
blog_post = response.choices[0].message.content
print(blog_post)
3. Multi-Language Transcript Search
# ContentAPI returns the detected language
transcript = client.youtube_transcript(
"https://youtube.com/watch?v=spanish_video"
)
print(f"Detected language: {transcript.language}")
# "es" — Spanish
# The full_text is in the original language
# Use any translation API to convert if needed
Comparison with Alternatives
| Feature | youtube-transcript-api | YouTube Data API | ContentAPI |
|---|---|---|---|
| API key needed | No | Yes (Google) | Yes (free) |
| Rate limits | Aggressive | 10,000 units/day | 5,000 req/month free |
| No-caption videos | ❌ Fails | ❌ No transcripts | ✅ AI fallback |
| Video metadata | ❌ No | ✅ Yes | ✅ Yes |
| Summaries | ❌ No | ❌ No | ✅ AI-powered |
| Chapters | ❌ No | ❌ No | ✅ Yes |
| Comments | ❌ No | ✅ Yes | ✅ Yes |
| Maintenance | You | You | Managed |
Beyond YouTube
The same API also handles web pages, Twitter/X, and Reddit — so if your pipeline needs content from multiple sources, it's one SDK:
from contentapi import ContentAPI
client = ContentAPI(api_key="your_api_key")
# All through the same interface
youtube = client.extract("https://youtube.com/watch?v=...")
webpage = client.extract("https://example.com/article")
tweet = client.extract("https://x.com/user/status/123456")
reddit = client.extract("https://reddit.com/r/python/comments/abc")
MCP Server for AI Assistants
If you use Claude, Cursor, or Windsurf, there's an MCP server that lets your AI assistant extract YouTube transcripts directly:
npx contentapi-mcp-server
Then just ask your AI: "Get me the transcript from this YouTube video: [url]"
Getting Started
- Sign up free: getcontentapi.com — no credit card needed
-
Install the SDK:
pip install contentapi - Extract your first transcript:
from contentapi import ContentAPI
client = ContentAPI(api_key="your_key")
t = client.youtube_transcript("https://youtube.com/watch?v=dQw4w9WgXcQ")
print(t.full_text)
Free tier: 5,000 requests/month. Enough to process ~170 videos per day.
Resources:
Have you worked with YouTube transcripts before? What was your biggest pain point? I'd love to hear about your use cases in the comments! 💬
Top comments (0)