From 70ebd6f36e19e31fad2e98980919f9566285be7d Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 1 Feb 2014 00:15:35 -0200 Subject: [PATCH] Bug 864765 - Correctly parse SRT files starting with blank lines --- parsers/parserSRT/data/unit.srt | 2 ++ parsers/parserSRT/popcorn.parserSRT.js | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/parsers/parserSRT/data/unit.srt b/parsers/parserSRT/data/unit.srt index c9735a6d9..5f6e5636e 100644 --- a/parsers/parserSRT/data/unit.srt +++ b/parsers/parserSRT/data/unit.srt @@ -1,3 +1,5 @@ + + 1 00:00:02.400 --> 00:00:05.200 [Background Music Playing] diff --git a/parsers/parserSRT/popcorn.parserSRT.js b/parsers/parserSRT/popcorn.parserSRT.js index c6427c622..9d1d34c56 100644 --- a/parsers/parserSRT/popcorn.parserSRT.js +++ b/parsers/parserSRT/popcorn.parserSRT.js @@ -1,7 +1,7 @@ // 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 @@ -9,12 +9,12 @@ * SSA-style tags are stripped, HTML style tags are left for the browser to handle: * HTML: , , , , * 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 @@ -52,6 +52,7 @@ sub = {}; text = []; + i = nextNonEmptyLine( lines, i ); sub.id = parseInt( lines[i++], 10 ); // Split on '-->' delimiter, trimming spaces as well @@ -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, ">" ); @@ -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;