forked from mozilla/popcorn-js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Text parsing completed. Styles remain [mozilla#291]
- Loading branch information
Showing
6 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
1 | ||
00:00:02.400 --> 00:00:07.200 | ||
Senator, we're making | ||
our final approach into Coruscant. | ||
|
||
2 | ||
00:00:9.712 --> 00:00:13.399 | ||
Very good, Lieutenant. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
1 | ||
00:00:02.400 --> 00:00:07.200 | ||
Senator, we're making | ||
our final approach into Coruscant. | ||
|
||
2 | ||
00:9.712 --> 00:13.399 | ||
Very good, Lieutenant. | ||
|
||
Track-3 | ||
00:00:15.042 --> 00:00:18.042 A:start D:vertical L:98% | ||
It's a trap! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Popcorn 0.3 VTT parser Plug-in Demo</title> | ||
|
||
<script src="../../popcorn.js"></script> | ||
<script src="../../plugins/subtitle/popcorn.subtitle.js"></script> | ||
<script src="../../parsers/parserVTT/popcorn.parserVTT.js"></script> | ||
|
||
</head> | ||
<body> | ||
<h1 id="qunit-header">Popcorn 0.3 VTT parser Plug-in Demo</h1> | ||
<p></p> | ||
<div> | ||
<video id='video' data-timeline-sources="data/data.vtt" | ||
controls | ||
width= '250px' | ||
poster="../../test/poster.png"> | ||
|
||
<source id='mp4' | ||
src="../../test/trailer.mp4" | ||
type='video/mp4; codecs="avc1, mp4a"'> | ||
|
||
<source id='ogv' | ||
src="../../test/trailer.ogv" | ||
type='video/ogg; codecs="theora, vorbis"'> | ||
|
||
<p>Your user agent does not support the HTML5 Video element.</p> | ||
|
||
</video> | ||
</div> | ||
|
||
<style> | ||
.displays { | ||
width: 300px; | ||
height: 300px; | ||
} | ||
</style> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// PARSER: 0.3 VTT | ||
|
||
(function (Popcorn) { | ||
Popcorn.parser( "parseVTT", "VTT", function( data ) { | ||
|
||
// declare needed variables | ||
var retObj = { | ||
title: "", | ||
remote: "", | ||
data: [] | ||
}, | ||
subs = [], | ||
lines, | ||
i = 0, l = 0; | ||
|
||
// [HH]:MM:SS.mmm string to SS.mmm | ||
var toSeconds = function(t_in) { | ||
var t = t_in.split(':'); | ||
var time, l = t.length-1; | ||
|
||
try { | ||
time = parseInt(t[l-1], 10)*60 + parseFloat(t[l], 10); | ||
|
||
if (l === 2) // Hours given | ||
time += parseInt(t[0], 10)*60*60; // hours => seconds | ||
} catch (e) { throw "Bad cue"; } | ||
|
||
return time; | ||
}; | ||
|
||
var createTrack = function( name, attributes ) { | ||
var track = {}; | ||
track[name] = attributes; | ||
return track; | ||
}; | ||
|
||
// Here is where the magic happens | ||
lines = data.text.replace("\r",'').split("\n"); | ||
l = lines.length; | ||
|
||
while (i < l) { | ||
var sub = {}; | ||
|
||
sub.id = lines[i++].replace('\r', ''); | ||
|
||
var time = lines[i++].split(" --> "); | ||
var text = []; | ||
|
||
try { | ||
sub.start = toSeconds(time[0]); | ||
|
||
// Filter out any trailing styling info | ||
time[1] = time[1].replace("\r", " "); | ||
sub.end = toSeconds(time[1].substr(0, time[1].indexOf(" "))); | ||
|
||
while (lines[i] && lines[i] !== "\r") { | ||
text.push(lines[i++].replace("\r", "")); | ||
} | ||
|
||
sub.text = text.join(" "); | ||
subs.push( createTrack("subtitle", sub) ); | ||
} catch (e) { // Bad cue | ||
while (i < l && !lines[i++] !== "\r"); // Advance to end of cue | ||
} | ||
|
||
// Consume empty whitespace | ||
while (i < l && !lines[i++] === "\r"); | ||
} | ||
|
||
retObj.data = subs; | ||
|
||
return retObj; | ||
}); | ||
|
||
})( Popcorn ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Popcorn 0.3 VTT parser Plug-in Test</title> | ||
<link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen"> | ||
<script src="../../test/qunit/qunit.js"></script> | ||
<!-- | ||
do not move - this must be called immediately prior to | ||
popcorn-api-draft.js | ||
--> | ||
|
||
<script src="../../popcorn.js"></script> | ||
|
||
<script src="popcorn.parserVTT.js"></script> | ||
<script src="../../plugins/subtitle/popcorn.subtitle.js"></script> | ||
<script src="popcorn.parserVTT.unit.js"></script> | ||
</head> | ||
<body> | ||
<h1 id="qunit-header">Popcorn 0.3 VTT parser Plug-in Test</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<div id="qunit-testrunner-toolbar"></div> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
<div id="qunit-fixture"> </div> | ||
|
||
<video id='video' | ||
controls | ||
width= '250px' | ||
poster="../../test/poster.png"> | ||
|
||
<source id='mp4' | ||
src="../../test/trailer.mp4" | ||
type='video/mp4; codecs="avc1, mp4a"'> | ||
|
||
<source id='ogv' | ||
src="../../test/trailer.ogv" | ||
type='video/ogg; codecs="theora, vorbis"'> | ||
|
||
<p>Your user agent does not support the HTML5 Video element.</p> | ||
|
||
</video> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
test("Popcorn 0.3 VTT Parser Plugin", function () { | ||
|
||
var count = 0, | ||
numSubs = 0, | ||
sub, | ||
poppercorn = Popcorn( "#video" ), | ||
subs = { // Expected values | ||
"1": { | ||
text: "Senator, we're making our final approach into Coruscant.", | ||
start: 2.4, | ||
end: 7.2 | ||
}, | ||
"2": { | ||
text: "Very good, Lieutenant.", | ||
start: 9.712, | ||
end: 13.399 | ||
}, | ||
"Track-3": { | ||
text: "It's a trap!", | ||
start: 15.042, | ||
end: 18.042 | ||
} | ||
}, | ||
expectSubs = 3, | ||
expects = expectSubs*4 + 1; | ||
|
||
function plus() { | ||
if ( ++count === expects ) { | ||
start(); | ||
} | ||
} | ||
|
||
poppercorn.parseVTT("data/unit.vtt"); | ||
|
||
expect(expects); | ||
|
||
stop( 5000 ); | ||
|
||
// Allow load time | ||
setTimeout(function () { | ||
Popcorn.forEach(poppercorn.getTrackEvents(), function(evt) { | ||
if(evt._natives.type === "subtitle") { | ||
numSubs++; | ||
sub = subs[evt.id.toString()]; | ||
|
||
ok(!!sub , "Correctly parsed id of " + evt.id ); | ||
plus(); | ||
equals(evt.text, sub.text, "Correctly parsed text of " + evt.id ); | ||
plus(); | ||
equals(evt.start, sub.start, "Correctly parsed start at " + evt.id ); | ||
plus(); | ||
equals(evt.end, sub.end, "Correctly parsed end at " + evt.id ); | ||
plus(); | ||
} | ||
}); | ||
|
||
equals(expectSubs, numSubs , "Parsed all subs" ); | ||
plus(); | ||
|
||
}, 500); | ||
|
||
}); |