1.0.1 • Published 6 years ago
subtools v1.0.1
subtools
Advanced SRT subtitles parser.
Getting started
Prerequisites
- NodeJS
- NPM
- Yarn
Install
From npm
yarn add subtools
or
npm i subtools
Use
The SRT format

Source : 3PlayMedia
Import module
const subtools = require('subtools');Import subtitles
From variable
const mySubtitles = new subtools.Sub(body);bodystring - Your subtitles in SRT format
From file
const mySrtFile = new subtools.SubFile(file, encoding);filestring - Path to *.srt fileencodingstring (optional) - File encoding Default :utf-8
Sub class
subtitlesarray - List ofSubtitleinstancessentencesarray - List ofSentenceinstancesgetSubtitlefunction - Get subtitle -keyinteger - Subtitle keyprintfunction - Export subtitles to variablewritefunction - Export subtitles to file -filestring - Path to file
SubFile class (inherits from Sub)
Sub class properties and methods +
filestring - Path to *.srt filewritefunction - Export subtitles to file -filestring - Path to file Default : initial file path
Subtitle class
keyinteger - SRT keybegintime -Dateinstance matching SRT begin timecodeendtime -Dateinstance matching SRT end timecodetextstring - SRT text, newlines removedsentencesarray - List ofSentencepartially or entirely present in subtitlegetPrevfunction - Get previous subtitlegetNextfunction - Get next subtitlesetTextfunction - Change subtitle text and auto adapt timecodesaddTextfunction - Append text to subtitle body -positioninteger - Substring indexremoveTextfunction - Remove text from subtitle body -startinteger - Substring start index -endinteger - Substring end indexprintfunction - Export individual subtitle item to variable
Sentence class
subtitlesarray - List ofSubtitlepartially or entirely containing the sentencetextstring - Sentence bodypositioninteger - Substring index of sentence in subtitle textsetTextfunction - Change sentence text and auto-update relatedSubtitleinstances
Planned features
I designed this module to make subtitle translations easier with sentence context. However, I'll add more features that common subtitles tools modules have.
Changelog
1.0.1(2019-05-11) • Initial release