Skip to content
This repository has been archived by the owner on Jun 29, 2018. It is now read-only.

Commit

Permalink
Bug 864765 - Correctly parse SRT files starting with blank lines
Browse files Browse the repository at this point in the history
  • Loading branch information
cinemascop89 authored and ScottDowne committed Feb 5, 2014
1 parent 1f9f449 commit 3325b80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions parsers/parserSRT/data/unit.srt
@@ -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
@@ -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

0 comments on commit 3325b80

Please sign in to comment.