npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parallelizer

v1.3.3

Published

Library to parallelize subtitles (.srt)

Downloads

14

Readme

subtitles-parallelizer (WIP)

A javascript library to easily work with subtitles (.srt). It helps to parse and easily process subtitles!

Installation

npm install parallelizer or yarn add parallelizer

Example

Imagine, we downloaded subtitles with name movie.srt. For instance, to parse a movie trascript to work with this in the further future.

The API of subtitles-parallelizer or simply parallelizer is pretty simple. Without further ado, let's get to the point and take a look at an example.

1
00:00:01,000 --> 00:00:05,000
Subtitle 1.1
Subtitle 1.2

2
00:00:30,500 --> 01:30:00,000
Subtitle 2.1
Subtitle 2.2
Happy end 2.3
  1. Load file or get subtitles from third-party services and put them into a variable
import { promises as fs } from "fs";
import * as parallelizer from "parallelizer";

const run = async () => {
  const fileContent = await fs.readFile("movie.srt", "utf8");
  const sections = parallelizer.parse(text);

  console.log(sections);
};

run();

There we go, this is how our sections data array looks like

[
  {
    id: 1,
    startTime: '00:00:01',
    endTime: '00:00:05',
    startTimeWithMs: '00:00:01,000',
    endTimeWithMs: '00:00:05,000',
    content: 'Subtitle 1.1\n    Subtitle 1.2'
  },
  {
    id: 2,
    startTime: '00:00:30',
    endTime: '01:30:00',
    startTimeWithMs: '00:00:30,500',
    endTimeWithMs: '01:30:00,000',
    content: 'Subtitle 2.1\n    Subtitle 2.2\n    Happy end 2.3'
  }
]

API

parse

The function takes subtitles text in srt format and returns sections as an array of objects

| Param | Description | | ----- | --------------------------------------------- | | text | subtitles text to parse into array of objects |

Example

 const subtitles = `
 1
    00:00:01,000 --> 00:00:05,000
    Subtitle 1.1
    Subtitle 1.2
    `
 parse(subtitles)

 // output
 [
      {
        id: 1,
        startTime: '00:00:01',
        endTime: '00:00:05',
        startTimeWithMs: '00:00:01,000',
        endTimeWithMs: '00:00:05,000',
        content: 'Subtitle 1.1\nSubtitle 1.2'
      },
    ]

parseBoth

The function takes settings and returns two parallelized subtitles (for instance, to parallelize two different subtitles in different languages)

Returns: the tuple (array with two items), where items are the data structures of the same output as the parse function returns

| Param | Description | | ------------------------ | ----------------------------------------- | | settings | Settings to parallelize two subtitles | | settings.start | The start time in the each subtitles file | | settings.end | The end time in the each subtitles file | | settings.firstSubtitles | The first subtitles text | | settings.secondSubtitles | The second subtitles text |

parseByName

The function takes name and subtitles text to find a word or a phrase in each section's content of the subtitles The function takes a third argument as offset object to widen array of objects left or right or both

Returns: array of objects (sections) like parse function does

| Param | Type | Description | | ------ | ------------------- | --------------------------- | | name | | A word or phrase to find | | text | | The text to parse | | offset | Object | Offset configuration object |

parseByTimestamp

The function takes subtitles text, start and end time to get sections between specific timestamps

Returns: the same array of objects as parse function does

| Param | Description | | ----- | ------------------- | | text | The text to parse | | start | The start timestamp | | end | The end timestamp |

srtTimeToSeconds

The function takes time in srt format (such as 00:01:00,200) and returns seconds

| Param | Description | | ----- | ------------------------------ | | time | srt time to convert in seconds |

Example

srtTimeToSecond("00:01:30,000"); // 90

secondsToSrtTime

The function is the opposite of the srtTimeToSeconds function it takes time in seconds and returns a string in srt time format

| Param | Description | | ------- | ------------------------------------ | | seconds | convert seconds into srt time format |

Example

secondsToSrtTime(90); // "00:01:30,000"

resync

The function resynchonizes subtitles

| Param | Description | | --------- | ------------------------------------------------------ | | subtitles | array of objects that parse function produces | | time | offset time (you can use negative value for flexibity) |

Example

const unresyncedSubtitles = [
  {
    id: 1,
    content: "a lot of text",
    startTime: "00:00:26",
    endTime: "00:00:29",
    startTimeWithMs: "00:00:26,500",
    endTimeWithMs: "00:00:29,461",
  },
  {
    id: 2,
    content: "a lot of text",
    startTime: "00:00:29",
    endTime: "00:00:36",
    startTimeWithMs: "00:00:29,500",
    endTimeWithMs: "00:00:36,461",
  },
];

resync(unresyncedSubtitles, 2000);