A tool that takes any YouTube URL, fetches the transcript for free, and uses Gemini to produce a bullet-point summary with key takeaways.
youtube-transcript-api pulls the closed captions from any public video — no download needed.
from youtube_transcript_api import YouTubeTranscriptApi
from urllib.parse import urlparse, parse_qs
def get_video_id(url):
parsed = urlparse(url)
if parsed.hostname == "youtu.be":
return parsed.path[1:]
return parse_qs(parsed.query).get("v", [None])[0]
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
video_id = get_video_id(url)
transcript = YouTubeTranscriptApi.get_transcript(video_id)
full_text = " ".join(t["text"] for t in transcript)
print(f"Transcript length: {len(full_text)} characters")
Transcript length: 8432 characters
Pass the transcript to Gemini and ask for a structured summary.
import google.generativeai as genai
genai.configure(api_key="YOUR_GEMINI_API_KEY")
model = genai.GenerativeModel("gemini-1.5-flash")
prompt = f"""
Summarise the following YouTube video transcript.
Return:
1. A one-paragraph overview (3-4 sentences)
2. Five key takeaways as bullet points
3. The main conclusion
TRANSCRIPT:
{full_text[:15000]}
"""
response = model.generate_content(prompt)
print(response.text)
**Overview** This video covers the fundamentals of machine learning, starting from the definition... **Key Takeaways** • Machine learning models learn patterns from data without being explicitly programmed • Supervised learning requires labelled training data... • ... **Conclusion** Machine learning is now accessible to anyone with Python and a dataset.
Accept any YouTube URL as a command-line argument.
import sys
from youtube_transcript_api import YouTubeTranscriptApi
from urllib.parse import urlparse, parse_qs
import google.generativeai as genai
def get_id(url):
p = urlparse(url)
return p.path[1:] if p.hostname == "youtu.be" else parse_qs(p.query).get("v",[None])[0]
url = sys.argv[1] if len(sys.argv) > 1 else input("YouTube URL: ")
transcript = " ".join(t["text"] for t in YouTubeTranscriptApi.get_transcript(get_id(url)))
genai.configure(api_key="YOUR_GEMINI_API_KEY")
model = genai.GenerativeModel("gemini-1.5-flash")
print(model.generate_content(f"Summarise this transcript in 5 bullet points:\n{transcript[:15000]}").text)
Your summariser handles any public YouTube video in seconds. Wrap it in a Streamlit app for a shareable web tool.
Spotted a bug, broken code, or something that doesn't look right? Tell us what's off and we'll fix it.