Skip to content
This repository was archived by the owner on Jun 29, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions parsers/parserSRT/data/unit.srt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


1
00:00:02.400 --> 00:00:05.200
[Background Music Playing]
Expand Down
19 changes: 14 additions & 5 deletions parsers/parserSRT/popcorn.parserSRT.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// PARSER: 0.3 SRT
(function (Popcorn) {
/**
* SRT popcorn parser plug-in
* SRT popcorn parser plug-in
* Parses subtitle files in the SRT format.
* Times are expected in HH:MM:SS,MIL format, though HH:MM:SS.MIL also supported
* Ignore styling, which may occur after the end time or in-text
* While not part of the "official" spec, majority of players support HTML and SSA styling tags
* SSA-style tags are stripped, HTML style tags are left for the browser to handle:
* HTML: <font>, <b>, <i>, <u>, <s>
* SSA: \N or \n, {\cmdArg1}, {\cmd(arg1, arg2, ...)}

* Data parameter is given by Popcorn, will need a text.
* Text is the file contents to be parsed
*
*
* @param {Object} data
*
*
* Example:
1
00:00:25,712 --> 00:00:30.399
Expand Down Expand Up @@ -52,6 +52,7 @@
sub = {};
text = [];

i = nextNonEmptyLine( lines, i );
sub.id = parseInt( lines[i++], 10 );

// Split on '-->' delimiter, trimming spaces as well
Expand All @@ -74,7 +75,7 @@
// Join into 1 line, SSA-style linebreaks
// Strip out other SSA-style tags
sub.text = text.join( "\\N" ).replace( /\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}/gi, "" );

// Escape HTML entities
sub.text = sub.text.replace( /</g, "&lt;" ).replace( />/g, "&gt;" );

Expand Down Expand Up @@ -115,6 +116,14 @@
}
}

function nextNonEmptyLine( linesArray, position ) {
var idx = position;
while ( !linesArray[idx] ) {
idx++;
}
return idx;
}

function lastNonEmptyLine( linesArray ) {
var idx = linesArray.length - 1;

Expand Down