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 FileParservar srt = ; // Create a new FileParservar fp = '/path/to/my/file.srt';// Parse filefp;
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.
Subtitle]
getSubtitles() -> [Return the list of parsed Subtitle
instances after parsing.
Subtitle])
parse() -> Promise([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.
Time
getEndTime() ->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.
Time
getEndTime() ->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.
Time endTime)
setEndTime(Set this subtitle's end time to the given Time
.
setIndex(Number index)
Set this subtitle's index number to the given one.
Time startTime)
setStartTime(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.
Subtitle
zero() ->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.
Time
[static] Time.fromSeconds(Number seconds) ->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).