Skip to content

Commit 7181cc6

Browse files
committed
HEADER support. Taken from w3c#6
1 parent a16b4e3 commit 7181cc6

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

parser.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,33 @@
6464
err("No valid signature. (File needs to start with \"WEBVTT\".)")
6565
}
6666

67-
linePos++
68-
69-
/* HEADER */
70-
while(lines[linePos] != "" && lines[linePos] != undefined) {
71-
err("No blank line after the signature.")
72-
if(lines[linePos].indexOf("-->") != -1) {
73-
alreadyCollected = true
67+
/* HEADER */
68+
while(lines[linePos] !== undefined) {
69+
line = lines[linePos]
70+
/* look-ahead */
71+
if (line === "") {
72+
if ((lines[linePos+1] && lines[linePos+1].indexOf("-->") !== -1 )||
73+
(lines[linePos+2] && lines[linePos+2].indexOf("-->") !== -1)) {
7474
break
75+
} else {
76+
linePos++
77+
continue
78+
}
79+
} else {
80+
if ((line.match(/:/g) || []).length !== 1) {
81+
err("Metadata header line needs to consist of a name and value separated by a ':' character.")
82+
if (line.indexOf("-->") != -1) {
83+
err("Cues need to be separated from the Header by a blank line.")
84+
alreadyCollected = true
85+
}
86+
}
87+
if (line.substring(0,6) !== "Region") {
88+
err("Metadata headers other than Region are not defined.")
89+
alreadyCollected = true
7590
}
7691
linePos++
7792
}
93+
}
7894

7995
/* CUE LOOP */
8096
while(lines[linePos] != undefined) {

0 commit comments

Comments
 (0)