YouTube videos contain valuable information locked in audio format. Transcripts unlock this content for search indexing, summarization, knowledge base ingestion, and content repurposing. This tutorial builds a complete pipeline that takes a list of YouTube video URLs, fetches transcripts via the Scavio API, sends them to an LLM for summarization, and outputs structured summaries with key points and timestamps.
Prerequisites
- Python 3.10 or higher
- pip install requests openai
- A Scavio API key
- An OpenAI API key (or any LLM provider)
Walkthrough
Step 1: Extract video IDs from URLs
Parse YouTube URLs to extract video IDs. Handle both youtube.com/watch and youtu.be URL formats.
from urllib.parse import urlparse, parse_qs
def extract_video_id(url: str) -> str:
parsed = urlparse(url)
if parsed.hostname in ("youtu.be",):
return parsed.path.lstrip("/")
return parse_qs(parsed.query).get("v", [url])[0]Step 2: Fetch transcript from Scavio
Call the Scavio YouTube transcript endpoint with the video ID. The response contains timestamped text segments.
def fetch_transcript(video_id: str) -> list[dict]:
r = requests.post(
"https://api.scavio.dev/api/v1/search",
headers={"x-api-key": API_KEY},
json={"platform": "youtube", "action": "transcript", "video_id": video_id}
)
r.raise_for_status()
return r.json().get("transcript", [])
def segments_to_text(segments: list[dict]) -> str:
return " ".join(seg["text"] for seg in segments)Step 3: Summarize with an LLM
Send the full transcript to an LLM with instructions to produce a structured summary with key points.
from openai import OpenAI
client = OpenAI()
def summarize(text: str, title: str = "") -> str:
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "Summarize this YouTube transcript. Output: 1) One paragraph summary. 2) 5 key takeaways as bullet points."},
{"role": "user", "content": f"Title: {title}\n\nTranscript:\n{text[:15000]}"}
],
temperature=0
)
return response.choices[0].message.contentStep 4: Process a batch of videos
Run the full pipeline across multiple videos and save results to a JSON file.
import json
def process_batch(urls: list[str]) -> list[dict]:
results = []
for url in urls:
vid = extract_video_id(url)
segments = fetch_transcript(vid)
text = segments_to_text(segments)
summary = summarize(text)
results.append({"video_id": vid, "url": url, "word_count": len(text.split()), "summary": summary})
return results
with open("summaries.json", "w") as f:
json.dump(process_batch(URLS), f, indent=2)Python Example
import os
import requests
from urllib.parse import urlparse, parse_qs
from openai import OpenAI
SCAVIO_KEY = os.environ.get("SCAVIO_API_KEY", "your_scavio_api_key")
client = OpenAI()
def get_video_id(url: str) -> str:
parsed = urlparse(url)
if parsed.hostname == "youtu.be":
return parsed.path.lstrip("/")
return parse_qs(parsed.query).get("v", [url])[0]
def get_transcript(vid: str) -> str:
r = requests.post("https://api.scavio.dev/api/v1/search",
headers={"x-api-key": SCAVIO_KEY},
json={"platform": "youtube", "action": "transcript", "video_id": vid})
r.raise_for_status()
segments = r.json().get("transcript", [])
return " ".join(s["text"] for s in segments)
def summarize(text: str) -> str:
resp = client.chat.completions.create(
model="gpt-4o", temperature=0,
messages=[{"role": "system", "content": "Summarize this transcript in 3 bullet points."},
{"role": "user", "content": text[:15000]}])
return resp.choices[0].message.content
if __name__ == "__main__":
vid = get_video_id("https://youtube.com/watch?v=dQw4w9WgXcQ")
text = get_transcript(vid)
print(f"Transcript: {len(text.split())} words")
print(summarize(text))JavaScript Example
const SCAVIO_KEY = process.env.SCAVIO_API_KEY || "your_scavio_api_key";
const { OpenAI } = require("openai");
const client = new OpenAI();
function getVideoId(url) {
const u = new URL(url);
if (u.hostname === "youtu.be") return u.pathname.slice(1);
return u.searchParams.get("v") || url;
}
async function getTranscript(vid) {
const res = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST",
headers: { "x-api-key": SCAVIO_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ platform: "youtube", action: "transcript", video_id: vid })
});
const data = await res.json();
return (data.transcript || []).map(s => s.text).join(" ");
}
async function main() {
const vid = getVideoId("https://youtube.com/watch?v=dQw4w9WgXcQ");
const text = await getTranscript(vid);
console.log(`Transcript: ${text.split(" ").length} words`);
const resp = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: `Summarize in 3 points:\n${text.slice(0, 15000)}` }]
});
console.log(resp.choices[0].message.content);
}
main().catch(console.error);Expected Output
Transcript: 2847 words
Summary:
- The video discusses the evolution of web frameworks in 2026,
highlighting FastAPI and Next.js as the leading choices for
API-first development.
- Key takeaway: server components have fundamentally changed
how developers think about frontend architecture.
- The speaker recommends starting with FastAPI for backend
services and Next.js for full-stack applications.