@transmitlive/m3u8-parser 4.7.2-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +30 -0
- package/LICENSE +13 -0
- package/README.md +388 -0
- package/dist/m3u8-parser.cjs.js +1563 -0
- package/dist/m3u8-parser.es.js +1549 -0
- package/dist/m3u8-parser.js +1748 -0
- package/dist/m3u8-parser.min.js +2 -0
- package/index.html +15 -0
- package/package.json +100 -0
- package/scripts/karma.conf.js +12 -0
- package/scripts/rollup.config.js +47 -0
- package/src/index.js +19 -0
- package/src/line-stream.js +35 -0
- package/src/parse-stream.js +619 -0
- package/src/parser.js +748 -0
- package/test/fixtures/integration/absoluteUris.js +31 -0
- package/test/fixtures/integration/absoluteUris.m3u8 +12 -0
- package/test/fixtures/integration/allowCache.js +165 -0
- package/test/fixtures/integration/allowCache.m3u8 +58 -0
- package/test/fixtures/integration/allowCacheInvalid.js +21 -0
- package/test/fixtures/integration/allowCacheInvalid.m3u8 +10 -0
- package/test/fixtures/integration/alternateAudio.js +56 -0
- package/test/fixtures/integration/alternateAudio.m3u8 +9 -0
- package/test/fixtures/integration/alternateVideo.js +48 -0
- package/test/fixtures/integration/alternateVideo.m3u8 +8 -0
- package/test/fixtures/integration/brightcove.js +57 -0
- package/test/fixtures/integration/brightcove.m3u8 +9 -0
- package/test/fixtures/integration/byteRange.js +161 -0
- package/test/fixtures/integration/byteRange.m3u8 +56 -0
- package/test/fixtures/integration/dateTime.js +27 -0
- package/test/fixtures/integration/dateTime.m3u8 +12 -0
- package/test/fixtures/integration/diff-init-key.js +164 -0
- package/test/fixtures/integration/diff-init-key.m3u8 +57 -0
- package/test/fixtures/integration/disallowCache.js +21 -0
- package/test/fixtures/integration/disallowCache.m3u8 +10 -0
- package/test/fixtures/integration/disc-sequence.js +32 -0
- package/test/fixtures/integration/disc-sequence.m3u8 +15 -0
- package/test/fixtures/integration/discontinuity.js +59 -0
- package/test/fixtures/integration/discontinuity.m3u8 +26 -0
- package/test/fixtures/integration/domainUris.js +31 -0
- package/test/fixtures/integration/domainUris.m3u8 +12 -0
- package/test/fixtures/integration/empty.js +5 -0
- package/test/fixtures/integration/empty.m3u8 +0 -0
- package/test/fixtures/integration/emptyAllowCache.js +21 -0
- package/test/fixtures/integration/emptyAllowCache.m3u8 +10 -0
- package/test/fixtures/integration/emptyMediaSequence.js +31 -0
- package/test/fixtures/integration/emptyMediaSequence.m3u8 +14 -0
- package/test/fixtures/integration/emptyPlaylistType.js +40 -0
- package/test/fixtures/integration/emptyPlaylistType.m3u8 +16 -0
- package/test/fixtures/integration/emptyTargetDuration.js +57 -0
- package/test/fixtures/integration/emptyTargetDuration.m3u8 +10 -0
- package/test/fixtures/integration/encrypted.js +61 -0
- package/test/fixtures/integration/encrypted.m3u8 +28 -0
- package/test/fixtures/integration/event.js +41 -0
- package/test/fixtures/integration/event.m3u8 +16 -0
- package/test/fixtures/integration/extXPlaylistTypeInvalidPlaylist.js +15 -0
- package/test/fixtures/integration/extXPlaylistTypeInvalidPlaylist.m3u8 +8 -0
- package/test/fixtures/integration/extinf.js +165 -0
- package/test/fixtures/integration/extinf.m3u8 +57 -0
- package/test/fixtures/integration/fmp4.js +44 -0
- package/test/fixtures/integration/fmp4.m3u8 +14 -0
- package/test/fixtures/integration/headerOnly.js +5 -0
- package/test/fixtures/integration/headerOnly.m3u8 +1 -0
- package/test/fixtures/integration/invalidAllowCache.js +21 -0
- package/test/fixtures/integration/invalidAllowCache.m3u8 +10 -0
- package/test/fixtures/integration/invalidMediaSequence.js +31 -0
- package/test/fixtures/integration/invalidMediaSequence.m3u8 +14 -0
- package/test/fixtures/integration/invalidPlaylistType.js +40 -0
- package/test/fixtures/integration/invalidPlaylistType.m3u8 +16 -0
- package/test/fixtures/integration/invalidTargetDuration.js +164 -0
- package/test/fixtures/integration/invalidTargetDuration.m3u8 +57 -0
- package/test/fixtures/integration/liveMissingSegmentDuration.js +25 -0
- package/test/fixtures/integration/liveMissingSegmentDuration.m3u8 +9 -0
- package/test/fixtures/integration/liveStart30sBefore.js +54 -0
- package/test/fixtures/integration/liveStart30sBefore.m3u8 +22 -0
- package/test/fixtures/integration/llhls-byte-range.js +253 -0
- package/test/fixtures/integration/llhls-byte-range.m3u8 +66 -0
- package/test/fixtures/integration/llhls-delta-byte-range.js +149 -0
- package/test/fixtures/integration/llhls-delta-byte-range.m3u8 +30 -0
- package/test/fixtures/integration/llhls.js +214 -0
- package/test/fixtures/integration/llhls.m3u8 +56 -0
- package/test/fixtures/integration/llhlsDelta.js +186 -0
- package/test/fixtures/integration/llhlsDelta.m3u8 +50 -0
- package/test/fixtures/integration/manifestExtTTargetdurationNegative.js +14 -0
- package/test/fixtures/integration/manifestExtTTargetdurationNegative.m3u8 +5 -0
- package/test/fixtures/integration/manifestExtXEndlistEarly.js +35 -0
- package/test/fixtures/integration/manifestExtXEndlistEarly.m3u8 +14 -0
- package/test/fixtures/integration/manifestNoExtM3u.js +15 -0
- package/test/fixtures/integration/manifestNoExtM3u.m3u8 +4 -0
- package/test/fixtures/integration/master-fmp4.js +465 -0
- package/test/fixtures/integration/master-fmp4.m3u8 +76 -0
- package/test/fixtures/integration/master.js +57 -0
- package/test/fixtures/integration/master.m3u8 +10 -0
- package/test/fixtures/integration/media.js +31 -0
- package/test/fixtures/integration/media.m3u8 +12 -0
- package/test/fixtures/integration/mediaSequence.js +31 -0
- package/test/fixtures/integration/mediaSequence.m3u8 +14 -0
- package/test/fixtures/integration/missingEndlist.js +19 -0
- package/test/fixtures/integration/missingEndlist.m3u8 +6 -0
- package/test/fixtures/integration/missingExtinf.js +27 -0
- package/test/fixtures/integration/missingExtinf.m3u8 +11 -0
- package/test/fixtures/integration/missingMediaSequence.js +31 -0
- package/test/fixtures/integration/missingMediaSequence.m3u8 +13 -0
- package/test/fixtures/integration/missingSegmentDuration.js +31 -0
- package/test/fixtures/integration/missingSegmentDuration.m3u8 +11 -0
- package/test/fixtures/integration/multipleAudioGroups.js +89 -0
- package/test/fixtures/integration/multipleAudioGroups.m3u8 +17 -0
- package/test/fixtures/integration/multipleAudioGroupsCombinedMain.js +88 -0
- package/test/fixtures/integration/multipleAudioGroupsCombinedMain.m3u8 +17 -0
- package/test/fixtures/integration/multipleTargetDurations.js +28 -0
- package/test/fixtures/integration/multipleTargetDurations.m3u8 +8 -0
- package/test/fixtures/integration/multipleVideo.js +74 -0
- package/test/fixtures/integration/multipleVideo.m3u8 +16 -0
- package/test/fixtures/integration/negativeMediaSequence.js +31 -0
- package/test/fixtures/integration/negativeMediaSequence.m3u8 +14 -0
- package/test/fixtures/integration/playlist.js +165 -0
- package/test/fixtures/integration/playlist.m3u8 +57 -0
- package/test/fixtures/integration/playlistMediaSequenceHigher.js +16 -0
- package/test/fixtures/integration/playlistMediaSequenceHigher.m3u8 +8 -0
- package/test/fixtures/integration/start.js +36 -0
- package/test/fixtures/integration/start.m3u8 +13 -0
- package/test/fixtures/integration/streamInfInvalid.js +24 -0
- package/test/fixtures/integration/streamInfInvalid.m3u8 +6 -0
- package/test/fixtures/integration/twoMediaSequences.js +31 -0
- package/test/fixtures/integration/twoMediaSequences.m3u8 +15 -0
- package/test/fixtures/integration/versionInvalid.js +16 -0
- package/test/fixtures/integration/versionInvalid.m3u8 +8 -0
- package/test/fixtures/integration/whiteSpace.js +31 -0
- package/test/fixtures/integration/whiteSpace.m3u8 +13 -0
- package/test/fixtures/integration/zeroDuration.js +16 -0
- package/test/fixtures/integration/zeroDuration.m3u8 +7 -0
- package/test/line-stream.test.js +80 -0
- package/test/parse-stream.test.js +903 -0
- package/test/parser.test.js +884 -0
|
@@ -0,0 +1,903 @@
|
|
|
1
|
+
import {LineStream, ParseStream} from '../src';
|
|
2
|
+
import QUnit from 'qunit';
|
|
3
|
+
import sinon from 'sinon';
|
|
4
|
+
|
|
5
|
+
QUnit.module('ParseStream', {
|
|
6
|
+
beforeEach() {
|
|
7
|
+
this.lineStream = new LineStream();
|
|
8
|
+
this.parseStream = new ParseStream();
|
|
9
|
+
this.lineStream.pipe(this.parseStream);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
QUnit.test('parses custom tags', function(assert) {
|
|
14
|
+
const manifest = '#VOD-STARTTIMESTAMP:1501533337573\n';
|
|
15
|
+
let element;
|
|
16
|
+
|
|
17
|
+
this.parseStream.addParser({
|
|
18
|
+
expression: /^#VOD-STARTTIMESTAMP/,
|
|
19
|
+
customType: 'startTimestamp'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
this.parseStream.on('data', function(elem) {
|
|
23
|
+
element = elem;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
this.lineStream.push(manifest);
|
|
27
|
+
assert.ok(element, 'element');
|
|
28
|
+
assert.strictEqual(element.type, 'custom', 'the type of the data is custom');
|
|
29
|
+
assert.strictEqual(
|
|
30
|
+
element.customType,
|
|
31
|
+
'startTimestamp',
|
|
32
|
+
'the customType is startTimestamp'
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
QUnit.test('mapper does not conflict with parser', function(assert) {
|
|
37
|
+
const manifest = '#EXAMPLE\n';
|
|
38
|
+
const commentMapper = sinon.spy(line => '#NEW-COMMENT');
|
|
39
|
+
const commentMapper2 = sinon.spy(line => '#SOMETHING-ELSE');
|
|
40
|
+
const dataCallback = sinon.spy();
|
|
41
|
+
|
|
42
|
+
this.parseStream.addTagMapper({
|
|
43
|
+
expression: /^#EXAMPLE/,
|
|
44
|
+
map: commentMapper
|
|
45
|
+
});
|
|
46
|
+
this.parseStream.addTagMapper({
|
|
47
|
+
expression: /^#EXAMPLE/,
|
|
48
|
+
map: commentMapper2
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
this.parseStream.addParser({
|
|
52
|
+
expression: /^#EXAMPLE/,
|
|
53
|
+
customType: 'test'
|
|
54
|
+
});
|
|
55
|
+
this.parseStream.addParser({
|
|
56
|
+
expression: /^#NEW-COMMENT/,
|
|
57
|
+
customType: 'test2'
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
this.parseStream.on('data', dataCallback);
|
|
61
|
+
this.lineStream.push(manifest);
|
|
62
|
+
|
|
63
|
+
assert.ok(commentMapper.called);
|
|
64
|
+
assert.ok(commentMapper2.called);
|
|
65
|
+
assert.strictEqual(dataCallback.callCount, 3);
|
|
66
|
+
|
|
67
|
+
assert.deepEqual(dataCallback.getCall(0).args[0], {
|
|
68
|
+
data: '#EXAMPLE',
|
|
69
|
+
type: 'custom',
|
|
70
|
+
customType: 'test',
|
|
71
|
+
segment: undefined
|
|
72
|
+
});
|
|
73
|
+
assert.deepEqual(dataCallback.getCall(1).args[0], {
|
|
74
|
+
data: '#NEW-COMMENT',
|
|
75
|
+
type: 'custom',
|
|
76
|
+
customType: 'test2',
|
|
77
|
+
segment: undefined
|
|
78
|
+
});
|
|
79
|
+
assert.deepEqual(dataCallback.getCall(2).args[0], {
|
|
80
|
+
text: 'SOMETHING-ELSE',
|
|
81
|
+
type: 'comment'
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
QUnit.test('maps custom tags', function(assert) {
|
|
86
|
+
const manifest = '#EXAMPLE\n';
|
|
87
|
+
const commentMapper = sinon.spy(line => '#NEW-COMMENT');
|
|
88
|
+
const dataCallback = sinon.spy();
|
|
89
|
+
|
|
90
|
+
this.parseStream.addTagMapper({
|
|
91
|
+
expression: /^#EXAMPLE/,
|
|
92
|
+
map: commentMapper
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
this.parseStream.on('data', dataCallback);
|
|
96
|
+
this.lineStream.push(manifest);
|
|
97
|
+
|
|
98
|
+
assert.ok(commentMapper.called);
|
|
99
|
+
assert.strictEqual(dataCallback.callCount, 2);
|
|
100
|
+
|
|
101
|
+
assert.deepEqual(dataCallback.getCall(0).args[0], {
|
|
102
|
+
text: 'EXAMPLE',
|
|
103
|
+
type: 'comment'
|
|
104
|
+
});
|
|
105
|
+
assert.deepEqual(dataCallback.getCall(1).args[0], {
|
|
106
|
+
text: 'NEW-COMMENT',
|
|
107
|
+
type: 'comment'
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
QUnit.test('maps multiple custom tags', function(assert) {
|
|
112
|
+
const manifest = '#VOD-STARTTIMESTAMP:1501533337573\n';
|
|
113
|
+
const commentMapper = sinon.spy(line => '#NEW-COMMENT');
|
|
114
|
+
const pdtMapper = sinon.spy((line) => {
|
|
115
|
+
const match = /#VOD-STARTTIMESTAMP:(\d+)/g.exec(line)[1];
|
|
116
|
+
const ISOdate = new Date(Number(match)).toISOString();
|
|
117
|
+
|
|
118
|
+
return `#EXT-X-PROGRAM-DATE-TIME:${ISOdate}`;
|
|
119
|
+
});
|
|
120
|
+
const dataCallback = sinon.spy();
|
|
121
|
+
|
|
122
|
+
this.parseStream.addTagMapper({
|
|
123
|
+
expression: /^#VOD-STARTTIMESTAMP/,
|
|
124
|
+
map: commentMapper
|
|
125
|
+
});
|
|
126
|
+
this.parseStream.addTagMapper({
|
|
127
|
+
expression: /^#VOD-STARTTIMESTAMP/,
|
|
128
|
+
map: pdtMapper
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
this.parseStream.on('data', dataCallback);
|
|
132
|
+
this.lineStream.push(manifest);
|
|
133
|
+
|
|
134
|
+
assert.ok(commentMapper.called);
|
|
135
|
+
assert.ok(pdtMapper.called);
|
|
136
|
+
assert.strictEqual(dataCallback.callCount, 3);
|
|
137
|
+
|
|
138
|
+
assert.deepEqual(dataCallback.getCall(0).args[0], {
|
|
139
|
+
text: 'VOD-STARTTIMESTAMP:1501533337573',
|
|
140
|
+
type: 'comment'
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
assert.deepEqual(dataCallback.getCall(1).args[0], {
|
|
144
|
+
text: 'NEW-COMMENT',
|
|
145
|
+
type: 'comment'
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const dateTag = dataCallback.getCall(2).args[0];
|
|
149
|
+
|
|
150
|
+
assert.strictEqual(dateTag.dateTimeString, '2017-07-31T20:35:37.573Z');
|
|
151
|
+
assert.strictEqual(dateTag.tagType, 'program-date-time');
|
|
152
|
+
assert.strictEqual(dateTag.type, 'tag');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
QUnit.test('mapper ignores tags', function(assert) {
|
|
156
|
+
const manifest = '#TAG\n';
|
|
157
|
+
const dataCallback = sinon.spy();
|
|
158
|
+
|
|
159
|
+
this.parseStream.addTagMapper({
|
|
160
|
+
expression: /^#NO-MATCH/,
|
|
161
|
+
map(line) {
|
|
162
|
+
return '#MAPPED';
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
this.parseStream.on('data', dataCallback);
|
|
167
|
+
this.lineStream.push(manifest);
|
|
168
|
+
|
|
169
|
+
assert.strictEqual(dataCallback.callCount, 1);
|
|
170
|
+
assert.deepEqual(dataCallback.getCall(0).args[0], {
|
|
171
|
+
text: 'TAG',
|
|
172
|
+
type: 'comment'
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
QUnit.test('parses comment lines', function(assert) {
|
|
177
|
+
const manifest = '# a line that starts with a hash mark without "EXT" is a comment\n';
|
|
178
|
+
let element;
|
|
179
|
+
|
|
180
|
+
this.parseStream.on('data', function(elem) {
|
|
181
|
+
element = elem;
|
|
182
|
+
});
|
|
183
|
+
this.lineStream.push(manifest);
|
|
184
|
+
|
|
185
|
+
assert.ok(element, 'an event was triggered');
|
|
186
|
+
assert.strictEqual(element.type, 'comment', 'the type is comment');
|
|
187
|
+
assert.strictEqual(
|
|
188
|
+
element.text,
|
|
189
|
+
manifest.slice(1, manifest.length - 1),
|
|
190
|
+
'the comment text is parsed'
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
QUnit.test('parses uri lines', function(assert) {
|
|
194
|
+
const manifest = 'any non-blank line that does not start with a hash-mark is a URI\n';
|
|
195
|
+
let element;
|
|
196
|
+
|
|
197
|
+
this.parseStream.on('data', function(elem) {
|
|
198
|
+
element = elem;
|
|
199
|
+
});
|
|
200
|
+
this.lineStream.push(manifest);
|
|
201
|
+
|
|
202
|
+
assert.ok(element, 'an event was triggered');
|
|
203
|
+
assert.strictEqual(element.type, 'uri', 'the type is uri');
|
|
204
|
+
assert.strictEqual(
|
|
205
|
+
element.uri,
|
|
206
|
+
manifest.substring(0, manifest.length - 1),
|
|
207
|
+
'the uri text is parsed'
|
|
208
|
+
);
|
|
209
|
+
});
|
|
210
|
+
QUnit.test('parses unknown tag types', function(assert) {
|
|
211
|
+
const manifest = '#EXT-X-EXAMPLE-TAG:some,additional,stuff\n';
|
|
212
|
+
let element;
|
|
213
|
+
|
|
214
|
+
this.parseStream.on('data', function(elem) {
|
|
215
|
+
element = elem;
|
|
216
|
+
});
|
|
217
|
+
this.lineStream.push(manifest);
|
|
218
|
+
|
|
219
|
+
assert.ok(element, 'an event was triggered');
|
|
220
|
+
assert.strictEqual(element.type, 'tag', 'the type is tag');
|
|
221
|
+
assert.strictEqual(
|
|
222
|
+
element.data,
|
|
223
|
+
manifest.slice(4, manifest.length - 1),
|
|
224
|
+
'unknown tag data is preserved'
|
|
225
|
+
);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// #EXTM3U
|
|
229
|
+
QUnit.test('parses #EXTM3U tags', function(assert) {
|
|
230
|
+
const manifest = '#EXTM3U\n';
|
|
231
|
+
let element;
|
|
232
|
+
|
|
233
|
+
this.parseStream.on('data', function(elem) {
|
|
234
|
+
element = elem;
|
|
235
|
+
});
|
|
236
|
+
this.lineStream.push(manifest);
|
|
237
|
+
|
|
238
|
+
assert.ok(element, 'an event was triggered');
|
|
239
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
240
|
+
assert.strictEqual(element.tagType, 'm3u', 'the tag type is m3u');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// #EXTINF
|
|
244
|
+
QUnit.test('parses minimal #EXTINF tags', function(assert) {
|
|
245
|
+
const manifest = '#EXTINF\n';
|
|
246
|
+
let element;
|
|
247
|
+
|
|
248
|
+
this.parseStream.on('data', function(elem) {
|
|
249
|
+
element = elem;
|
|
250
|
+
});
|
|
251
|
+
this.lineStream.push(manifest);
|
|
252
|
+
|
|
253
|
+
assert.ok(element, 'an event was triggered');
|
|
254
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
255
|
+
assert.strictEqual(element.tagType, 'inf', 'the tag type is inf');
|
|
256
|
+
});
|
|
257
|
+
QUnit.test('parses #EXTINF tags with durations', function(assert) {
|
|
258
|
+
let manifest = '#EXTINF:15\n';
|
|
259
|
+
let element;
|
|
260
|
+
|
|
261
|
+
this.parseStream.on('data', function(elem) {
|
|
262
|
+
element = elem;
|
|
263
|
+
});
|
|
264
|
+
this.lineStream.push(manifest);
|
|
265
|
+
|
|
266
|
+
assert.ok(element, 'an event was triggered');
|
|
267
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
268
|
+
assert.strictEqual(element.tagType, 'inf', 'the tag type is inf');
|
|
269
|
+
assert.strictEqual(element.duration, 15, 'the duration is parsed');
|
|
270
|
+
assert.ok(!('title' in element), 'no title is parsed');
|
|
271
|
+
|
|
272
|
+
manifest = '#EXTINF:21,\n';
|
|
273
|
+
this.lineStream.push(manifest);
|
|
274
|
+
|
|
275
|
+
assert.ok(element, 'an event was triggered');
|
|
276
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
277
|
+
assert.strictEqual(element.tagType, 'inf', 'the tag type is inf');
|
|
278
|
+
assert.strictEqual(element.duration, 21, 'the duration is parsed');
|
|
279
|
+
assert.ok(!('title' in element), 'no title is parsed');
|
|
280
|
+
});
|
|
281
|
+
QUnit.test('parses #EXTINF tags with a duration and title', function(assert) {
|
|
282
|
+
const manifest = '#EXTINF:13,Does anyone really use the title attribute?\n';
|
|
283
|
+
let element;
|
|
284
|
+
|
|
285
|
+
this.parseStream.on('data', function(elem) {
|
|
286
|
+
element = elem;
|
|
287
|
+
});
|
|
288
|
+
this.lineStream.push(manifest);
|
|
289
|
+
|
|
290
|
+
assert.ok(element, 'an event was triggered');
|
|
291
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
292
|
+
assert.strictEqual(element.tagType, 'inf', 'the tag type is inf');
|
|
293
|
+
assert.strictEqual(element.duration, 13, 'the duration is parsed');
|
|
294
|
+
assert.strictEqual(
|
|
295
|
+
element.title,
|
|
296
|
+
manifest.substring(manifest.indexOf(',') + 1, manifest.length - 1),
|
|
297
|
+
'the title is parsed'
|
|
298
|
+
);
|
|
299
|
+
});
|
|
300
|
+
QUnit.test('parses #EXTINF tags with carriage returns', function(assert) {
|
|
301
|
+
const manifest = '#EXTINF:13,Does anyone really use the title attribute?\r\n';
|
|
302
|
+
let element;
|
|
303
|
+
|
|
304
|
+
this.parseStream.on('data', function(elem) {
|
|
305
|
+
element = elem;
|
|
306
|
+
});
|
|
307
|
+
this.lineStream.push(manifest);
|
|
308
|
+
|
|
309
|
+
assert.ok(element, 'an event was triggered');
|
|
310
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
311
|
+
assert.strictEqual(element.tagType, 'inf', 'the tag type is inf');
|
|
312
|
+
assert.strictEqual(element.duration, 13, 'the duration is parsed');
|
|
313
|
+
assert.strictEqual(
|
|
314
|
+
element.title,
|
|
315
|
+
manifest.substring(manifest.indexOf(',') + 1, manifest.length - 2),
|
|
316
|
+
'the title is parsed'
|
|
317
|
+
);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// #EXT-X-TARGETDURATION
|
|
321
|
+
QUnit.test('parses minimal #EXT-X-TARGETDURATION tags', function(assert) {
|
|
322
|
+
const manifest = '#EXT-X-TARGETDURATION\n';
|
|
323
|
+
let element;
|
|
324
|
+
|
|
325
|
+
this.parseStream.on('data', function(elem) {
|
|
326
|
+
element = elem;
|
|
327
|
+
});
|
|
328
|
+
this.lineStream.push(manifest);
|
|
329
|
+
|
|
330
|
+
assert.ok(element, 'an event was triggered');
|
|
331
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
332
|
+
assert.strictEqual(element.tagType, 'targetduration', 'the tag type is targetduration');
|
|
333
|
+
assert.ok(!('duration' in element), 'no duration is parsed');
|
|
334
|
+
});
|
|
335
|
+
QUnit.test('parses #EXT-X-TARGETDURATION with duration', function(assert) {
|
|
336
|
+
const manifest = '#EXT-X-TARGETDURATION:47\n';
|
|
337
|
+
let element;
|
|
338
|
+
|
|
339
|
+
this.parseStream.on('data', function(elem) {
|
|
340
|
+
element = elem;
|
|
341
|
+
});
|
|
342
|
+
this.lineStream.push(manifest);
|
|
343
|
+
|
|
344
|
+
assert.ok(element, 'an event was triggered');
|
|
345
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
346
|
+
assert.strictEqual(element.tagType, 'targetduration', 'the tag type is targetduration');
|
|
347
|
+
assert.strictEqual(element.duration, 47, 'the duration is parsed');
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// #EXT-X-VERSION
|
|
351
|
+
QUnit.test('parses minimal #EXT-X-VERSION tags', function(assert) {
|
|
352
|
+
const manifest = '#EXT-X-VERSION:\n';
|
|
353
|
+
let element;
|
|
354
|
+
|
|
355
|
+
this.parseStream.on('data', function(elem) {
|
|
356
|
+
element = elem;
|
|
357
|
+
});
|
|
358
|
+
this.lineStream.push(manifest);
|
|
359
|
+
|
|
360
|
+
assert.ok(element, 'an event was triggered');
|
|
361
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
362
|
+
assert.strictEqual(element.tagType, 'version', 'the tag type is version');
|
|
363
|
+
assert.ok(!('version' in element), 'no version is present');
|
|
364
|
+
});
|
|
365
|
+
QUnit.test('parses #EXT-X-VERSION with a version', function(assert) {
|
|
366
|
+
const manifest = '#EXT-X-VERSION:99\n';
|
|
367
|
+
let element;
|
|
368
|
+
|
|
369
|
+
this.parseStream.on('data', function(elem) {
|
|
370
|
+
element = elem;
|
|
371
|
+
});
|
|
372
|
+
this.lineStream.push(manifest);
|
|
373
|
+
|
|
374
|
+
assert.ok(element, 'an event was triggered');
|
|
375
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
376
|
+
assert.strictEqual(element.tagType, 'version', 'the tag type is version');
|
|
377
|
+
assert.strictEqual(element.version, 99, 'the version is parsed');
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
// #EXT-X-MEDIA-SEQUENCE
|
|
381
|
+
QUnit.test('parses minimal #EXT-X-MEDIA-SEQUENCE tags', function(assert) {
|
|
382
|
+
const manifest = '#EXT-X-MEDIA-SEQUENCE\n';
|
|
383
|
+
let element;
|
|
384
|
+
|
|
385
|
+
this.parseStream.on('data', function(elem) {
|
|
386
|
+
element = elem;
|
|
387
|
+
});
|
|
388
|
+
this.lineStream.push(manifest);
|
|
389
|
+
|
|
390
|
+
assert.ok(element, 'an event was triggered');
|
|
391
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
392
|
+
assert.strictEqual(element.tagType, 'media-sequence', 'the tag type is media-sequence');
|
|
393
|
+
assert.ok(!('number' in element), 'no number is present');
|
|
394
|
+
});
|
|
395
|
+
QUnit.test('parses #EXT-X-MEDIA-SEQUENCE with sequence numbers', function(assert) {
|
|
396
|
+
const manifest = '#EXT-X-MEDIA-SEQUENCE:109\n';
|
|
397
|
+
let element;
|
|
398
|
+
|
|
399
|
+
this.parseStream.on('data', function(elem) {
|
|
400
|
+
element = elem;
|
|
401
|
+
});
|
|
402
|
+
this.lineStream.push(manifest);
|
|
403
|
+
|
|
404
|
+
assert.ok(element, 'an event was triggered');
|
|
405
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
406
|
+
assert.strictEqual(element.tagType, 'media-sequence', 'the tag type is media-sequence');
|
|
407
|
+
assert.ok(element.number, 109, 'the number is parsed');
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// #EXT-X-PLAYLIST-TYPE
|
|
411
|
+
QUnit.test('parses minimal #EXT-X-PLAYLIST-TYPE tags', function(assert) {
|
|
412
|
+
const manifest = '#EXT-X-PLAYLIST-TYPE:\n';
|
|
413
|
+
let element;
|
|
414
|
+
|
|
415
|
+
this.parseStream.on('data', function(elem) {
|
|
416
|
+
element = elem;
|
|
417
|
+
});
|
|
418
|
+
this.lineStream.push(manifest);
|
|
419
|
+
|
|
420
|
+
assert.ok(element, 'an event was triggered');
|
|
421
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
422
|
+
assert.strictEqual(element.tagType, 'playlist-type', 'the tag type is playlist-type');
|
|
423
|
+
assert.ok(!('playlistType' in element), 'no playlist type is present');
|
|
424
|
+
});
|
|
425
|
+
QUnit.test('parses #EXT-X-PLAYLIST-TYPE with mutability info', function(assert) {
|
|
426
|
+
let manifest = '#EXT-X-PLAYLIST-TYPE:EVENT\n';
|
|
427
|
+
let element;
|
|
428
|
+
|
|
429
|
+
this.parseStream.on('data', function(elem) {
|
|
430
|
+
element = elem;
|
|
431
|
+
});
|
|
432
|
+
this.lineStream.push(manifest);
|
|
433
|
+
|
|
434
|
+
assert.ok(element, 'an event was triggered');
|
|
435
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
436
|
+
assert.strictEqual(element.tagType, 'playlist-type', 'the tag type is playlist-type');
|
|
437
|
+
assert.strictEqual(element.playlistType, 'EVENT', 'the playlist type is EVENT');
|
|
438
|
+
|
|
439
|
+
manifest = '#EXT-X-PLAYLIST-TYPE:VOD\n';
|
|
440
|
+
this.lineStream.push(manifest);
|
|
441
|
+
assert.ok(element, 'an event was triggered');
|
|
442
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
443
|
+
assert.strictEqual(element.tagType, 'playlist-type', 'the tag type is playlist-type');
|
|
444
|
+
assert.strictEqual(element.playlistType, 'VOD', 'the playlist type is VOD');
|
|
445
|
+
|
|
446
|
+
manifest = '#EXT-X-PLAYLIST-TYPE:nonsense\n';
|
|
447
|
+
this.lineStream.push(manifest);
|
|
448
|
+
assert.ok(element, 'an event was triggered');
|
|
449
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
450
|
+
assert.strictEqual(element.tagType, 'playlist-type', 'the tag type is playlist-type');
|
|
451
|
+
assert.strictEqual(element.playlistType, 'nonsense', 'the playlist type is parsed');
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// #EXT-X-BYTERANGE
|
|
455
|
+
QUnit.test('parses minimal #EXT-X-BYTERANGE tags', function(assert) {
|
|
456
|
+
const manifest = '#EXT-X-BYTERANGE\n';
|
|
457
|
+
let element;
|
|
458
|
+
|
|
459
|
+
this.parseStream.on('data', function(elem) {
|
|
460
|
+
element = elem;
|
|
461
|
+
});
|
|
462
|
+
this.lineStream.push(manifest);
|
|
463
|
+
|
|
464
|
+
assert.ok(element, 'an event was triggered');
|
|
465
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
466
|
+
assert.strictEqual(element.tagType, 'byterange', 'the tag type is byterange');
|
|
467
|
+
assert.ok(!('length' in element), 'no length is present');
|
|
468
|
+
assert.ok(!('offset' in element), 'no offset is present');
|
|
469
|
+
});
|
|
470
|
+
QUnit.test('parses #EXT-X-BYTERANGE with length and offset', function(assert) {
|
|
471
|
+
let manifest = '#EXT-X-BYTERANGE:45\n';
|
|
472
|
+
let element;
|
|
473
|
+
|
|
474
|
+
this.parseStream.on('data', function(elem) {
|
|
475
|
+
element = elem;
|
|
476
|
+
});
|
|
477
|
+
this.lineStream.push(manifest);
|
|
478
|
+
|
|
479
|
+
assert.ok(element, 'an event was triggered');
|
|
480
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
481
|
+
assert.strictEqual(element.tagType, 'byterange', 'the tag type is byterange');
|
|
482
|
+
assert.strictEqual(element.length, 45, 'length is parsed');
|
|
483
|
+
assert.ok(!('offset' in element), 'no offset is present');
|
|
484
|
+
|
|
485
|
+
manifest = '#EXT-X-BYTERANGE:108@16\n';
|
|
486
|
+
this.lineStream.push(manifest);
|
|
487
|
+
assert.ok(element, 'an event was triggered');
|
|
488
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
489
|
+
assert.strictEqual(element.tagType, 'byterange', 'the tag type is byterange');
|
|
490
|
+
assert.strictEqual(element.length, 108, 'length is parsed');
|
|
491
|
+
assert.strictEqual(element.offset, 16, 'offset is parsed');
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
// #EXT-X-ALLOW-CACHE
|
|
495
|
+
QUnit.test('parses minimal #EXT-X-ALLOW-CACHE tags', function(assert) {
|
|
496
|
+
const manifest = '#EXT-X-ALLOW-CACHE:\n';
|
|
497
|
+
let element;
|
|
498
|
+
|
|
499
|
+
this.parseStream.on('data', function(elem) {
|
|
500
|
+
element = elem;
|
|
501
|
+
});
|
|
502
|
+
this.lineStream.push(manifest);
|
|
503
|
+
|
|
504
|
+
assert.ok(element, 'an event was triggered');
|
|
505
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
506
|
+
assert.strictEqual(element.tagType, 'allow-cache', 'the tag type is allow-cache');
|
|
507
|
+
assert.ok(!('allowed' in element), 'no allowed is present');
|
|
508
|
+
});
|
|
509
|
+
QUnit.test('parses valid #EXT-X-ALLOW-CACHE tags', function(assert) {
|
|
510
|
+
let manifest = '#EXT-X-ALLOW-CACHE:YES\n';
|
|
511
|
+
let element;
|
|
512
|
+
|
|
513
|
+
this.parseStream.on('data', function(elem) {
|
|
514
|
+
element = elem;
|
|
515
|
+
});
|
|
516
|
+
this.lineStream.push(manifest);
|
|
517
|
+
|
|
518
|
+
assert.ok(element, 'an event was triggered');
|
|
519
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
520
|
+
assert.strictEqual(element.tagType, 'allow-cache', 'the tag type is allow-cache');
|
|
521
|
+
assert.ok(element.allowed, 'allowed is parsed');
|
|
522
|
+
|
|
523
|
+
manifest = '#EXT-X-ALLOW-CACHE:NO\n';
|
|
524
|
+
this.lineStream.push(manifest);
|
|
525
|
+
|
|
526
|
+
assert.ok(element, 'an event was triggered');
|
|
527
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
528
|
+
assert.strictEqual(element.tagType, 'allow-cache', 'the tag type is allow-cache');
|
|
529
|
+
assert.ok(!element.allowed, 'allowed is parsed');
|
|
530
|
+
});
|
|
531
|
+
// #EXT-X-MAP
|
|
532
|
+
QUnit.test('parses minimal #EXT-X-MAP tags', function(assert) {
|
|
533
|
+
const manifest = '#EXT-X-MAP:URI="init.m4s"\n';
|
|
534
|
+
let element;
|
|
535
|
+
|
|
536
|
+
this.parseStream.on('data', function(elem) {
|
|
537
|
+
element = elem;
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
this.lineStream.push(manifest);
|
|
541
|
+
assert.ok(element, 'an event was triggered');
|
|
542
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
543
|
+
assert.strictEqual(element.tagType, 'map', 'the tag type is map');
|
|
544
|
+
assert.strictEqual(element.uri, 'init.m4s', 'parsed the uri');
|
|
545
|
+
});
|
|
546
|
+
QUnit.test('parses #EXT-X-MAP tags with a byterange', function(assert) {
|
|
547
|
+
const manifest = '#EXT-X-MAP:URI="0.m4s", BYTERANGE="1000@23"\n';
|
|
548
|
+
let element;
|
|
549
|
+
|
|
550
|
+
this.parseStream.on('data', function(elem) {
|
|
551
|
+
element = elem;
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
this.lineStream.push(manifest);
|
|
555
|
+
assert.ok(element, 'an event was triggered');
|
|
556
|
+
assert.strictEqual(element.uri, '0.m4s', 'parsed the uri');
|
|
557
|
+
assert.strictEqual(
|
|
558
|
+
element.byterange.length,
|
|
559
|
+
1000,
|
|
560
|
+
'parsed the byterange length'
|
|
561
|
+
);
|
|
562
|
+
assert.strictEqual(
|
|
563
|
+
element.byterange.offset,
|
|
564
|
+
23,
|
|
565
|
+
'parsed the byterange offset'
|
|
566
|
+
);
|
|
567
|
+
});
|
|
568
|
+
QUnit.test('parses #EXT-X-MAP tags with arbitrary attributes', function(assert) {
|
|
569
|
+
const manifest = '#EXT-X-MAP:URI="init.mp4", SOMETHING=YES,BYTERANGE="720@0"\n';
|
|
570
|
+
let element;
|
|
571
|
+
|
|
572
|
+
this.parseStream.on('data', function(elem) {
|
|
573
|
+
element = elem;
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
this.lineStream.push(manifest);
|
|
577
|
+
assert.ok(element, 'an event was triggered');
|
|
578
|
+
assert.strictEqual(element.uri, 'init.mp4', 'parsed the uri');
|
|
579
|
+
assert.strictEqual(
|
|
580
|
+
element.byterange.length,
|
|
581
|
+
720,
|
|
582
|
+
'parsed the byterange length'
|
|
583
|
+
);
|
|
584
|
+
assert.strictEqual(
|
|
585
|
+
element.byterange.offset,
|
|
586
|
+
0,
|
|
587
|
+
'parsed the byterange offset'
|
|
588
|
+
);
|
|
589
|
+
});
|
|
590
|
+
// #EXT-X-STREAM-INF
|
|
591
|
+
QUnit.test('parses minimal #EXT-X-STREAM-INF tags', function(assert) {
|
|
592
|
+
const manifest = '#EXT-X-STREAM-INF\n';
|
|
593
|
+
let element;
|
|
594
|
+
|
|
595
|
+
this.parseStream.on('data', function(elem) {
|
|
596
|
+
element = elem;
|
|
597
|
+
});
|
|
598
|
+
this.lineStream.push(manifest);
|
|
599
|
+
|
|
600
|
+
assert.ok(element, 'an event was triggered');
|
|
601
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
602
|
+
assert.strictEqual(element.tagType, 'stream-inf', 'the tag type is stream-inf');
|
|
603
|
+
assert.ok(!('attributes' in element), 'no attributes are present');
|
|
604
|
+
});
|
|
605
|
+
// #EXT-X-PROGRAM-DATE-TIME
|
|
606
|
+
QUnit.test('parses minimal EXT-X-PROGRAM-DATE-TIME tags', function(assert) {
|
|
607
|
+
const manifest = '#EXT-X-PROGRAM-DATE-TIME\n';
|
|
608
|
+
let element;
|
|
609
|
+
|
|
610
|
+
this.parseStream.on('data', function(elem) {
|
|
611
|
+
element = elem;
|
|
612
|
+
});
|
|
613
|
+
this.lineStream.push(manifest);
|
|
614
|
+
|
|
615
|
+
assert.ok(element, 'an event was triggered');
|
|
616
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
617
|
+
assert.strictEqual(element.tagType, 'program-date-time', 'the tag type is date-time');
|
|
618
|
+
assert.ok(!('dateTimeString' in element), 'no dateTime is present');
|
|
619
|
+
});
|
|
620
|
+
QUnit.test(
|
|
621
|
+
'parses EXT-X-PROGRAM-DATE-TIME tags with valid date-time formats',
|
|
622
|
+
function(assert) {
|
|
623
|
+
let manifest = '#EXT-X-PROGRAM-DATE-TIME:2016-06-22T09:20:16.166-04:00\n';
|
|
624
|
+
let element;
|
|
625
|
+
|
|
626
|
+
this.parseStream.on('data', function(elem) {
|
|
627
|
+
element = elem;
|
|
628
|
+
});
|
|
629
|
+
this.lineStream.push(manifest);
|
|
630
|
+
|
|
631
|
+
assert.ok(element, 'an event was triggered');
|
|
632
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
633
|
+
assert.strictEqual(element.tagType, 'program-date-time', 'the tag type is date-time');
|
|
634
|
+
assert.strictEqual(
|
|
635
|
+
element.dateTimeString, '2016-06-22T09:20:16.166-04:00',
|
|
636
|
+
'dateTimeString is parsed'
|
|
637
|
+
);
|
|
638
|
+
assert.deepEqual(
|
|
639
|
+
element.dateTimeObject, new Date('2016-06-22T09:20:16.166-04:00'),
|
|
640
|
+
'dateTimeObject is parsed'
|
|
641
|
+
);
|
|
642
|
+
|
|
643
|
+
manifest = '#EXT-X-PROGRAM-DATE-TIME:2016-06-22T09:20:16.16389Z\n';
|
|
644
|
+
this.lineStream.push(manifest);
|
|
645
|
+
|
|
646
|
+
assert.ok(element, 'an event was triggered');
|
|
647
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
648
|
+
assert.strictEqual(element.tagType, 'program-date-time', 'the tag type is date-time');
|
|
649
|
+
assert.strictEqual(
|
|
650
|
+
element.dateTimeString, '2016-06-22T09:20:16.16389Z',
|
|
651
|
+
'dateTimeString is parsed'
|
|
652
|
+
);
|
|
653
|
+
assert.deepEqual(
|
|
654
|
+
element.dateTimeObject, new Date('2016-06-22T09:20:16.16389Z'),
|
|
655
|
+
'dateTimeObject is parsed'
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
);
|
|
659
|
+
QUnit.test('parses #EXT-X-STREAM-INF with common attributes', function(assert) {
|
|
660
|
+
let manifest = '#EXT-X-STREAM-INF:BANDWIDTH=14400\n';
|
|
661
|
+
let element;
|
|
662
|
+
|
|
663
|
+
this.parseStream.on('data', function(elem) {
|
|
664
|
+
element = elem;
|
|
665
|
+
});
|
|
666
|
+
this.lineStream.push(manifest);
|
|
667
|
+
|
|
668
|
+
assert.ok(element, 'an event was triggered');
|
|
669
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
670
|
+
assert.strictEqual(element.tagType, 'stream-inf', 'the tag type is stream-inf');
|
|
671
|
+
assert.strictEqual(element.attributes.BANDWIDTH, 14400, 'bandwidth is parsed');
|
|
672
|
+
|
|
673
|
+
manifest = '#EXT-X-STREAM-INF:PROGRAM-ID=7\n';
|
|
674
|
+
this.lineStream.push(manifest);
|
|
675
|
+
|
|
676
|
+
assert.ok(element, 'an event was triggered');
|
|
677
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
678
|
+
assert.strictEqual(element.tagType, 'stream-inf', 'the tag type is stream-inf');
|
|
679
|
+
assert.strictEqual(element.attributes['PROGRAM-ID'], 7, 'program-id is parsed');
|
|
680
|
+
|
|
681
|
+
manifest = '#EXT-X-STREAM-INF:RESOLUTION=396x224\n';
|
|
682
|
+
this.lineStream.push(manifest);
|
|
683
|
+
|
|
684
|
+
assert.ok(element, 'an event was triggered');
|
|
685
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
686
|
+
assert.strictEqual(element.tagType, 'stream-inf', 'the tag type is stream-inf');
|
|
687
|
+
assert.strictEqual(element.attributes.RESOLUTION.width, 396, 'width is parsed');
|
|
688
|
+
assert.strictEqual(element.attributes.RESOLUTION.height, 224, 'heigth is parsed');
|
|
689
|
+
|
|
690
|
+
manifest = '#EXT-X-STREAM-INF:CODECS="avc1.4d400d, mp4a.40.2"\n';
|
|
691
|
+
this.lineStream.push(manifest);
|
|
692
|
+
|
|
693
|
+
assert.ok(element, 'an event was triggered');
|
|
694
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
695
|
+
assert.strictEqual(element.tagType, 'stream-inf', 'the tag type is stream-inf');
|
|
696
|
+
assert.strictEqual(
|
|
697
|
+
element.attributes.CODECS,
|
|
698
|
+
'avc1.4d400d, mp4a.40.2',
|
|
699
|
+
'codecs are parsed'
|
|
700
|
+
);
|
|
701
|
+
});
|
|
702
|
+
QUnit.test('parses #EXT-X-STREAM-INF with arbitrary attributes', function(assert) {
|
|
703
|
+
const manifest = '#EXT-X-STREAM-INF:NUMERIC=24,ALPHA=Value,MIXED=123abc\n';
|
|
704
|
+
let element;
|
|
705
|
+
|
|
706
|
+
this.parseStream.on('data', function(elem) {
|
|
707
|
+
element = elem;
|
|
708
|
+
});
|
|
709
|
+
this.lineStream.push(manifest);
|
|
710
|
+
|
|
711
|
+
assert.ok(element, 'an event was triggered');
|
|
712
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
713
|
+
assert.strictEqual(element.tagType, 'stream-inf', 'the tag type is stream-inf');
|
|
714
|
+
assert.strictEqual(element.attributes.NUMERIC, '24', 'numeric attributes are parsed');
|
|
715
|
+
assert.strictEqual(
|
|
716
|
+
element.attributes.ALPHA,
|
|
717
|
+
'Value',
|
|
718
|
+
'alphabetic attributes are parsed'
|
|
719
|
+
);
|
|
720
|
+
assert.strictEqual(element.attributes.MIXED, '123abc', 'mixed attributes are parsed');
|
|
721
|
+
});
|
|
722
|
+
// #EXT-X-ENDLIST
|
|
723
|
+
QUnit.test('parses #EXT-X-ENDLIST tags', function(assert) {
|
|
724
|
+
const manifest = '#EXT-X-ENDLIST\n';
|
|
725
|
+
let element;
|
|
726
|
+
|
|
727
|
+
this.parseStream.on('data', function(elem) {
|
|
728
|
+
element = elem;
|
|
729
|
+
});
|
|
730
|
+
this.lineStream.push(manifest);
|
|
731
|
+
|
|
732
|
+
assert.ok(element, 'an event was triggered');
|
|
733
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
734
|
+
assert.strictEqual(element.tagType, 'endlist', 'the tag type is stream-inf');
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
// #EXT-X-KEY
|
|
738
|
+
QUnit.test('parses valid #EXT-X-KEY tags', function(assert) {
|
|
739
|
+
let manifest =
|
|
740
|
+
'#EXT-X-KEY:METHOD=AES-128,URI="https://priv.example.com/key.php?r=52"\n';
|
|
741
|
+
let element;
|
|
742
|
+
|
|
743
|
+
this.parseStream.on('data', function(elem) {
|
|
744
|
+
element = elem;
|
|
745
|
+
});
|
|
746
|
+
this.lineStream.push(manifest);
|
|
747
|
+
|
|
748
|
+
assert.ok(element, 'an event was triggered');
|
|
749
|
+
assert.deepEqual(element, {
|
|
750
|
+
type: 'tag',
|
|
751
|
+
tagType: 'key',
|
|
752
|
+
attributes: {
|
|
753
|
+
METHOD: 'AES-128',
|
|
754
|
+
URI: 'https://priv.example.com/key.php?r=52'
|
|
755
|
+
}
|
|
756
|
+
}, 'parsed a valid key');
|
|
757
|
+
|
|
758
|
+
manifest = '#EXT-X-KEY:URI="https://example.com/key#1",METHOD=FutureType-1024\n';
|
|
759
|
+
this.lineStream.push(manifest);
|
|
760
|
+
assert.ok(element, 'an event was triggered');
|
|
761
|
+
assert.deepEqual(element, {
|
|
762
|
+
type: 'tag',
|
|
763
|
+
tagType: 'key',
|
|
764
|
+
attributes: {
|
|
765
|
+
METHOD: 'FutureType-1024',
|
|
766
|
+
URI: 'https://example.com/key#1'
|
|
767
|
+
}
|
|
768
|
+
}, 'parsed the attribute list independent of order');
|
|
769
|
+
|
|
770
|
+
manifest = '#EXT-X-KEY:IV=1234567890abcdef1234567890abcdef\n';
|
|
771
|
+
this.lineStream.push(manifest);
|
|
772
|
+
assert.ok(element.attributes.IV, 'detected an IV attribute');
|
|
773
|
+
assert.deepEqual(element.attributes.IV, new Uint32Array([
|
|
774
|
+
0x12345678,
|
|
775
|
+
0x90abcdef,
|
|
776
|
+
0x12345678,
|
|
777
|
+
0x90abcdef
|
|
778
|
+
]), 'parsed an IV value');
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
QUnit.test('parses minimal #EXT-X-KEY tags', function(assert) {
|
|
782
|
+
const manifest = '#EXT-X-KEY:\n';
|
|
783
|
+
let element;
|
|
784
|
+
|
|
785
|
+
this.parseStream.on('data', function(elem) {
|
|
786
|
+
element = elem;
|
|
787
|
+
});
|
|
788
|
+
this.lineStream.push(manifest);
|
|
789
|
+
|
|
790
|
+
assert.ok(element, 'an event was triggered');
|
|
791
|
+
assert.deepEqual(element, {
|
|
792
|
+
type: 'tag',
|
|
793
|
+
tagType: 'key'
|
|
794
|
+
}, 'parsed a minimal key tag');
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
QUnit.test('parses lightly-broken #EXT-X-KEY tags', function(assert) {
|
|
798
|
+
let manifest = '#EXT-X-KEY:URI=\'https://example.com/single-quote\',METHOD=AES-128\n';
|
|
799
|
+
let element;
|
|
800
|
+
|
|
801
|
+
this.parseStream.on('data', function(elem) {
|
|
802
|
+
element = elem;
|
|
803
|
+
});
|
|
804
|
+
this.lineStream.push(manifest);
|
|
805
|
+
|
|
806
|
+
assert.strictEqual(
|
|
807
|
+
element.attributes.URI,
|
|
808
|
+
'https://example.com/single-quote',
|
|
809
|
+
'parsed a single-quoted uri'
|
|
810
|
+
);
|
|
811
|
+
|
|
812
|
+
element = null;
|
|
813
|
+
manifest = '#EXT-X-KEYURI="https://example.com/key",METHOD=AES-128\n';
|
|
814
|
+
this.lineStream.push(manifest);
|
|
815
|
+
assert.strictEqual(element.tagType, 'key', 'parsed the tag type');
|
|
816
|
+
assert.strictEqual(
|
|
817
|
+
element.attributes.URI,
|
|
818
|
+
'https://example.com/key',
|
|
819
|
+
'inferred a colon after the tag type'
|
|
820
|
+
);
|
|
821
|
+
|
|
822
|
+
element = null;
|
|
823
|
+
manifest = '#EXT-X-KEY: URI = "https://example.com/key",METHOD=AES-128\n';
|
|
824
|
+
this.lineStream.push(manifest);
|
|
825
|
+
assert.strictEqual(
|
|
826
|
+
element.attributes.URI,
|
|
827
|
+
'https://example.com/key',
|
|
828
|
+
'trims and removes quotes around the URI'
|
|
829
|
+
);
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
QUnit.test('parses prefixed with 0x or 0X #EXT-X-KEY:IV tags', function(assert) {
|
|
833
|
+
let manifest;
|
|
834
|
+
let element;
|
|
835
|
+
|
|
836
|
+
this.parseStream.on('data', function(elem) {
|
|
837
|
+
element = elem;
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
manifest = '#EXT-X-KEY:IV=0x1234567890abcdef1234567890abcdef\n';
|
|
841
|
+
this.lineStream.push(manifest);
|
|
842
|
+
assert.ok(element.attributes.IV, 'detected an IV attribute');
|
|
843
|
+
assert.deepEqual(element.attributes.IV, new Uint32Array([
|
|
844
|
+
0x12345678,
|
|
845
|
+
0x90abcdef,
|
|
846
|
+
0x12345678,
|
|
847
|
+
0x90abcdef
|
|
848
|
+
]), 'parsed an IV value with 0x');
|
|
849
|
+
|
|
850
|
+
manifest = '#EXT-X-KEY:IV=0X1234567890abcdef1234567890abcdef\n';
|
|
851
|
+
this.lineStream.push(manifest);
|
|
852
|
+
assert.ok(element.attributes.IV, 'detected an IV attribute');
|
|
853
|
+
assert.deepEqual(element.attributes.IV, new Uint32Array([
|
|
854
|
+
0x12345678,
|
|
855
|
+
0x90abcdef,
|
|
856
|
+
0x12345678,
|
|
857
|
+
0x90abcdef
|
|
858
|
+
]), 'parsed an IV value with 0X');
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
// #EXT-X-START
|
|
862
|
+
QUnit.test('parses EXT-X-START tags', function(assert) {
|
|
863
|
+
const manifest = '#EXT-X-START:TIME-OFFSET=1.1\n';
|
|
864
|
+
let element;
|
|
865
|
+
|
|
866
|
+
this.parseStream.on('data', function(elem) {
|
|
867
|
+
element = elem;
|
|
868
|
+
});
|
|
869
|
+
this.lineStream.push(manifest);
|
|
870
|
+
|
|
871
|
+
assert.ok(element, 'an event was triggered');
|
|
872
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
873
|
+
assert.strictEqual(element.tagType, 'start', 'the tag type is start');
|
|
874
|
+
assert.strictEqual(element.attributes['TIME-OFFSET'], 1.1, 'parses time offset');
|
|
875
|
+
assert.strictEqual(element.attributes.PRECISE, false, 'precise defaults to false');
|
|
876
|
+
});
|
|
877
|
+
QUnit.test('parses EXT-X-START PRECISE attribute', function(assert) {
|
|
878
|
+
const manifest = '#EXT-X-START:TIME-OFFSET=1.4,PRECISE=YES\n';
|
|
879
|
+
let element;
|
|
880
|
+
|
|
881
|
+
this.parseStream.on('data', function(elem) {
|
|
882
|
+
element = elem;
|
|
883
|
+
});
|
|
884
|
+
this.lineStream.push(manifest);
|
|
885
|
+
|
|
886
|
+
assert.ok(element, 'an event was triggered');
|
|
887
|
+
assert.strictEqual(element.type, 'tag', 'the line type is tag');
|
|
888
|
+
assert.strictEqual(element.tagType, 'start', 'the tag type is start');
|
|
889
|
+
assert.strictEqual(element.attributes['TIME-OFFSET'], 1.4, 'parses time offset');
|
|
890
|
+
assert.strictEqual(element.attributes.PRECISE, true, 'parses precise attribute');
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
QUnit.test('ignores empty lines', function(assert) {
|
|
894
|
+
const manifest = '\n';
|
|
895
|
+
let event = false;
|
|
896
|
+
|
|
897
|
+
this.parseStream.on('data', function() {
|
|
898
|
+
event = true;
|
|
899
|
+
});
|
|
900
|
+
this.lineStream.push(manifest);
|
|
901
|
+
|
|
902
|
+
assert.ok(!event, 'no event is triggered');
|
|
903
|
+
});
|