Skip to content

Commit

Permalink
feat: parse content steering tags and attributes (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 authored Aug 7, 2023
1 parent 73d934c commit 42472c5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/parse-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,16 @@ export default class ParseStream extends Stream {
});
return;
}
match = (/^#EXT-X-CONTENT-STEERING:(.*)$/).exec(newLine);
if (match) {
event = {
type: 'tag',
tagType: 'content-steering'
};
event.attributes = parseAttributes(match[1]);
this.trigger('data', event);
return;
}

// unknown tag type
this.trigger('data', {
Expand Down
8 changes: 8 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,14 @@ export default class Parser extends Stream {
},
'independent-segments'() {
this.manifest.independentSegments = true;
},
'content-steering'() {
this.manifest.contentSteering = camelCaseKeys(entry.attributes);
this.warnOnMissingAttributes_(
'#EXT-X-CONTENT-STEERING',
entry.attributes,
['SERVER-URI']
);
}
})[entry.tagType] || noop).call(self);
},
Expand Down
8 changes: 8 additions & 0 deletions test/parse-stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,14 @@ QUnit.test('parses #EXT-X-STREAM-INF with common attributes', function(assert) {
'avc1.4d400d, mp4a.40.2',
'codecs are parsed'
);

manifest = '#EXT-X-STREAM-INF:PATHWAY-ID="CDN-A"\n';
this.lineStream.push(manifest);

assert.ok(element, 'an event was triggered');
assert.strictEqual(element.type, 'tag', 'the line type is tag');
assert.strictEqual(element.tagType, 'stream-inf', 'the tag type is stream-inf');
assert.strictEqual(element.attributes['PATHWAY-ID'], 'CDN-A', 'pathway-id is parsed');
});
QUnit.test('parses #EXT-X-STREAM-INF with arbitrary attributes', function(assert) {
const manifest = '#EXT-X-STREAM-INF:NUMERIC=24,ALPHA=Value,MIXED=123abc\n';
Expand Down
29 changes: 29 additions & 0 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,35 @@ QUnit.module('m3u8s', function(hooks) {
assert.equal(this.parser.manifest.independentSegments, true);
});

QUnit.test('parses #EXT-X-CONTENT-STEERING', function(assert) {
const expectedContentSteeringObject = {
serverUri: '/foo?bar=00012',
pathwayId: 'CDN-A'
};

this.parser.push('#EXT-X-CONTENT-STEERING:SERVER-URI="/foo?bar=00012",PATHWAY-ID="CDN-A"');
this.parser.end();
assert.deepEqual(this.parser.manifest.contentSteering, expectedContentSteeringObject);
});

QUnit.test('parses #EXT-X-CONTENT-STEERING without PATHWAY-ID', function(assert) {
const expectedContentSteeringObject = {
serverUri: '/bar?foo=00012'
};

this.parser.push('#EXT-X-CONTENT-STEERING:SERVER-URI="/bar?foo=00012"');
this.parser.end();
assert.deepEqual(this.parser.manifest.contentSteering, expectedContentSteeringObject);
});

QUnit.test('warns on #EXT-X-CONTENT-STEERING missing SERVER-URI', function(assert) {
const warning = ['#EXT-X-CONTENT-STEERING lacks required attribute(s): SERVER-URI'];

this.parser.push('#EXT-X-CONTENT-STEERING:PATHWAY-ID="CDN-A"');
this.parser.end();
assert.deepEqual(this.warnings, warning, 'warnings as expected');
});

QUnit.module('integration');

for (const key in testDataExpected) {
Expand Down

0 comments on commit 42472c5

Please sign in to comment.