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

subtitle-convert

v0.3.6

Published

Subtitle converter from traditional subtitle extention.

Downloads

3

Readme

subtitle-convert

npm version Build Status

Subtitle converter from traditional subtitles.
It automatically detects file encoding and easily convert to other file encoding with different subtitle type.
eg.) SMI(EUC-KR) -> WEBVTT(UTF-8)

At 0.2.0, it only supports SMI and VTT only. Please check Future Works section.

Install

> npm install --save subtitle-convert
// or
> yarn add subtitle-convert

Usage

Node

// In node.js,

// in ES Style..
import Converter from 'subtitle-convert';

// in Common Style..
const Converter = require('subtitle-convert').default;

// Default initialize and load files.
const smi2vtt = new Converter();

smi2vtt.load(filePath);

/* Or you may write specific encoding of input and output.
 In this case, converter automatically parse extension so you don't have to set
 extname to file extension obviously unless you're going to change it. So, */
const smi2vtt = new Converter(filePath, extname, inputEncoding, outputEncoding);
// or just null.
const smi2vtt = new Converter(filePath, null, inputEncoding, outputEncoding);
// These two case of initialization step, converter automatically calls load function.

// Parse from raw file.
smi2vtt.parse();

// You may add delay(seconds) to each cue separately.
smi2vtt.delay(delayTime, cueIndex);

// You can set range of delay like below -
smi2vtt.delay(delayTime, cueIndex, cueIndexEnd);

// If you set cueIndexEnd to -1, converter automatically interpretes to last index of cue list.
smi2vtt.delay(delayTime, cueIndex, -1);

// Or add delay to entire cueList.
smi2vtt.delay(delayTime);

// These two statements are equivalent :
smi2vtt.delay(-12.3); // 12.3 seconds faster.
smi2vtt.delay('-12.3'); // 12.3 seconds faster too.

// You may resize instead of delay. It just resizes endTime of cue. Usage of .resize is very similar to .delay.
// Actually, .resize(...args) is equivalent to .delay(...args, true).
smi2vtt.resize(delayTime); // equivalent to .delay(delayTime, null, null, true).
smi2vtt.resize(delayTime, cueIndex); // equivalent to .delay(delayTime, cueIndex, null, true).
smi2vtt.resize(delayTime, cueIndex, cueIndexEnd); // equivalent to .delay(delayTime, cueIndex, cueIndexEnd, true).

/* Convert parsed data to chosen type.
 Then parser will create an new file in destination with specific encoding.
 At 0.2.0, only VTT supported.
 Both two cases, result variable get result of conversion if succeed or get false. */
const result = smi2vtt.convert('.vtt', outputFilePath);
// Without saving file.
const result = smi2vtt.convert('.vtt');

Browser

// In browser,

// All of methods are same, but you should set string that contains subtitle details
// instead of filepath.
const smi2vtt = new Converter(textofSubtitle);

// You may push TextTrackCueList array to converter to modify track cue list.
smi2vtt.apply(cueList); // cueList overwritten to converter's cue list.

// You may skip to call parse method if you need only just conversion.
const result = smi2vtt.convert('.vtt');

Result

WEBVTT

...

STYLE
::cue(.style2) {
	color: #8BC3FF;
}

STYLE
::cue(.style3) {
	color: #ff3939;
}

0
00:00:10.000 --> 00:00:10.700
<c.style0>[ 르네상스 시대 3대 발명 ]
나침반, 화약, 활판 인쇄</c>


1
00:00:10.700 --> 00:00:11.900
<c.style0>[ 르네상스 시대 3대 발명 ]
나침반, 화약, <u>활판 인쇄</u></c>
그러한 연유로-

Tips

When you using vtt files with Chrome browser you may confused because they won't support vtt inline css style.
In this module, convert function automatically supports for css hack with WEBVTT comment(called NOTE) like below-

WEBVTT

NOTE
STYLE_START
/* For not-supported browser only.
 Paste this part to head style using xhr. */
video::cue(.style0) {
	color: #A4A0A0;
}
video::cue(.style1) {
	color: #F8B203;
}
video::cue(.style2) {
	color: #8BC3FF;
}
video::cue(.style3) {
	color: #ff3939;
}
/* End of inner css. */
STYLE_END

STYLE
::cue(.style0) {
	color: #A4A0A0;
}

...

You may use to parse these parts to put in your own head style to apply subtitle style in Chrome.

Test

> npm test
// or
> yarn test

Future Works

-Aegisub, srt support.
-Output encoding.
-VTT Fully support (At 0.2.0, it only supports essentials.)

License

MIT