是否可以从Youtube视频中提取隐藏式字幕脚本?
我们在youtube上有200多个网络广播,每个网络广播至少有一个小时.Youtube已经关闭了所有视频的标题,但似乎用户无法获得它.
我在此博客中尝试过该网址,但它不适用于我们的视频.
http://googlesystem.blogspot.com/2010/10/download-youtube-captions.html
谢谢
小智 36
以下是如何获取YouTube视频的文字记录(如果有):
虽然语法可能有点傻,但这是一个非常好的解决方案.
资料来源:http://ccm.net/faq/40644-youtube-how-to-get-the-transcript-of-a-video
nis*_*ama 21
另一种选择是使用youtube-dl:
youtube-dl --skip-download --write-auto-sub $youtube_url
Run Code Online (Sandbox Code Playgroud)
默认格式为vtt,其他可用格式为ttml(--sub-format ttml)。
--write-sub
Write subtitle file
--write-auto-sub
Write automatically generated subtitle file (YouTube only)
--all-subs
Download all the available subtitles of the video
--list-subs
List all available subtitles for the video
--sub-format FORMAT
Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"
--sub-lang LANGS
Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags
Run Code Online (Sandbox Code Playgroud)
您可以ffmpeg用来将字幕文件转换为另一种格式:
ffmpeg -i input.vtt output.srt
Run Code Online (Sandbox Code Playgroud)
这是VTT字幕的样子:
WEBVTT
Kind: captions
Language: en
00:00:01.429 --> 00:00:04.249 align:start position:0%
ladies<00:00:02.429><c> and</c><00:00:02.580><c> gentlemen</c><c.colorE5E5E5><00:00:02.879><c> I'd</c></c><c.colorCCCCCC><00:00:03.870><c> like</c></c><c.colorE5E5E5><00:00:04.020><c> to</c><00:00:04.110><c> thank</c></c>
00:00:04.249 --> 00:00:04.259 align:start position:0%
ladies and gentlemen<c.colorE5E5E5> I'd</c><c.colorCCCCCC> like</c><c.colorE5E5E5> to thank
</c>
00:00:04.259 --> 00:00:05.930 align:start position:0%
ladies and gentlemen<c.colorE5E5E5> I'd</c><c.colorCCCCCC> like</c><c.colorE5E5E5> to thank
you<00:00:04.440><c> for</c><00:00:04.620><c> coming</c><00:00:05.069><c> tonight</c><00:00:05.190><c> especially</c></c><c.colorCCCCCC><00:00:05.609><c> at</c></c>
00:00:05.930 --> 00:00:05.940 align:start position:0%
you<c.colorE5E5E5> for coming tonight especially</c><c.colorCCCCCC> at
</c>
00:00:05.940 --> 00:00:07.730 align:start position:0%
you<c.colorE5E5E5> for coming tonight especially</c><c.colorCCCCCC> at
such<00:00:06.180><c> short</c><00:00:06.690><c> notice</c></c>
00:00:07.730 --> 00:00:07.740 align:start position:0%
such short notice
00:00:07.740 --> 00:00:09.620 align:start position:0%
such short notice
I'm<00:00:08.370><c> sure</c><c.colorE5E5E5><00:00:08.580><c> mr.</c><00:00:08.820><c> Irving</c><00:00:09.000><c> will</c><00:00:09.120><c> fill</c><00:00:09.300><c> you</c><00:00:09.389><c> in</c><00:00:09.420><c> on</c></c>
00:00:09.620 --> 00:00:09.630 align:start position:0%
I'm sure<c.colorE5E5E5> mr. Irving will fill you in on
</c>
00:00:09.630 --> 00:00:11.030 align:start position:0%
I'm sure<c.colorE5E5E5> mr. Irving will fill you in on
the<00:00:09.750><c> circumstances</c><00:00:10.440><c> that's</c><00:00:10.620><c> brought</c><00:00:10.920><c> us</c></c>
00:00:11.030 --> 00:00:11.040 align:start position:0%
<c.colorE5E5E5>the circumstances that's brought us
</c>
Run Code Online (Sandbox Code Playgroud)
以下是相同的字幕,文件的顶部没有该部分,也没有标签:
00:00:01.429 --> 00:00:04.249 align:start position:0%
ladies and gentlemen I'd like to thank
00:00:04.249 --> 00:00:04.259 align:start position:0%
ladies and gentlemen I'd like to thank
00:00:04.259 --> 00:00:05.930 align:start position:0%
ladies and gentlemen I'd like to thank
you for coming tonight especially at
00:00:05.930 --> 00:00:05.940 align:start position:0%
you for coming tonight especially at
00:00:05.940 --> 00:00:07.730 align:start position:0%
you for coming tonight especially at
such short notice
00:00:07.730 --> 00:00:07.740 align:start position:0%
such short notice
00:00:07.740 --> 00:00:09.620 align:start position:0%
such short notice
I'm sure mr. Irving will fill you in on
00:00:09.620 --> 00:00:09.630 align:start position:0%
I'm sure mr. Irving will fill you in on
00:00:09.630 --> 00:00:11.030 align:start position:0%
I'm sure mr. Irving will fill you in on
the circumstances that's brought us
Run Code Online (Sandbox Code Playgroud)
您会看到每个字幕文本重复了三遍。每八行(第三,十一,十九和二十七)会有一个新的字幕文本。
这会将VTT字幕转换为更简单的格式:
sed '1,/^$/d' *.vtt| # remove the part at the top
sed 's/<[^>]*>//g'| # remove tags
awk -F. 'NR%8==1{printf"%s ",$1}NR%8==3' # print each new subtitle text and its start time without milliseconds
Run Code Online (Sandbox Code Playgroud)
上面命令的输出如下所示:
00:00:01 ladies and gentlemen I'd like to thank
00:00:04 you for coming tonight especially at
00:00:05 such short notice
00:00:07 I'm sure mr. Irving will fill you in on
00:00:09 the circumstances that's brought us
Run Code Online (Sandbox Code Playgroud)
这将以简化格式输出视频的隐藏式字幕:
cap()(cd /tmp;rm -f *.vtt;youtube-dl --skip-download --write-auto-sub "$1";sed '1,/^$/d' *.vtt|sed 's/<[^>]*>//g'|awk -F. 'NR%8==1{printf"%s ",$1}NR%8==3'|tee cap)
ton*_*gil 18
您可以通过访问来查看/复制/下载youtube的隐藏式字幕文件的时间编码的xml文件
http://video.google.com/timedtext?lang=[LANGUAGE]&v=[YOUTUBE VIDEO IDENTIFIER]
Run Code Online (Sandbox Code Playgroud)
例如 http://video.google.com/timedtext?lang=pt&v=WSVKbw7LC2w
注意:此方法不会下载自动生成的隐藏式字幕,即使您使用的语言正确(可能还有自动生成语言的特殊代码).
Pet*_*ann 15
以下文档显示,只有渠道所有者才能通过标准YouTube界面执行此操作:https://developers.google.com/youtube/2.0/developers_guide_protocol_captions?hl = zh- CN
廉价修复:您可以单击"交互式转录"按钮 - 并以这种方式复制内容.当然,你会以这种方式失去毫秒.
非常便宜的修复:共享的YouTube帐户 - 以便多人可以编辑和上传字幕文件.
具有挑战性的解决方案:youtube API允许通过HTTP下载和上传字幕文件...您可以编写一个youtube API应用程序,为任何用户或特定用户提供上传或下载的浏览器用户界面.
这是java的一个示例项目 http://apiblog.youtube.com/2011/01/youtube-captions-uploader-web-app.html
以下是每个人工作上传的非常简单的示例:http: //yt-captions-uploader.appspot.com/
(强制性“这可能是youtube.com内部界面,可能随时中断”)
而不是链接到执行此操作的其他工具,而是对“如何执行此操作”问题的解答
我使用了提琴手来检查youtube.com的HTTP流量,并且有一个响应,/api/timedtext其中包含以XML格式显示的隐藏式字幕信息。
似乎是这样的响应:
<p t="0" d="5430" w="1">
<s p="2" ac="136">we've</s>
<s t="780" ac="252"> got</s>
</p>
<p t="2280" d="7170" w="1">
<s ac="243">we're</s>
<s t="810" ac="233"> going</s>
</p>
Run Code Online (Sandbox Code Playgroud)
表示时间0是单词we've,时间0+780是单词got,时间2280+810是单词going,等等。这个时间以毫秒为单位,因此对于时间3090,您要附加&t=3到URL。
您可以使用任何工具将XML拼接在一起以使其易于阅读,但这是我的Power BI Desktop脚本,用于查找诸如“ privilege”之类的词:
let
Source = Xml.Tables(File.Contents("C:\Download\body.xml")),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Attribute:format", Int64.Type}}),
body = #"Changed Type"{0}[body],
p = body{0}[p],
#"Changed Type1" = Table.TransformColumnTypes(p,{{"Attribute:t", Int64.Type}, {"Attribute:d", Int64.Type}, {"Attribute:w", Int64.Type}, {"Attribute:a", Int64.Type}, {"Attribute:p", Int64.Type}}),
#"Expanded s" = Table.ExpandTableColumn(#"Changed Type1", "s", {"Attribute:ac", "Attribute:p", "Attribute:t", "Element:Text"}, {"s.Attribute:ac", "s.Attribute:p", "s.Attribute:t", "s.Element:Text"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Expanded s",{{"s.Attribute:t", Int64.Type}}),
#"Removed Other Columns" = Table.SelectColumns(#"Changed Type2",{"s.Attribute:t", "s.Element:Text", "Attribute:t"}),
#"Replaced Value" = Table.ReplaceValue(#"Removed Other Columns",null,0,Replacer.ReplaceValue,{"s.Attribute:t"}),
#"Filtered Rows" = Table.SelectRows(#"Replaced Value", each [#"s.Element:Text"] <> null),
#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Time", each [#"Attribute:t"] + [#"s.Attribute:t"]),
#"Filtered Rows1" = Table.SelectRows(#"Added Custom", each ([#"s.Element:Text"] = " privilege" or [#"s.Element:Text"] = " privileged" or [#"s.Element:Text"] = " privileges" or [#"s.Element:Text"] = "privilege" or [#"s.Element:Text"] = "privileges"))
in
#"Filtered Rows1"
Run Code Online (Sandbox Code Playgroud)
有一个免费的 Python 工具叫做YouTube 脚本 API
您可以在脚本中或作为命令行工具使用它:
pip install youtube_transcript_api
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
165787 次 |
| 最近记录: |