Captions in default language (single available or English it seems):
To get captions of a YouTube video just use this Linux command (using curl and base64):
curl -s 'https://www.youtube.com/youtubei/v1/get_transcript?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8' -H 'Content-Type: application/json' --data-raw "{\"context\":{\"client\":{\"clientName\":\"WEB\",\"clientVersion\":\"2.2021111\"}},\"params\":\"$(printf '\n\x0bVIDEO_ID' | base64)\"}"
Change the VIDEO_ID
parameter with the one interesting you.
Note: the key isn’t a YouTube Data API v3 one, it is the first public (tested on some computers in different countries) one coming if you curl https://www.youtube.com/ | grep AIzaSy
Note: If interested in how I reverse-engineered this YouTube feature, say it in the comments and I would write a paragraph to explain
Captions in desired language if available:
YouTube made things tricky maybe to lose you at this step, so follow me: the only thing we have to change is the params
value which is base64 encoded data which is in addition to weird characters also containing base64 data which also contains weird characters.
- Get the language initials like “ru” for russian
- Encode
\n\x00\x12\x02LANGUAGE_INITIALS\x1a\x00
in base64 with for instanceA=$(printf '\n\x00\x12\x02LANGUAGE_INITIALS\x1a\x00' | base64)
(don’t forget to changeLANGUAGE_INITIALS
to your language initials wantedru
for instance). The result forru
isCgASAnJ1GgA=
- Encode the result as a URL by replacing the
=
to%3D
with for instanceB=$(printf %s $A | jq -sRr @uri)
. The result forru
isCgASAnJ1GgA%3D
- Only if using shell commands: replace the single
%
to two%
with for instanceC=$(echo $B | sed 's/%/%%/')
. The result forru
isCgASAnJ1GgA%%3D
- Encode
\n\x0bVIDEO_ID\x12\x0e$C
(don’t forget to changeVIDEO_ID
to your video id, with$C
the result of the previous step) with for instanceD=$(printf "\n\x0bVIDEO_ID\x12\x0e$C" | base64)
. The result forru
andlo0X2ZdElQ4
isCgtsbzBYMlpkRWxRNBIOQ2dBU0FuSjFHZ0ElM0Q=
- Use this
params
value from the Captions in default language section:curl -s 'https://www.youtube.com/youtubei/v1/get_transcript?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8' -H 'Content-Type: application/json' --data-raw "{\"context\":{\"client\":{\"clientName\":\"WEB\",\"clientVersion\":\"2.2021111\"}},\"params\":\"$D\"}"