Extract automatic captions from YouTube video

为君一笑 提交于 2019-11-27 18:23:23

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:

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

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:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!