Extract automatic captions from YouTube video

Aerodynamika picture Aerodynamika · Dec 23, 2012 · Viewed 16.3k times · Source

I'm having problems extracting automatic captions from YouTube videos.

I tried using the http://video.google.com/timedtext?type=track&v=3wszM2SA12E&name=Automatic&lang=en method, but that one only works for those videos, which have named tracks. For example, this one doesn't have any named tracks (only automatic caption) and doesn't load up: rrkrvAUbU9Y

There are several web-applications out there which can do it (like http://www.serpsite.com/youtube-subtitles-download-tool/ and http://mo.dbxdb.com/), but I need a script, because I want to use it for my research.

Anyone has any ideas what is the correct way to get this? YouTube's API has something about captions, but only for registered users, while the apps above work for all videos and I doubt they just capture the html code from the page (although that's possible too). There must be a way... please help!

Answer

Vlada Katlinskaya picture Vlada Katlinskaya · Aug 14, 2017

You need to call another API first: http://video.google.com/timedtext?type=list&v=3wszM2SA12E

This will give you the list of the tracks available. In your case only one track can be obtained: id="0" name="Automatic" lang_code="en" lang_original="English" lang_translated="English" lang_default="true"

In this particular video I could get the track by name name=Automatic:

https://video.google.com/timedtext?type=track&v=3wszM2SA12E&name=Automatic&lang=en

But for another video id= worked fine:

http://video.google.com/timedtext?type=track&v=zenMEj0cAC4&id=0&lang=en