youtube-dl - 如何将 WebVTT 格式转换为纯文本?

标签 youtube-dl webvtt

这是 WebVTT 的示例

WEBVTT
Kind: captions
Language: en
Style:
::cue(c.colorCCCCCC) { color: rgb(204,204,204);
 }
::cue(c.colorE5E5E5) { color: rgb(229,229,229);
 }
##

00:00:00.060 --> 00:00:03.080 align:start position:0%
 
<c.colorE5E5E5>okay<00:00:00.690><c> so</c><00:00:00.750><c> this</c><00:00:01.319><c> is</c><00:00:01.469><c> a</c></c><c.colorCCCCCC><00:00:01.500><c> newsflash</c><00:00:02.040><c> page</c><00:00:02.460><c> for</c></c>

00:00:03.080 --> 00:00:03.090 align:start position:0%
<c.colorE5E5E5>okay so this is a</c><c.colorCCCCCC> newsflash page for
 </c>

00:00:03.090 --> 00:00:08.360 align:start position:0%
<c.colorE5E5E5>okay so this is a</c><c.colorCCCCCC> newsflash page for</c>
<c.colorE5E5E5>Meraki<00:00:03.659><c> printing</c><00:00:05.120><c> so</c><00:00:06.529><c> all</c><00:00:07.529><c> we</c><00:00:08.040><c> need</c><00:00:08.130><c> to</c><00:00:08.189><c> do</c></c>

00:00:08.360 --> 00:00:08.370 align:start position:0%
<c.colorE5E5E5>Meraki printing so all we need to do
 </c>

00:00:08.370 --> 00:00:11.749 align:start position:0%
<c.colorE5E5E5>Meraki printing so all we need to do
here<00:00:08.700><c> is</c><00:00:08.820><c> to</c><00:00:09.000><c> swap</c><00:00:09.330><c> out</c><00:00:09.480><c> the</c><00:00:09.660><c> logo</c><00:00:09.929><c> here</c><00:00:10.650><c> and</c><00:00:10.830><c> I</c></c>

00:00:11.749 --> 00:00:11.759 align:start position:0%
here is to swap out the logo here<c.colorE5E5E5> and I
 </c>

00:00:11.759 --> 00:00:16.400 align:start position:0%
here is to swap out the logo here<c.colorE5E5E5> and I
should<00:00:11.969><c> also</c><00:00:12.120><c> work</c><00:00:12.420><c> on</c><00:00:12.630><c> move</c><00:00:12.840><c> out</c><00:00:13.049><c> as</c><00:00:13.230><c> well</c><00:00:15.410><c> and</c></c>

00:00:16.400 --> 00:00:16.410 align:start position:0%
<c.colorE5E5E5>should also work on move out as well and
 </c>


我用过 youtube-dl从 YouTube 上抓取它。

我想将其转换为纯文本。我不能在文本重复时去掉时间和颜色标签。

所以我想知道是否存在将其转换为纯文本的东西,或者是否有人可以提供一些伪代码以便我可以对其进行编码?

我还通过 youtube-dl 发布了一个关于此的问题.

最佳答案

我用过 WebVTT-py提取纯文本转录。

import webvtt
vtt = webvtt.read('subtitles.vtt')
transcript = ""

lines = []
for line in vtt:
    # Strip the newlines from the end of the text.
    # Split the string if it has a newline in the middle
    # Add the lines to an array
    lines.extend(line.text.strip().splitlines())

# Remove repeated lines
previous = None
for line in lines:
    if line == previous:
       continue
    transcript += " " + line
    previous = line

print(transcript)

关于youtube-dl - 如何将 WebVTT 格式转换为纯文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51784232/

相关文章:

javascript - 使用 Video.js 从 VTT 章节轨道中获取线索

.net - 使用正则表达式从 webvtt 中提取

HTML5本地播放带字幕的MP4视频

python - 为什么我无法在 python 中使用 youtube-dl 下载 mp4 文件

Python youtube-dl 可以获取合并文件的扩展名吗?

youtube-dl: zsh: 未找到匹配项:

text - 如何在直播中使用 FFMpeg 将 dvb 字幕转换为文本格式,或者如何优化 dvb 刻录过程?

google-chrome - 我可以从 chrome-app 调用 youtube-dl 和 ffmpeg 等 API 吗?

ffmpeg - 将使用 youtube-dl 下载的音频转换为 flac?

ffmpeg - 如何正确转换 ffmpeg 中的 RTL 字幕?