📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

@plussub/srt-vtt-parser

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@plussub/srt-vtt-parser

A dependency free SRT / Vtt subtitle parser, written in Typescript.

2.0.5
latest
Source
npm
Version published
Maintainers
0
Created
Source

SRT/VTT Parser

A dependency-free SRT/VTT subtitle parser, written in TypeScript.

Installation

npm i @plussub/srt-vtt-parser

Usage

import fs from 'fs';
import { parse } from '@plussub/srt-vtt-parser';

const { entries } = parse(
  fs
    .readFileSync('transcript.vtt') // or '.srt'
    .toString()
);

entries.forEach(({ from, to, text, id }) => {
  // process transcript entry
});

Examples

SRT (SubRip)

00:01:42,821 --> 00:01:44,289
(SIREN WAILING IN DISTANCE)
multiline test

2
00:01:45,365 --> 00:01:48,084
<i>DRIVER: There's 100,000 streets in this city.</i>

3
00:01:49,077 --> 00:01:51,421
You don't need to know the route.

VTT

WEBVTT

1
00:01:42.821 --> 00:01:44.289
(SIREN WAILING IN DISTANCE)
multiline test

2
00:01:45.365 --> 00:01:48.084
<i>DRIVER: There's 100,000 streets in this city.</i>

3
00:01:49.077 --> 00:01:51.421
You don't need to know the route.

Results into

{
  "entries": [
    {
      "from": 102821,
      "id": "1",
      "text": "(SIREN WAILING IN DISTANCE)\nmultiline test",
      "to": 104289
    },
    {
      "from": 105365,
      "id": "2",
      "text": "<i>DRIVER: There's 100,000 streets in this city.</i>",
      "to": 108084
    },
    {
      "from": 109077,
      "id": "3",
      "text": "You don't need to know the route.",
      "to": 111421
    }
  ]
}

Respect NOTE/ MULTILINE NOTE / STYLE Blocks and inline style but will ignore them for the output.

WEBVTT

STYLE
::cue {
  background-image: linear-gradient(to bottom, dimgray, lightgray);
  color: papayawhip;
}
/* Style blocks cannot use blank lines nor "dash dash greater than" */

NOTE comment blocks can be used between style blocks.

00:01:42.821 --> 00:01:44.289
(SIREN WAILING IN DISTANCE)
multiline test

NOTE style blocks cannot appear after the first cue.
this is a multiline note block

some identifier
00:01:45.365 --> 00:01:48.084
<i>DRIVER: There's 100,000 streets in this city.</i>


00:01:49.077 --> 00:01:51.421
You don't need to know the route.

Results into

{
  "entries": [
    {
      "from": 102821,
      "id": "",
      "text": "(SIREN WAILING IN DISTANCE)\nmultiline test",
      "to": 104289
    },
    {
      "from": 105365,
      "id": "some identifier",
      "text": "<i>DRIVER: There's 100,000 streets in this city.</i>",
      "to": 108084
    },
    {
      "from": 109077,
      "id": "",
      "text": "You don't need to know the route.",
      "to": 111421
    }
  ]
}

Keywords

vtt

FAQs

Package last updated on 29 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts