Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Video no longer able to retrieve captions?

As of 4 days ago, you were able to send a GET request to or visit https://video.google.com/timedtext?lang=en&v={youtubeVideoId} and receive an xml response containing the caption track of a given youtube video. Does anyone know if this support has been removed, because as of tonight, it no longer provides the xml response with the captions, the page is simply empty for every video. There were numerous videos this worked for 4 days ago that no longer work. Thanks in advance

like image 914
Dillon Duff Avatar asked Nov 12 '21 04:11

Dillon Duff


People also ask

Why do some videos not have captions?

If your video doesn't generate automatic captions, it could be due to one or more of the following reasons: The captions aren't available yet due to processing complex audio in the video. Automatic captions don't support the language in the video. The video is too long.

Why are closed captions not showing up on my YouTube video?

Click your profile picture at the top right corner. Switch to the Playback and performance section at the left. Uncheck the option named Always show captions. Refresh the page and then re-check the option.

How do I turn on YouTube captions in a video that doesn't have a CC button?

Click your profile picture . Click Settings . From the left-hand menu, click Playback and performance. Check or uncheck Always show captions.

How do I add captions to a Google Drive video?

On your computer, sign in to drive.google.com. Click the video you want to add captions to. Click More Manage caption tracks. Click Add new caption tracks. Click Select file and choose a caption or transcript file. Choose the language for the captions and a name for the track.

Why should I add captions to my videos?

You can make your video content available to a larger audience when you add captions. If you want to reach deaf, hard-of-hearing viewers, or speakers of different languages, captions help these groups understand your videos. You can use two types of caption files:

What is the difference between caption file and transcript file?

Caption file (recommended): This file contains the text and other information to time your captions with your video. Transcript file: This file only contains the text. If you upload a transcript, the video player will have to determine when the words should be displayed.

How do I add captions to a track?

Click Add new caption tracks. Click Select file and choose a caption or transcript file. Choose the language for the captions and a name for the track. Click Upload. Edit caption tracks


1 Answers

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.

  1. Get the language initials like "ru" for russian
  2. Encode \n\x00\x12\x02LANGUAGE_INITIALS\x1a\x00 in base64 with for instance A=$(printf '\n\x00\x12\x02LANGUAGE_INITIALS\x1a\x00' | base64) (don't forget to change LANGUAGE_INITIALS to your language initials wanted ru for instance). The result for ru is CgASAnJ1GgA=
  3. Encode the result as a URL by replacing the = to %3D with for instance B=$(printf %s $A | jq -sRr @uri). The result for ru is CgASAnJ1GgA%3D
  4. Only if using shell commands: replace the single % to two % with for instance C=$(echo $B | sed 's/%/%%/'). The result for ru is CgASAnJ1GgA%%3D
  5. Encode \n\x0bVIDEO_ID\x12\x0e$C (don't forget to change VIDEO_ID to your video id, with $C the result of the previous step) with for instance D=$(printf "\n\x0bVIDEO_ID\x12\x0e$C" | base64). The result for ru and lo0X2ZdElQ4 is CgtsbzBYMlpkRWxRNBIOQ2dBU0FuSjFHZ0ElM0Q=
  6. 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\"}"
like image 76
Benjamin Loison Avatar answered Oct 10 '22 06:10

Benjamin Loison