yt-dlpでYouTubeの字幕ファイルのダウンロードに失敗(HTTP Error 429: Too Many Requests)
Tokyo Linux Users Group のTechnical Meeting のビデオがYouTube にアップロードされていると先日の #kagolug で教えてもらったので観てみようと思いました.
でもTLUG は英語です.以前はWisper.cpp で文字起こし & 機械翻訳で字幕を作っていましたが最近のYouTube の文字起こしは大分良くなっているのでそれを使おうとローカルにビデオと字幕をdl しようとしたところ字幕のダウンロードに失敗しました.
* Tokyo Linux Users Group
* https://www.youtube.com/@TokyoLinuxUsersGroup
適当な解像度のビデオとオーディオ,それと英語の文字起こし字幕と,それを日本語に翻訳したものをダウンロードしようとしました.
$ yt-dlp -f 244+251 yYgF87nqyKI --write-auto-subs --sub-langs ja,en_orig
[youtube] Extracting URL: yYgF87nqyKI
[youtube] yYgF87nqyKI: Downloading webpage
[youtube] yYgF87nqyKI: Downloading android vr player API JSON
[youtube] yYgF87nqyKI: Downloading web safari player API JSON
[youtube] yYgF87nqyKI: Downloading player 4c5cf06a-tv
[youtube] [jsc:deno] Solving JS challenges using deno
[youtube] yYgF87nqyKI: Downloading m3u8 information
[info] yYgF87nqyKI: Downloading subtitles: ja
[info] yYgF87nqyKI: Downloading 1 format(s): 244+251
[info] Writing video subtitles to: CDImage - Cam [yYgF87nqyKI].ja.vtt
WARNING: The extractor specified to use impersonation for this download, but no impersonate target is available. If you encounter errors, then see https://github.com/yt-dlp/yt-dlp#impersonation for information on installing the required dependencies
ERROR: Unable to download video subtitles for 'ja': HTTP Error 429: Too Many Requests
_*Too Many Requests*_ とか言われてしまいました.今日初めて実行したのになんで?
`--verbose` オプションを付けてみましたがよくわかりません
[info] Writing video subtitles to: CDImage - Cam [yYgF87nqyKI].ja.vtt
[debug] Invoking http downloader on "https://www.youtube.com/api/timedtext?v=yYgF87nqyKI&ei=M4WXaZnECfax2roP_YqAqAc&caps=asr&opi=112496729&xoaf=5&xowf=1&xospf=1&hl=en&ip=0.0.0.0&ipbits=0&expire=1771562915&sparams=ip%2Cipbits%2Cexpire%2Cv%2Cei%2Ccaps%2Copi%2Cxoaf&signature=1B0AC6AA8FB20AFE9B45B2F66DBB1000F04DE626.909918AF43ACD2AFD3E0C2C61E53A3C72E49AB6C&key=yt8&kind=asr&lang=en&fmt=vtt&tlang=ja"
WARNING: The extractor specified to use impersonation for this download, but no impersonate target is available. If you encounter errors, then see https://github.com/yt-dlp/yt-dlp#impersonation for information on installing the required dependencies
ERROR: Unable to download video subtitles for 'ja': HTTP Error 429: Too Many Requests
Traceback (most recent call last):
File "/home/matoken/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 4449, in _write_subtitles
self.dl(sub_filename, sub_copy, subtitle=True)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/matoken/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 3285, in dl
return fd.download(name, new_info, subtitle)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/matoken/bin/yt-dlp/yt_dlp/downloader/common.py", line 480, in download
ret = self.real_download(filename, info_dict)
File "/home/matoken/bin/yt-dlp/yt_dlp/downloader/http.py", line 362, in real_download
establish_connection()
~~~~~~~~~~~~~~~~~~~~^^
File "/home/matoken/bin/yt-dlp/yt_dlp/downloader/http.py", line 119, in establish_connection
ctx.data = self.ydl.urlopen(request)
~~~~~~~~~~~~~~~~^^^^^^^^^
File "/home/matoken/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 4260, in urlopen
return self._request_director.send(req)
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
File "/home/matoken/bin/yt-dlp/yt_dlp/networking/common.py", line 117, in send
response = handler.send(request)
File "/home/matoken/bin/yt-dlp/yt_dlp/networking/_helper.py", line 194, in wrapper
return func(self, *args, **kwargs)
File "/home/matoken/bin/yt-dlp/yt_dlp/networking/common.py", line 359, in send
return self._send(request)
~~~~~~~~~~^^^^^^^^^
File "/home/matoken/bin/yt-dlp/yt_dlp/networking/_requests.py", line 361, in _send
raise HTTPError(res, redirect_loop=max_redirects_exceeded)
yt_dlp.networking.exceptions.HTTPError: HTTP Error 429: Too Many Requests
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/matoken/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 1698, in wrapper
return func(self, *args, **kwargs)
File "/home/matoken/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 1854, in __extract_info
return self.process_ie_result(ie_result, download, extra_info)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/matoken/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 1913, in process_ie_result
ie_result = self.process_video_result(ie_result, download=download)
File "/home/matoken/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 3096, in process_video_result
self.process_info(new_info)
~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/home/matoken/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 189, in wrapper
return func(self, *args, **kwargs)
File "/home/matoken/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 3353, in process_info
sub_files = self._write_subtitles(info_dict, temp_filename)
File "/home/matoken/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 4457, in _write_subtitles
raise DownloadError(msg)
yt_dlp.utils.DownloadError: Unable to download video subtitles for 'ja': HTTP Error 429: Too Many Requests
ISSUES を探すと既知の問題のようでワークアラウンドがありました.
> > [FreeTubeApp/FreeTube#7484](https://github.com/FreeTubeApp/FreeTube/pull/7484)
>
> FreeTube is adding a PO token to their subtitles requests. But FreeTube doesn’t use auto-translated subs AFAICT.
> # Manual subtitles and original language automatic captions are not affected by this HTTP Error 429 issue.
>
> Only subtitles/captions that have been automatically translated into another language are affected. So you may be able to get the subs you want without a problem if you are precise with your `--sub-langs` and `--write-subs` vs `--write-auto-subs` arguments.
>
> But if you _want_ translated auto subs,
> # there are 2 known ways of avoiding this HTTP Error 429:
>
> * Pass fresh cookies to yt-dlp from a browser session where you’ve very recently loaded auto-translated subs
>
> * Wait ~60 seconds after extraction and before downloading the auto subs, e.g. `--sleep-subtitles 60`
>
>
>
> (Either of these 2 methods will work individually, you do not need to combine them)
— [YouTube] Unable to download video subtitles: HTTP Error 429: Too Many Requests · Issue #13831 · yt-dlp/yt-dlp
ということでとりあえず `--sleep-subtitles 60` を付けて実行することで字幕ダウンロード時にsleep して怒られずに字幕をダウンロードすることができました.
$ yt-dlp -f 244+251 yYgF87nqyKI --write-auto-subs --sub-langs ja,en_orig --sleep-subtitles 60
そしてmpv 等でこんな感じで字幕を2つ表示しながら視聴可能に :)
$ mpv --sub-files='CDImage - Cam [yYgF87nqyKI].en.vtt:CDImage - Cam [yYgF87nqyKI].ja.vtt' --secondary-sid=2 'CDImage - Cam [yYgF87nqyKI].webm'
環境
$ yt-dlp --version
2026.02.04
$ deno --version
deno 2.6.8 (stable, release, x86_64-unknown-linux-gnu)
v8 14.5.201.2-rusty
typescript 5.9.2
$ lsb_release -dr
Description: Debian GNU/Linux forky/sid
Release: n/a
$ arch
x86_64
toot
* matoken :fox:: “#tlug のビデオがYouTube にアップロードされてい…” – いなこん