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!
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 address the track by
name=Automatic only for some reasons. But for another video it worked fine:
A great way about going to get data from a page is by using file_get_contents however this only works if the video has a ‘CC’ or captions button but when it does you can get all the text elements from the xml file unfortunately as documented by one of the ‘Youtube to caption’ services stated it needs captions enabled by the youtuber to get the captions so unfortunately you cannot get captions from videos without ‘CC’ enabled, however if you still want you can use file_get_contents on the xml file then find all the ‘text’ tags and then turn those into captions.
Here my suggestions after spending some time:
Js library: https://github.com/syzer/youtube-captions-scraper => support auto-generated caption.
2 quick methods below not support auto-generated caption
- Get a list of subtitles: http://video.google.com/timedtext?type=list&v=lT3vGaOLWqE
- Get subtitle with track id: http://video.google.com/timedtext?type=track&v=lT3vGaOLWqE&id=0&lang=en
I was taking a look at downsub.com and found the following API call which seems to work for automatically generated captions: