Socket
Socket
Sign inDemoInstall

srtparsejs

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    srtparsejs

A javascript srt text parser and player.


Version published
Weekly downloads
71
decreased by-18.39%
Maintainers
1
Install size
24.3 kB
Created
Weekly downloads
 

Readme

Source

srt-parse.js

A javascript srt text parser and player.

Install

$ npm install srtparsejs

or

$ yarn add srtparsejs

parse Example

import * as srtparsejs from "srtparsejs"; // cjs
const srtparsejs = require('srtparsejs'); // esm

let srt = `
1
00:00:11,544 --> 00:00:12,682
Hello
`
let parsed = srtparsejs.parse(srt)
console.log(parsed)
/*
[{
    id: '1',
    startTime: '00:00:11,544',
    endTime: '00:00:12,682',
    text: 'Hello' 
}]
*/

let srtString = srtparsejs.toSrt(parsed)
console.log(srtString)
/*
1
00:00:11,544 --> 00:00:12,682
Hello
`
*/

srtPlayer Usage

// Display the text of each subtitle by time
let srtPlayer = srtparsejs.setPlayer(parsed, text=>{
    console.log(text)
})

// Move player to this time
srtPlayer.update("00:00:11,544") 

// Get subtitle end time
console.log(srtPlayer.getEndTime())
//control the player
let pause = false

//srt player check interval
let interval = 100

//parse srt
let srtArray = srtparsejs.parse(srt)

//start millisecond
let ms = 0

//create player
let player = srtparsejs.setPlayer(srtArray, text => {
    //here to display the text
    console.log(text)
})

//update srt player time
setInterval(() => {
    if (pause) return;
    ms += interval
    //update to specific time
    player.update(srtparsejs.toTime(ms))
}, interval)

Keywords

FAQs

Last updated on 05 Nov 2022

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc