{"slug": "why-fetching-youtube-transcripts-fails-what-6-real-failures-taught-me", "title": "Why Fetching YouTube Transcripts Fails: What 6 Real Failures Taught Me", "summary": "A developer building VidScope, a tool that analyzes YouTube videos from their transcripts, audited failed analyses and found 6 of 24 attempts (about 25%) failed, with four of the six caused not by IP bans but by code that only requested French and English captions. The fix lists all available transcripts, prefers manual over auto-generated captions, and falls back to any language, while a separate issue involves YouTube auto-dubbed audio tracks whose generated subtitles can be translations of a dub rather than the speaker's original words. The developer detects the original track by reading audio track IDs from the player response via a requests hook, noting the .4 suffix pattern is observed rather than documented.", "body_md": "I build [VidScope](https://www.vidscope.fr), 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.\n\nI 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:\n\n`IpBlocked`, even through a residential proxy.\nFour failures out of six had nothing to do with rate limiting. My code only looked for French and English.\n\nThis is a small sample from one product, so treat the numbers as an illustration, not a benchmark.\n\nI use [`youtube-transcript-api`](https://github.com/jdepoix/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.\n\nAlso, 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)`.\n\nMy first version asked for `fr` or `en` and gave up otherwise. The fix is to list what exists and decide afterwards:\n\n``` python\nfrom youtube_transcript_api import YouTubeTranscriptApi, NoTranscriptFound\n\napi = YouTubeTranscriptApi()\ntranscript_list = api.list(video_id)\n\n# Manual captions first, then auto-generated\navailable = sorted(transcript_list, key=lambda t: t.is_generated)\n\ntry:\n    transcript = transcript_list.find_transcript([\"fr\", \"en\"])\nexcept NoTranscriptFound:\n    if not available:\n        raise\n    transcript = available[0]          # any language beats no transcript\n\nsnippets = transcript.fetch()\n```\n\nThen 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.\n\nThis 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.\n\nThe 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.\n\nThe 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:\n\n``` php\nimport requests\n\ndef watch_audio_tracks(session: requests.Session) -> list[str]:\n    audio_ids: list[str] = []\n\n    def read(resp, *_args, **_kwargs):\n        if \"/youtubei/\" not in resp.url:\n            return\n        try:\n            tracks = resp.json()[\"captions\"][\"playerCaptionsTracklistRenderer\"][\"audioTracks\"]\n            audio_ids[:] = [t.get(\"audioTrackId\") or \"\" for t in tracks]\n        except (ValueError, LookupError, TypeError, AttributeError):\n            pass  # no captions, or the format changed: let the library deal with it\n\n    session.hooks[\"response\"].append(read)\n    return audio_ids\n```\n\nThen 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:\n\n``` php\ndef lang(code: str) -> str:\n    return code.split(\"-\")[0].lower()          # \"en-US\" -> \"en\"\n\ndef original_language(transcripts, audio_ids):\n    for audio_id in audio_ids:\n        code, _, kind = audio_id.rpartition(\".\")\n        if code and kind == \"4\":\n            return lang(code)\n    spoken = {lang(t.language_code) for t in transcripts if t.is_generated}\n    return spoken.pop() if len(spoken) == 1 else None\n```\n\nI 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.\n\nDisabled 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.\n\n``` python\nfrom youtube_transcript_api import (\n    AgeRestricted, InvalidVideoId, IpBlocked, NoTranscriptFound,\n    RequestBlocked, TranscriptsDisabled, VideoUnavailable,\n    VideoUnplayable, YouTubeRequestFailed,\n)\n\ndef is_transient(exc: Exception) -> bool:\n    return isinstance(exc, (IpBlocked, RequestBlocked, YouTubeRequestFailed,\n                            requests.exceptions.RequestException))\n```\n\nThe loop is deliberately boring. Five attempts, a fresh session each time, and a rotating residential proxy that gives a new IP per attempt:\n\n```\nfor attempt in range(5):\n    session = requests.Session()\n    if proxy_url:\n        session.proxies = {\"http\": proxy_url, \"https\": proxy_url}\n    api = YouTubeTranscriptApi(http_client=session)\n    try:\n        ...  # pick the transcript and fetch it\n        return result\n    except TranscriptsDisabled:\n        raise RuntimeError(\"Subtitles are disabled by the author.\")\n    except (VideoUnavailable, VideoUnplayable, AgeRestricted, InvalidVideoId):\n        raise RuntimeError(\"This video is private, removed, age-restricted or the link is invalid.\")\n    except Exception as e:\n        if is_transient(e) and attempt < 4:\n            continue            # new session, new IP\n        break\n```\n\nThere 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.\n\nBefore 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.", "url": "https://wpnews.pro/news/why-fetching-youtube-transcripts-fails-what-6-real-failures-taught-me", "canonical_source": "https://dev.to/wgeorgeassistantia/why-fetching-youtube-transcripts-fails-what-6-real-failures-taught-me-9ko", "published_at": "2026-11-30 19:11:46+00:00", "updated_at": "2026-11-30 19:15:14.444606+00:00", "lang": "en", "topics": ["ai-tools", "natural-language-processing", "developer-tools"], "entities": ["VidScope", "YouTube", "youtube-transcript-api"], "also_reported_by": [], "takeaway": "Requesting only fr/en captions caused four of six transcript failures; listing all available transcripts and falling back to any language, then telling the model which language it is reading, avoids them.", "recommendation": {"advice": "List all available transcripts and fall back to any language instead of hardcoding fr/en, and prefer manual captions over auto-generated ones to avoid dub-translated text.", "playbook": "rag-retrieval", "playbook_url": "https://wpnews.pro/playbooks/rag-retrieval"}, "alternates": {"html": "https://wpnews.pro/news/why-fetching-youtube-transcripts-fails-what-6-real-failures-taught-me", "markdown": "https://wpnews.pro/news/why-fetching-youtube-transcripts-fails-what-6-real-failures-taught-me.md", "text": "https://wpnews.pro/news/why-fetching-youtube-transcripts-fails-what-6-real-failures-taught-me.txt", "jsonld": "https://wpnews.pro/news/why-fetching-youtube-transcripts-fails-what-6-real-failures-taught-me.jsonld"}}