bashawkyoutube-dlwebvtt

Convert WebVTT file from Youtube to plain text


I am downloading WebVTT files from youtube using youtube-dl.

A typical file looks like this:

WEBVTT
Kind: captions
Language: en

00:00:00.730 --> 00:00:05.200 align:start position:0%

[Applause]

00:00:05.200 --> 00:00:05.210 align:start position:0%
[Applause]


00:00:05.210 --> 00:00:11.860 align:start position:0%
[Applause]
hi<00:00:06.440><c> I'm</c><00:00:07.440><c> here</c><00:00:07.740><c> to</c><00:00:08.160><c> talk</c><00:00:08.429><c> to</c><00:00:09.019><c> share</c><00:00:10.019><c> an</c><00:00:10.469><c> idea</c><00:00:10.820><c> to</c>

00:00:11.860 --> 00:00:11.870 align:start position:0%
hi I'm here to talk to share an idea to


00:00:11.870 --> 00:00:15.890 align:start position:0%
hi I'm here to talk to share an idea to
communicate<00:00:12.920><c> but</c><00:00:13.920><c> what</c><00:00:14.790><c> is</c><00:00:14.940><c> communication</c>

00:00:15.890 --> 00:00:15.900 align:start position:0%
communicate but what is communication

I would like to get a text file with this:

hi I'm here to talk to share an idea to
communicate but what is communication

Using code I found online, I got this:

cat output.vtt | sed "s/^[0-9]*[0-9\:\.\ \>\-]*//g" | grep -v "^WEBVTT\|^Kind: cap\|^Language" | awk 'BEGIN{ RS="\n\n+"; RS="\n\n" }NR>=2{ print }' > dialogues.txt

But it is far from perfect. I get a lot of useless spaces, and all the sentences are displayed twice. Would you mind helping me? Somebody asked a similar question before but the answer submitted did not work for me.

Thanks!


Solution

  • You might be able to do something similar to this:

    sed -e '1,4d' -E -e '/^$|]|>$|%$/d' output.vtt | awk '!seen[$0]++' > dialogues.txt
    

    Result:

    hi I'm here to talk to share an idea to
    communicate but what is communication 
    

    You might have to tweak it a bit, although it should result in more along the lines of what you want.