1
-00:00:02.400 --> 00:00:07.200
+00:00:02.400 --> 00:00:07.200
Senator, we're making
our final approach into Coruscant.
2
-00:9.712 --> 00:13.399
+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!
+
(function (Popcorn) {
Popcorn.parser( "parseVTT", "VTT", function( data ) {
-
+
// declare needed variables
var retObj = {
title: "",
remote: "",
data: []
},
- subs = [],
- lines,
+ lines, time, text, sub,
+ subs = [],
i = 0, len = 0, idx = 0;
- // [HH]:MM:SS.mmm string to SS.mmm
+ // [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.length-1;
+ var time, l = t_in.length;
- try {
+ 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
len = lines.length;
while (i < len) {
- var sub = {};
-
- sub.id = lines[i++];
-
- var time = lines[i++].split(" --> ");
- var text = [];
+ 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