From: stevenaw Date: Tue, 25 Jan 2011 22:13:55 +0000 (-0500) Subject: Core is done, working on unit tests X-Git-Tag: v0.3~15^2~6^2~5 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ffa14d1b324df72521d035baa567e312b8aa6c40;p=popcorn-js.git Core is done, working on unit tests --- diff --git a/parsers/parserSRT/data/data.srt b/parsers/parserSRT/data/data.srt new file mode 100644 index 0000000..defebc6 --- /dev/null +++ b/parsers/parserSRT/data/data.srt @@ -0,0 +1,35 @@ +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. diff --git a/parsers/parserSRT/data/unit.srt b/parsers/parserSRT/data/unit.srt new file mode 100644 index 0000000..b88f84c --- /dev/null +++ b/parsers/parserSRT/data/unit.srt @@ -0,0 +1,11 @@ +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] diff --git a/parsers/parserSRT/popcorn.parserSRT.html b/parsers/parserSRT/popcorn.parserSRT.html new file mode 100644 index 0000000..7f1f143 --- /dev/null +++ b/parsers/parserSRT/popcorn.parserSRT.html @@ -0,0 +1,41 @@ + + + + Popcorn 0.3 SRT parser Plug-in Demo + + + + + + + +

Popcorn 0.3 SRT parser Plug-in Demo

+

+
+ +
+ + + + + diff --git a/parsers/parserSRT/popcorn.parserSRT.js b/parsers/parserSRT/popcorn.parserSRT.js new file mode 100644 index 0000000..6446f94 --- /dev/null +++ b/parsers/parserSRT/popcorn.parserSRT.js @@ -0,0 +1,62 @@ +// 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 "); + 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 ); diff --git a/parsers/parserSRT/popcorn.parserSRT.unit.html b/parsers/parserSRT/popcorn.parserSRT.unit.html new file mode 100644 index 0000000..f6ecffd --- /dev/null +++ b/parsers/parserSRT/popcorn.parserSRT.unit.html @@ -0,0 +1,43 @@ + + + + Popcorn 0.3 SRT parser Plug-in Test + + + + + + + + + + + +

Popcorn 0.3 SRT parser Plug-in Test

+

+
+

+
    +
    + + + + \ No newline at end of file diff --git a/parsers/parserSRT/popcorn.parserSRT.unit.js b/parsers/parserSRT/popcorn.parserSRT.unit.js new file mode 100644 index 0000000..dc0ff2f --- /dev/null +++ b/parsers/parserSRT/popcorn.parserSRT.unit.js @@ -0,0 +1,43 @@ +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 ); + + alert("HI"); + // Allow load time + setTimeout(function () { + Popcorn.forEach(poppercorn.getTrackEvents(), function(evt) { + if(evt._natives.type === "subtitle") { + numSubs++; + key = Math.ceil(evt.start).toString(); + equals(subs[key], evt.text , "Correct amounts" ); + plus(); + } + }); + + equals(3, numSubs , "Correctly parsed all subs" ); + plus(); + + }, 500); + +}); \ No newline at end of file