srtparse
v0.0.8
Published
Easy parsing of .srt ([SubRip Text](https://wikipedia.org/wiki/SubRip)) subtitle files.
Downloads
2
Readme
srtparse
Easy parsing of .srt (SubRip Text) subtitle files.
Usage
- Import the module and you can get access to the
FileParser
class. - Initialise a
FileParser
with the path to your subtitle file and callparse()
. - You get a promise which resolves when parsing is complete, at which point your
FileParser
will be populated with subtitles, accessible viagetSubtitles()
.
// Require FileParser
var srt = require('srtparse');
// Create a new FileParser
var fp = new srt.FileParser('/path/to/my/file.srt');
// Parse file
fp.parse().then(function () {
console.log('Parsed ' + fp.getSubtitles().length + ' subtitles!');
}).catch(console.error);
Reference
FileParser
FileParser(String pathToSRT)
Initialise a new FileParser
with a path to your SRT file.
getFilePath() -> String
Return the file path you initialised the FileParser
with.
getSubtitles() -> [Subtitle]
Return the list of parsed Subtitle
instances after parsing.
parse() -> Promise([Subtitle])
Promises to parse the entire file which you gave the FileParser
on initialisation.
Also resolves with the parsed Subtitles for ease of access.
Subtitle
Subtitle()
Initialise a new empty Subtitle
instance.
getEndTime() -> Time
Return this subtitle's start time as a Time
instance.
getIndex() -> Number
Return this subtitle's index number.
getText() -> [String]
Return this subtitle's text as an array of strings, each representing one line in the SRT.
getTextAsString() -> String
Return this subtitle's text list as a newline-joined string.
getEndTime() -> Time
Return this subtitle's end time as a Time
instance.
addText(String textLine)
Add a line of text to this subtitle's text list.
setText([String] textLines)
Set this subtitle's text list to the given one.
setEndTime(Time endTime)
Set this subtitle's end time to the given Time
.
setIndex(Number index)
Set this subtitle's index number to the given one.
setStartTime(Time startTime)
Set this subtitle's start time to the given Time
.
toSRTString() -> String
Returns a representation of this subtitle ready for insertion into a .srt file.
zero() -> Subtitle
Return a new Subtitle
instance which is a duplicate of this one, but with start time
at 00:00:00,000, end time adjusted accordingly to keep the same duration, and index
set to 1. Does not modify this instance.
Time
Time(Number|String hour, Number|String minute, Number|String second, Number|String milli)
Initialise a new Time
instance with the given values.
[static] Time.fromSeconds(Number seconds) -> Time
Create a new Time
instance from a given number of seconds. For example,
Time.fromSeconds(3661.111)
would give the time 01:01:01,111.
getHour() -> Number
Return this Time
instance's hour.
getMilli() -> Number
Return this Time
instance's milliseconds.
getMinute() -> Number
Return this Time
instance's minute.
getSecond() -> Number
Return this Time
instance's second.
toSeconds() -> Number
Return this Time
as an absolute number of seconds (including milliseconds).
toSRTString() -> String
Return this time in its SRT representation (eg 12:34:56,789).