зеркало из https://github.com/mozilla/popcorn-js.git
Clean up parsers from base 0.3 branch
This commit is contained in:
Родитель
a8a2e2bff3
Коммит
c693362cfe
|
@ -1,35 +0,0 @@
|
|||
1
|
||||
00:00:00,82 --> 00:00:03,09
|
||||
Hi, I am Po-Chiang (Bob), Po-Chiang Chao (Bob Chao)
|
||||
|
||||
2
|
||||
00:00:03,14 --> 00:00:11,09
|
||||
I've participated in the project for about 6-7 years, starting from about 2002.
|
||||
|
||||
3
|
||||
00:00:11,15 --> 00:00:17,17
|
||||
At first I started off translating technical documents and promoting web standards.
|
||||
|
||||
4
|
||||
00:00:17,17 --> 00:00:21,90
|
||||
Since I am a web designer myself, I find it troublesome to have many different standards.
|
||||
|
||||
5
|
||||
00:00:21,90 --> 00:00:24,61
|
||||
That's why I wanted to promote web standards.
|
||||
|
||||
6
|
||||
00:00:24,78 --> 00:00:36,72
|
||||
The locale owner from two terms before, Lin Hong-De (piaip), invited me to help set up the moztw website, so I helped him.
|
||||
|
||||
7
|
||||
00:00:36,72 --> 00:00:40,91
|
||||
After he entered the military service, I took over most of the works. Kind of like a lackey.
|
||||
|
||||
8
|
||||
00:00:40,99 --> 00:00:47,64
|
||||
Up to now, the locale owner keeps changing, but I'm still helping out.
|
||||
|
||||
9
|
||||
00:00:47,71 --> 99:59:59,00
|
||||
Mainly with marketing and promotion, and mostly to do with coordinating the community.
|
|
@ -1,11 +0,0 @@
|
|||
1
|
||||
00:00:02,400 --> 00:00:05,200
|
||||
[Background Music Playing]
|
||||
|
||||
2
|
||||
00:00:15,712 --> 00:00:17,399
|
||||
Heay!!
|
||||
|
||||
3
|
||||
00:00:25,712 --> 00:00:30,399
|
||||
[Bird noises]
|
|
@ -1,41 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Popcorn 0.3 SRT parser Plug-in Demo</title>
|
||||
|
||||
<script src="../../popcorn.js"></script>
|
||||
<script src="../../plugins/subtitle/popcorn.subtitle.js"></script>
|
||||
<script src="../../parsers/parserSRT/popcorn.parserSRT.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Popcorn 0.3 SRT parser Plug-in Demo</h1>
|
||||
<p></p>
|
||||
<div>
|
||||
<video id='video' data-timeline-sources="data/data.srt"
|
||||
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>
|
|
@ -1,62 +0,0 @@
|
|||
// PARSER: 0.3 SRT
|
||||
|
||||
(function (Popcorn) {
|
||||
Popcorn.parser( "parseSRT", "SRT", function( data ) {
|
||||
|
||||
// declare needed variables
|
||||
var retObj = {
|
||||
title: "",
|
||||
remote: "",
|
||||
data: []
|
||||
},
|
||||
subs = [];
|
||||
|
||||
var toSeconds = function(t_in) {
|
||||
var t = t_in.split(':');
|
||||
var time = 0;
|
||||
|
||||
try {
|
||||
var s = t[2].split(',');
|
||||
|
||||
time += parseFloat(t[0], 10)*60*60; // hours => seconds
|
||||
time += parseFloat(t[1], 10)*60; // minutes => seconds
|
||||
time += parseFloat(s[0], 10);
|
||||
time += parseFloat(s[1], 10)/1000;
|
||||
} catch (e) { time = 0; }
|
||||
|
||||
return time;
|
||||
};
|
||||
|
||||
var createTrack = function( name, attributes ) {
|
||||
var track = {};
|
||||
track[name] = attributes;
|
||||
return track;
|
||||
};
|
||||
|
||||
var lines = data.text.replace("\r",'').split("\n");
|
||||
|
||||
for(var i=0, l=lines.length; i<l;i++) {
|
||||
var sub = {};
|
||||
|
||||
i++; // Bypass idx
|
||||
var time = lines[i++].split(" --> ");
|
||||
var text = "";
|
||||
|
||||
sub.start = toSeconds(time[0]);
|
||||
sub.end = toSeconds(time[1]);
|
||||
|
||||
while (lines[i] && lines[i] !== "\r") {
|
||||
text += lines[i++].replace("\r", "");
|
||||
}
|
||||
|
||||
sub.text = text;
|
||||
|
||||
subs.push( createTrack("subtitle", sub) );
|
||||
}
|
||||
|
||||
retObj.data = subs;
|
||||
|
||||
return retObj;
|
||||
});
|
||||
|
||||
})( Popcorn );
|
|
@ -1,43 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Popcorn 0.3 SRT 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.parserSRT.js"></script>
|
||||
<script src="../../plugins/subtitle/popcorn.subtitle.js"></script>
|
||||
<script src="popcorn.parserSRT.unit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Popcorn 0.3 SRT 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>
|
|
@ -1,42 +0,0 @@
|
|||
test("Popcorn 0.3 SRT Parser Plugin", function () {
|
||||
|
||||
var expects = 4,
|
||||
count = 0,
|
||||
key,
|
||||
numSubs = 0,
|
||||
poppercorn = Popcorn( "#video" ),
|
||||
subs = { // Expected values
|
||||
"2.4": "[Background Music Playing]",
|
||||
"15.712": "Heay!!",
|
||||
"25.712": "[Bird noises]"
|
||||
};
|
||||
|
||||
function plus() {
|
||||
if ( ++count === expects ) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
poppercorn.parseSRT("data/unit.srt");
|
||||
|
||||
expect(expects);
|
||||
|
||||
stop( 10000 );
|
||||
|
||||
// Allow load time
|
||||
setTimeout(function () {
|
||||
Popcorn.forEach(poppercorn.getTrackEvents(), function(evt) {
|
||||
if(evt._natives.type === "subtitle") {
|
||||
numSubs++;
|
||||
key = evt.start.toString();
|
||||
equals(subs[key], evt.text , "Correct amounts" );
|
||||
plus();
|
||||
}
|
||||
});
|
||||
|
||||
equals(3, numSubs , "Correctly parsed all subs" );
|
||||
plus();
|
||||
|
||||
}, 500);
|
||||
|
||||
});
|
|
@ -1,12 +0,0 @@
|
|||
1
|
||||
00:00:02.400 --> 00:00:07.200
|
||||
Senator, we're making
|
||||
our final approach into Coruscant.
|
||||
|
||||
2
|
||||
00:00:09.712 --> 00:00:13.399
|
||||
Very good, Lieutenant.
|
||||
|
||||
Track-3
|
||||
00:00:15.542 --> 00:00:18.542 A:start D:vertical L:98%
|
||||
It's a trap!
|
|
@ -1,39 +0,0 @@
|
|||
1
|
||||
00:00:02.400 --> 00:00:07.200
|
||||
Senator, we're making
|
||||
our final approach into Coruscant.
|
||||
|
||||
2
|
||||
00:09.712-->00:13.399
|
||||
Very good, Lieutenant.
|
||||
|
||||
|
||||
|
||||
3
|
||||
00:00:13.400 --> 00:00:20
|
||||
A bad cue, no milliseconds. Should be ignored
|
||||
|
||||
-->
|
||||
00:00:14.456--> 00:00:20.000
|
||||
A bad cue, bad id. Should be ignored
|
||||
|
||||
4
|
||||
00:00:9.456--> 00:00:20.000
|
||||
A bad cue, seconds are single digit. Should be ignored
|
||||
|
||||
5
|
||||
00:1:00.456--> 00:00:20.000
|
||||
A bad cue, minutes are single digit. Should be ignored
|
||||
|
||||
6
|
||||
1:00:00.456--> 00:00:20.000
|
||||
A bad cue, hours are supplied as single digit. Should be ignored
|
||||
|
||||
7
|
||||
00:00:00.46--> 00:00:20.000
|
||||
A bad cue, ms are not 3 digits. Should be ignored
|
||||
|
||||
Track-3
|
||||
00:00:15.042 --> 00:00:18.042 A:start D:vertical L:98%
|
||||
It's a trap!
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
<!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>
|
|
@ -1,82 +0,0 @@
|
|||
// PARSER: 0.3 VTT
|
||||
|
||||
(function (Popcorn) {
|
||||
Popcorn.parser( "parseVTT", "VTT", function( data ) {
|
||||
|
||||
// declare needed variables
|
||||
var retObj = {
|
||||
title: "",
|
||||
remote: "",
|
||||
data: []
|
||||
},
|
||||
lines, time, text, sub,
|
||||
subs = [],
|
||||
i = 0, len = 0, idx = 0;
|
||||
|
||||
// [HH:]MM:SS.mmm string to SS.mmm float
|
||||
// Throws exception if invalid
|
||||
var toSeconds = function(t_in) {
|
||||
var t = t_in.split(':');
|
||||
var time, l = t_in.length;
|
||||
|
||||
if (l !== 12 && l !== 9) throw "Bad cue";
|
||||
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
|
||||
// Split on line breaks
|
||||
lines = data.text.split(/(?:\r\n|\r|\n)/gm);
|
||||
len = lines.length;
|
||||
|
||||
while (i < len) {
|
||||
sub = {};
|
||||
text = [];
|
||||
|
||||
try {
|
||||
sub.id = lines[i++];
|
||||
|
||||
if (!sub.id || sub.id.indexOf("-->") !== -1) throw "Bad cue";
|
||||
|
||||
time = lines[i++].split(/[\t ]*-->[\t ]*/);
|
||||
|
||||
sub.start = toSeconds(time[0]);
|
||||
|
||||
// Filter out any trailing styling info
|
||||
idx = time[1].indexOf(" ");
|
||||
sub.end = toSeconds(idx === -1 ? time[1] : time[1].substr(0, idx));
|
||||
|
||||
while (i < len && lines[i]) {
|
||||
text.push(lines[i++]);
|
||||
}
|
||||
|
||||
sub.text = text.join(" ");
|
||||
subs.push( createTrack("subtitle", sub) );
|
||||
} catch (e) { // Bad cue
|
||||
while (i < len && lines[i++]); // Advance to end of cue
|
||||
}
|
||||
|
||||
// Consume empty whitespace
|
||||
while (i < len && !lines[i]) { i++; }
|
||||
}
|
||||
|
||||
retObj.data = subs;
|
||||
|
||||
return retObj;
|
||||
});
|
||||
|
||||
})( Popcorn );
|
|
@ -1,44 +0,0 @@
|
|||
<!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'
|
||||
data-timeline-sources="data/unit.vtt"
|
||||
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>
|
|
@ -1,62 +0,0 @@
|
|||
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(document.getElementById('video').getAttribute('data-timeline-sources'));
|
||||
|
||||
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);
|
||||
|
||||
});
|
Загрузка…
Ссылка в новой задаче