Xi Xiao
Xi Xiao

Reputation: 973

Get all cues and their properties from a vtt file in nodejs

Say, I have a vtt file from which I want to get all the cues and their associated properties, such as startTime, endTime etc, in nodejs environment.

I have searched by all keywords I can come up with, like 'parse vtt file by javascript', but the results are all about mozilla/vtt.js. But I don't need to interact with browser/window, it is only a static vtt file that I need to extract data from by JavaScript.

Could somebody give me some hint? Thanks!

sample vtt content:

WEBVTT FILE

1
00:00:03.500 --> 00:00:05.000 D:vertical A:start
Everyone wants the most from life

2
00:00:06.000 --> 00:00:09.000 A:start
Like internet experiences that are rich <b>and</b> entertaining

3
00:00:11.000 --> 00:00:14.000 A:end
Phone conversations where people truly <c.highlight>connect</c>

4
00:00:14.500 --> 00:00:18.000
Your favourite TV programmes ready to watch at the touch of a button

5
00:00:19.000 --> 00:00:24.000
Which is why we are bringing TV, internet and phone together in <c.highlight>one</c> super package

6
00:00:24.500 --> 00:00:26.000
<c.highlight>One</c> simple way to get everything

7
00:00:26.500 --> 00:00:27.500 L:12%
UPC

8
00:00:28.000 --> 00:00:30.000 L:75%
Simply for <u>everyone</u>

Upvotes: 4

Views: 2338

Answers (2)

priyanka singh
priyanka singh

Reputation: 111

You can make use of the npm package node-webvtt

npm install node-webvtt
import * as webvtt from "node-webvtt" //if you are using typescript
const parsed = webvtt.parse("Your text")

This will give you the below:

parsed vtt

Reference: https://www.npmjs.com/package/node-webvtt

Upvotes: 6

Xi Xiao
Xi Xiao

Reputation: 973

this one helped me https://www.npmjs.com/package/vtt-to-json it can parse the vtt to json, with which I can get all properties/values.

Upvotes: 1

Related Questions