沃梦达 / 编程问答 / php问题 / 正文

从 YouTube 视频中提取自动字幕

Extract automatic captions from YouTube video(从 YouTube 视频中提取自动字幕)

本文介绍了从 YouTube 视频中提取自动字幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从 YouTube 视频中提取自动字幕时遇到问题.

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

我尝试使用 http://video.google.com/timedtext?type=track&v=3wszM2SA12E&name=Automatic&lang=en 方法,但该方法仅适用于那些具有命名轨道的视频.例如,这个没有任何命名轨道(只有自动字幕)并且不会加载:rrkrvAUbU9Y

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

有几个网络应用程序可以做到这一点(例如 http://www.serpsite.com/youtube-subtitles-download-tool/ 和 http://mo.dbxdb.com/),但我需要一个脚本,因为我想用它进行研究.

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.

任何人都知道获得这个的正确方法是什么?YouTube 的 API 有一些关于字幕的内容,但仅适用于注册用户,而上述应用程序适用于所有视频,我怀疑它们只是从页面中捕获 html 代码(尽管这也是可能的).一定有办法……请帮忙!

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!

推荐答案

需要先调用另一个API:http://video.google.com/timedtext?type=list&v=3wszM2SA12E

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

这将为您提供可用曲目的列表.在您的情况下,只能获得一首曲目:id=0";名称=自动"lang_code="en";lang_original=英语"lang_translated="英文"lang_default="true"

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"

在这个特定的视频中,我可以按名称获取曲目name=Automatic:

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

但是对于另一个视频 id= 工作正常:

But for another video id= worked fine:

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

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

这篇关于从 YouTube 视频中提取自动字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:从 YouTube 视频中提取自动字幕

基础教程推荐