I build VidScope, a tool that analyzes a YouTube video from its transcript. The first thing that goes wrong in a tool like this is not the AI. It is getting the transcript.
I went through every failed analysis in my logs. Over the period I looked at, 6 of 24 attempts failed (about 25%). I expected IP bans. Here is what the six really were:
- 4 were language failures. The video only had auto-generated subtitles in Portuguese, Hindi or Turkish, and my code only looked for French and English.
- 1 was disabled subtitles. The author turned them off. Nothing to do.
- 1 was a real IP block. The video had English and Turkish subtitles, and the request failed with
IpBlocked, even through a residential proxy.
Four failures out of six had nothing to do with rate limiting. My code only looked for French and English.
This is a small sample from one product, so treat the numbers as an illustration, not a benchmark.
A note on what this library is
I use youtube-transcript-api (version 1.2.4 when I wrote this). It is an unofficial library: it reads the same data the YouTube player reads. It can break whenever YouTube changes something, and automated access may go against YouTube's terms of service. Read them before building a product on it.
Also, if you copy older tutorials, note that the old YouTubeTranscriptApi.list_transcripts(video_id) static call no longer exists in 1.x. You instantiate the class and call api.list(video_id).
Lesson 1: "no transcript" usually means "no transcript in the language you asked for"
My first version asked for fr or en and gave up otherwise. The fix is to list what exists and decide afterwards:
from youtube_transcript_api import YouTubeTranscriptApi, NoTranscriptFound api = YouTubeTranscriptApi() transcript_list = api.list(video_id) # Manual captions first, then auto-generated available = sorted(transcript_list, key=lambda t: t.is_generated) try: transcript = transcript_list.find_transcript(["fr", "en"]) except NoTranscriptFound: if not available: raise transcript = available[0] # any language beats no transcript snippets = transcript.fetch() Then tell the downstream model which language it is reading. A modern LLM reads Turkish or Hindi fine, as long as you do not pretend it is English.
Lesson 2: the "best" transcript is the one in the spoken language
This one surprised me. YouTube can offer auto-dubbed audio tracks, and each dubbed track comes with its own auto-generated subtitles. If you pick the first generated transcript, you may get a translation of a dub, which means quotes the speaker never said.
The player response lists the audio tracks. In what I observed, the IDs look like fr-FR.10 or en-US.4, and the original track is the one ending in .4. This is something I observed on real videos, not documented behavior, so I keep a fallback if the pattern is missing.
The library does not expose the audio tracks, so I read them from the response as it passes through, with a requests hook, without any extra request:
import requests def watch_audio_tracks(session: requests.Session) -> list[str]: audio_ids: list[str] = [] def read(resp, *_args, **_kwargs): if "/youtubei/" not in resp.url: return try: tracks = resp.json()["captions"]["playerCaptionsTracklistRenderer"]["audioTracks"] audio_ids[:] = [t.get("audioTrackId") or "" for t in tracks] except (ValueError, LookupError, TypeError, AttributeError): pass # no captions, or the format changed: let the library deal with it session.hooks["response"].append(read) return audio_ids Then the original language is the track ending in .4. With no dubbing, there is a single auto-generated language and that is the spoken one:
def lang(code: str) -> str: return code.split("-")[0].lower() # "en-US" -> "en" def original_language(transcripts, audio_ids): for audio_id in audio_ids: code, _, kind = audio_id.rpartition(".") if code and kind == "4": return lang(code) spoken = {lang(t.language_code) for t in transcripts if t.is_generated} return spoken.pop() if len(spoken) == 1 else None I wrote unit tests for the cases where the answer is ambiguous (no audio info, several generated languages, a response with an unexpected shape). That code is the most fragile part of the whole pipeline, and it is the part where a silent wrong answer is worst.
Lesson 3: only retry what a retry can fix
Disabled subtitles, a private video, an age restriction: retrying will never help, and the user should get a clear message. An IP block, on the other hand, often goes away on the next attempt from a different IP.
from youtube_transcript_api import ( AgeRestricted, InvalidVideoId, IpBlocked, NoTranscriptFound, RequestBlocked, TranscriptsDisabled, VideoUnavailable, VideoUnplayable, YouTubeRequestFailed, ) def is_transient(exc: Exception) -> bool: return isinstance(exc, (IpBlocked, RequestBlocked, YouTubeRequestFailed, requests.exceptions.RequestException)) The loop is deliberately boring. Five attempts, a fresh session each time, and a rotating residential proxy that gives a new IP per attempt:
for attempt in range(5): session = requests.Session() if proxy_url: session.proxies = {"http": proxy_url, "https": proxy_url} api = YouTubeTranscriptApi(http_client=session) try: ... # pick the transcript and fetch it return result except TranscriptsDisabled: raise RuntimeError("Subtitles are disabled by the author.") except (VideoUnavailable, VideoUnplayable, AgeRestricted, InvalidVideoId): raise RuntimeError("This video is private, removed, age-restricted or the link is invalid.") except Exception as e: if is_transient(e) and attempt < 4: continue # new session, new IP break There is no exponential backoff here, and that is on purpose: the proxy changes the IP on every attempt, so waiting buys nothing. If you scrape from a single IP, the answer is different, and backoff with jitter is the right tool. I did not need it, so I will not pretend I measured it.
Before this loop, a failure was a generic "no transcript available", whatever the cause. Now the user sees one of three messages: the author disabled subtitles, the video is not accessible, or YouTube is temporarily blocking requests, try again in a minute. Two visitors in my logs retried the same video twice and then left. A clear message would have helped them more than a retry button.
What is still not solved
- A block still happens now and then, even through the proxy. It is intermittent, and I have not found a pattern.
- Videos with no subtitles at all need a different approach (transcribing the audio), with a higher cost. I have not built it.
Takeaways
- Read your failure logs by cause, not by count. I assumed rate limiting. Four failures out of six were a language filter in my own code.
- Never filter the language before you know what exists. List first, choose after.
- The transcript in the spoken language is not always the first one the library returns. Check which track is the original.
- Retry only transient errors, and give every permanent error its own message.
