最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get all cues and their properties from a vtt file in nodejs - Stack Overflow

programmeradmin0浏览0评论

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 e 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>

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 e 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>
Share Improve this question asked Jun 15, 2017 at 8:35 Xi XiaoXi Xiao 9731 gold badge12 silver badges30 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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:

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

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

发布评论

评论列表(0)

  1. 暂无评论