I have a folder of lectures I was definitely going to watch. Three hours each. I have watched none of them. The folder is not a study plan, it is a graveyard with good intentions.
So I built a machine that watches them for me — or rather, reads them. It takes a YouTube lecture, pulls the captions, and hands back a summary where every point is a link to the exact minute it was said. Click “backpropagation”, land at 3:42, hear the lecturer say it himself. That is the whole trick of this project: a free YouTube video summarizer AI free app that turns a 3-hour lecture into 5 minutes of reading, without ever asking you to trust a summary you cannot check.
This is project #63 in the series, it takes about five hours, and the whole stack is free: yt-dlp for captions, Whisper for the videos that have none, Gemini for the real summaries, and a Gradio web UI. No credit card, no server, no more lecture graveyard.

Why a normal summary fails this job
Paste a transcript into a chatbot and you get a nice paragraph. Lovely. Now try to verify one claim in it. Where did the lecturer say that? Page where? Minute where? You cannot find out, because the summary threw away the only thing that made it checkable: the time.
And when the model does not know, it does not say so. It invents a confident-sounding point, attaches it to nothing, and you walk into an exam repeating something nobody ever said. A summary without timestamps is a rumour with good formatting.
This project fixes both. Every point keeps the start time of the sentence it came from, and in demo mode the summary can only quote — it physically cannot invent a sentence, because it only picks sentences that already exist in the transcript. The timestamp is the citation. Click it, hear it, believe it or don’t.
What you need
- Python 3.10 or newer
- A free Google AI Studio API key (only for real mode — the demo runs with no key at all)
- A YouTube lecture you have been avoiding
- About five hours, most of which is you discovering how many lectures you have saved
Install with pip install -r requirements.txt: google-generativeai, gradio, and yt-dlp. Skip the install and demo mode still works on the standard library alone — it reads the bundled sample transcript and summarises that instead of calling Gemini.
How it works
There are three halves, and they only meet through a file of timestamps.

Half one: transcript. transcript.py asks yt-dlp for the video’s auto-generated English captions, which arrive as a WebVTT file — a list of cues, each with a start time, an end time, and a line or two of text. Every cue keeps its start time, because a summary point without a timestamp is just a claim. If the video has no captions at all, yt-dlp returns nothing — no error, just silence — so the code raises a clear error and the README tells you to transcribe the audio with Whisper instead, which writes timestamps for you.
Half two: segments. The cues are grouped into fixed 3-minute windows. Grouping by clock time, not by word count, is what keeps every point honestly attached to one minute of the lecture. A lecturer who rambles for ten minutes about one idea gets one segment; a lecturer who fires off five ideas in three minutes gets five sentences competing for two slots in the same segment. Time is the only fair ruler here.
Half three: summarise. In demo mode, summarize.py scores every sentence in a segment by the content words it shares with that segment, and keeps the top two, quoted verbatim. In real mode the same segments go to Gemini with one instruction: one sentence per segment, plain English, never invent a timestamp — use the segment start time you were given. Either way, each point becomes a link like https://www.youtube.com/watch?v=VIDEO_ID&t=90s, so clicking it jumps straight to that minute.
The maths: timestamp arithmetic, in plain English
Here is the one piece of maths in the project, and it is friendlier than it looks. A caption file stores time as 00:03:42.000 — hours, minutes, seconds, milliseconds. To do anything useful with it, you convert it to plain seconds:
def _to_seconds(hours, minutes, seconds, _ms):
hours = int(hours) if hours else 0
return hours * 3600 + int(minutes) * 60 + int(seconds)00:03:42 becomes 3 × 60 + 42 = 222 seconds. That number is the whole trick: it is the segment bucket (222 // 180 = 1, the second 3-minute window), and it is the link (&t=222s). Converting back is the reverse — divide by 3600 for hours, take the remainder, divide by 60 for minutes:
def format_timestamp(seconds):
seconds = int(seconds)
hours, rem = divmod(seconds, 3600)
minutes, secs = divmod(rem, 60)
if hours:
return f"{hours}:{minutes:02d}:{secs:02d}"
return f"{minutes}:{secs:02d}"222 seconds goes in, 3:42 comes out. A 3-hour lecture is 10,800 seconds, which is 60 segments of 180 seconds — 60 points in real mode, about 5 minutes of reading. In demo mode it keeps two points per segment, so 120 points, closer to 10 minutes. That is the compression ratio the whole project is selling in real mode: 10,800 seconds of talking, 300 seconds of reading, and every line still points back at the minute it came from.
Build it
Step 1 — Set up the project. Grab the download at the end of this article: config.py, transcript.py, summarize.py, app.py, plus requirements.txt and .env.example. Copy .env.example to .env and add your Gemini key if you have one. No key, no problem — demo mode kicks in automatically.

Step 2 — Get the transcript. This is transcript.py, and the parser is the whole game:
def parse_vtt(text):
cues, current = [], None
for raw in text.splitlines():
line = raw.strip()
match = _TIME_RE.match(line)
if match:
groups = match.groups()
current = {
"start": _to_seconds(*groups[:4]),
"end": _to_seconds(*groups[4:]),
"text": "",
}
cues.append(current)
elif current is not None and line and not line.startswith("WEBVTT"):
if line.isdigit():
continue
cleaned = _TAG_RE.sub("", line).strip()
current["text"] = f"{current['text']} {cleaned}".strip()
return [c for c in cues if c["text"]]It walks the file line by line, starts a new cue at every timestamp line, and glues the following lines onto it, stripping HTML tags like <c.color> that YouTube leaves in captions. A bare number on its own line is a cue id, not text, so it gets skipped. The result is a list of cues, each with a start, an end, and clean text.
Step 3 — Group into segments. Cues fall into 3-minute buckets by integer division:
def group_into_segments(cues, segment_seconds=None):
segment_seconds = segment_seconds or config.SEGMENT_SECONDS
segments, current = [], None
for cue in cues:
bucket = int(cue["start"] // segment_seconds)
if current is None or current["bucket"] != bucket:
current = {
"bucket": bucket,
"start": bucket * segment_seconds,
"end": (bucket + 1) * segment_seconds,
"text": "",
"cue_count": 0,
"sentences": [],
}
segments.append(current)
current["text"] = f"{current['text']} {cue['text']}".strip()
current["cue_count"] += 1
for sentence in re.split(r"(?<=[.!?])\s+", cue["text"]):
if sentence.strip():
current["sentences"].append((cue["start"], sentence.strip()))Each sentence remembers the start time of its own cue. That last detail matters more than it looks — it is the fix for the bug in the “What broke” section below.
Step 4 — Pick the points. The demo scorer counts how often each content word appears in the segment, then scores each sentence by the words it shares with the segment:
def extractive_point(segment, n_sentences=None):
n_sentences = n_sentences or config.SENTENCES_PER_SEGMENT
timed = segment.get("sentences") or [
(segment["start"], s) for s in split_sentences(segment["text"])
]
if len(timed) <= n_sentences:
return timed
words = [w for w in _WORD_RE.findall(segment["text"].lower())
if w not in STOPWORDS]
freq = Counter(words)
scored = []
for start, sentence in timed:
sentence_words = [w for w in _WORD_RE.findall(sentence.lower())
if w not in STOPWORDS]
score = sum(freq[w] for w in set(sentence_words))
score /= math.sqrt(max(len(sentence_words), 1))
scored.append((score, start, sentence))
scored.sort(key=lambda item: item[0], reverse=True)
chosen = {(start, s) for _, start, s in scored[:n_sentences]}
return [(start, s) for start, s in timed if (start, s) in chosen]Stopwords — “the”, “and”, “you”, “really” — are thrown out before counting, because a sentence full of “the” is not about anything. The score is divided by the square root of the sentence length, so a long ramble does not win just for being long. The winners are returned in spoken order, not score order, so the summary reads like the lecture, not like a leaderboard.
Step 5 — Put a face on it. app.py is a small Gradio UI: paste a YouTube URL, or upload a .vtt file, or load the sample lecture, and get a Markdown summary back with clickable timestamps. Run it with python app.py and open http://127.0.0.1:7860.
Expected outcome
Run the demo and you get this, word for word:
$ python summarize.py --sample
# Lecture summary (10:05)
Source: 23 caption cues in 4 x 3-minute segments. 485 spoken words compressed below — under a minute of reading.
- [1:30] We compute the gradient of the loss with respect to each weight, then step downhill.
- [2:20] Stochastic gradient descent uses one small batch at a time instead of the whole dataset, which makes each step noisy but much faster.
- [3:42] Each layer passes its share of the gradient to the layer before it, multiplied by the derivative of its activation function.
- [4:10] A sigmoid squashes gradients, which is one reason deep networks were so hard to train before ReLU.
- [6:00] Training loss keeps falling while validation loss starts climbing.
- [7:22] Watch the validation loss, and stop training the moment it starts getting worse.
- [9:12] Training crashes, power cuts happen, and a three-hour run you cannot resume is a three-hour run you lost.
- [9:40] Next lecture we will build a transformer from scratch, and you will see why attention made all of this scale.
The sample is a 10-minute lecture on how neural networks learn. I checked every timestamp against the transcript by hand: 1:30 really is gradient descent, 3:42 really is backpropagation, 6:00 really is overfitting, 7:22 is early stopping in the full run. The measured result is 8 points from 23 cues in 4 segments, 485 spoken words down to 136 words — under a minute of reading. With a real key, Gemini rewrites each segment in its own words instead of quoting — same timestamps, smoother sentences. The number to care about is not the word count, it is the link: right minute, right point, every time.
What broke
Three things, all of them instructive. First, the original version linked every point to its segment start — 0:00, 3:00, 6:00 — so a point spoken at 1:30 claimed to be at 0:00. Clicking it landed you a minute and a half early, listening to the introduction, wondering where gradient descent went. Sentences now carry their own cue start time, and the link uses that.
Second, the first demo scorer let long sentences win just for being long. A 40-word ramble about nothing outscored a sharp 12-word definition, because it had more words to match. Dividing by the square root of the sentence length fixed it — a short, on-topic sentence can now beat a ramble.
Third, yt-dlp returns no file at all when a video has no captions — no error, just silence — so the first version crashed with a confusing “no files found” message. Now it raises a clear error telling you to transcribe the audio with Whisper instead. A missing feature should say so, not pretend the video is empty.
Download the full project
The complete project — all the Python files, the sample lecture transcript, requirements.txt, .env.example, and the README — is in the zip below. Unzip it, run python summarize.py --sample, and read a 10-minute lecture in under a minute. Then point it at the 3-hour lecture you have been avoiding, and let it do the watching.
Premium Download
Get the complete project code
