зеркало из https://github.com/mozilla/popcorn-js.git
[#289] Documented, expanded tests
This commit is contained in:
Родитель
818ce17b49
Коммит
1cb1e319be
|
@ -11,8 +11,12 @@
|
||||||
<body>
|
<body>
|
||||||
<h1 id="qunit-header">Popcorn 0.3 TTXT parser Plug-in Demo</h1>
|
<h1 id="qunit-header">Popcorn 0.3 TTXT parser Plug-in Demo</h1>
|
||||||
<p>Subtitles are processed from <a href="data/data.TTXT">here</a></p>
|
<p>Subtitles are processed from <a href="data/data.TTXT">here</a></p>
|
||||||
|
<p>From 2.4 to 5.2 seconds, "[Background Music Playing]" is shown</p>
|
||||||
|
<p>From 15.712 to 17.399 seconds, "Heay!!" is shown</p>
|
||||||
|
<p>From 25.712 to 30.399 seconds, "[Bird noises]" is shown</p>
|
||||||
<div>
|
<div>
|
||||||
<video id='video' data-timeline-sources="data/data.TTXT"
|
<video id='video'
|
||||||
|
data-timeline-sources="data/data.TTXT"
|
||||||
controls
|
controls
|
||||||
width= '250px'
|
width= '250px'
|
||||||
poster="../../test/poster.png">
|
poster="../../test/poster.png">
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// Simple function to convert HH:MM:SS.MMM to SS.MMM
|
// Simple function to convert HH:MM:SS.MMM to SS.MMM
|
||||||
|
// Assume valid, returns 0 on error
|
||||||
var toSeconds = function(t_in) {
|
var toSeconds = function(t_in) {
|
||||||
var t = t_in.split(":");
|
var t = t_in.split(":");
|
||||||
var time = 0;
|
var time = 0;
|
||||||
|
@ -44,20 +45,21 @@
|
||||||
|
|
||||||
// this is where things actually start
|
// this is where things actually start
|
||||||
var node = data.xml.lastChild.lastChild; // Last Child of TextStreamHeader
|
var node = data.xml.lastChild.lastChild; // Last Child of TextStreamHeader
|
||||||
var lastStart = 3.4028235e+38;
|
var lastStart = Number.MAX_VALUE;
|
||||||
var cmds = [];
|
var cmds = [];
|
||||||
|
|
||||||
|
// Work backwards through DOM, processing TextSample nodes
|
||||||
while (node) {
|
while (node) {
|
||||||
if ( node.nodeType === 1 && node.nodeName === "TextSample") {
|
if ( node.nodeType === 1 && node.nodeName === "TextSample") {
|
||||||
var sub = {};
|
var sub = {};
|
||||||
sub.start = toSeconds(node.getAttribute('sampleTime'));
|
sub.start = toSeconds(node.getAttribute('sampleTime'));
|
||||||
sub.text = node.getAttribute('text');
|
sub.text = node.getAttribute('text');
|
||||||
|
|
||||||
// Infer end time, ms accuracy
|
// Infer end time from prior element, ms accuracy
|
||||||
sub.end = lastStart;
|
sub.end = lastStart - 0.001;
|
||||||
|
|
||||||
cmds.push( createTrack("subtitle", sub) );
|
cmds.push( createTrack("subtitle", sub) );
|
||||||
lastStart = sub.start - 0.001;
|
lastStart = sub.start;
|
||||||
}
|
}
|
||||||
node = node.previousSibling;
|
node = node.previousSibling;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,47 @@
|
||||||
test("Popcorn 0.3 TTXT Parser Plugin", function () {
|
test("Popcorn 0.3 TTXT Parser Plugin", function () {
|
||||||
|
|
||||||
var expects = 8,
|
var expects = 0,
|
||||||
count = 0,
|
count = 0,
|
||||||
|
sub = {},
|
||||||
numSubs = 0,
|
numSubs = 0,
|
||||||
poppercorn = Popcorn( "#video" ),
|
poppercorn = Popcorn( "#video" ),
|
||||||
subs = { // Expected values
|
subs = [ // Expected values
|
||||||
"0": "",
|
{
|
||||||
"2.4": "[Background Music Playing]",
|
start: 0,
|
||||||
"5.2": "",
|
end: 2.399,
|
||||||
"15.712": "Heay!!",
|
text: ""
|
||||||
"17.399": "",
|
},
|
||||||
"25.712": "[Bird noises]",
|
{
|
||||||
"30.399": ""
|
start: 2.4,
|
||||||
};
|
end: 5.199,
|
||||||
|
text: "[Background Music Playing]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 5.2,
|
||||||
|
end: 15.711,
|
||||||
|
text: ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 15.712,
|
||||||
|
end: 17.398,
|
||||||
|
text: "Heay!!"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 17.399,
|
||||||
|
end: 25.711,
|
||||||
|
text: ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 25.712,
|
||||||
|
end: 30.398,
|
||||||
|
text: "[Bird noises]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 30.399,
|
||||||
|
end: Number.MAX_VALUE,
|
||||||
|
text: ""
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
function plus() {
|
function plus() {
|
||||||
if ( ++count === expects ) {
|
if ( ++count === expects ) {
|
||||||
|
@ -22,6 +51,7 @@ test("Popcorn 0.3 TTXT Parser Plugin", function () {
|
||||||
|
|
||||||
poppercorn.parseTTXT(document.getElementById('video').getAttribute('data-timeline-sources'));
|
poppercorn.parseTTXT(document.getElementById('video').getAttribute('data-timeline-sources'));
|
||||||
|
|
||||||
|
expects = subs.length*3+1;
|
||||||
expect(expects);
|
expect(expects);
|
||||||
|
|
||||||
stop( 5000 );
|
stop( 5000 );
|
||||||
|
@ -30,15 +60,22 @@ test("Popcorn 0.3 TTXT Parser Plugin", function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
Popcorn.forEach(poppercorn.getTrackEvents(), function(evt) {
|
Popcorn.forEach(poppercorn.getTrackEvents(), function(evt) {
|
||||||
if(evt._natives.type === "subtitle") {
|
if(evt._natives.type === "subtitle") {
|
||||||
numSubs++;
|
sub = subs[numSubs++];
|
||||||
equals(subs[evt.start.toString()], evt.text , "Correct text" );
|
|
||||||
|
equals(sub.end, evt.end , "Correct end" );
|
||||||
|
plus();
|
||||||
|
|
||||||
|
equals(sub.start, evt.start , "Correct start" );
|
||||||
|
plus();
|
||||||
|
|
||||||
|
equals(sub.text, evt.text , "Correct text" );
|
||||||
plus();
|
plus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
equals(7, numSubs , "Correctly parsed all subs" );
|
equals(subs.length, numSubs , "Correctly parsed all subs" );
|
||||||
plus();
|
plus();
|
||||||
|
|
||||||
}, 1500);
|
}, 500);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче