mirror of
https://github.com/videojs/m3u8-parser.git
synced 2026-06-06 08:22:33 +00:00
Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6869ee6fa |
3 changed files with 45 additions and 5 deletions
|
|
@ -459,8 +459,9 @@ export default class ParseStream extends Stream {
|
|||
* @param {string} options.customType the custom type to register to the output
|
||||
* @param {Function} [options.dataParser] function to parse the line into an object
|
||||
* @param {boolean} [options.segment] should tag data be attached to the segment object
|
||||
* @param {boolean} [options.multiple] does the tag appear multiple times
|
||||
*/
|
||||
addParser({expression, customType, dataParser, segment}) {
|
||||
addParser({expression, customType, dataParser, segment, multiple}) {
|
||||
if (typeof dataParser !== 'function') {
|
||||
dataParser = (line) => line;
|
||||
}
|
||||
|
|
@ -472,7 +473,8 @@ export default class ParseStream extends Stream {
|
|||
type: 'custom',
|
||||
data: dataParser(line),
|
||||
customType,
|
||||
segment
|
||||
segment,
|
||||
multiple
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -418,7 +418,11 @@ export default class Parser extends Stream {
|
|||
if (entry.segment) {
|
||||
currentUri.custom = currentUri.custom || {};
|
||||
currentUri.custom[entry.customType] = entry.data;
|
||||
// if this is manifest-level data attach to the top level manifest object
|
||||
// if this is manifest-level data attach to the top level manifest object
|
||||
} else if (entry.multiple) {
|
||||
this.manifest.custom = this.manifest.custom || {};
|
||||
this.manifest.custom[entry.customType] = this.manifest.custom[entry.customType] || [];
|
||||
this.manifest.custom[entry.customType].push(entry.data);
|
||||
} else {
|
||||
this.manifest.custom = this.manifest.custom || {};
|
||||
this.manifest.custom[entry.customType] = entry.data;
|
||||
|
|
|
|||
|
|
@ -147,13 +147,15 @@ QUnit.test('mapper does not conflict with parser', function(assert) {
|
|||
data: '#EXAMPLE',
|
||||
type: 'custom',
|
||||
customType: 'test',
|
||||
segment: undefined
|
||||
segment: undefined,
|
||||
multiple: undefined
|
||||
});
|
||||
assert.deepEqual(dataCallback.getCall(1).args[0], {
|
||||
data: '#NEW-COMMENT',
|
||||
type: 'custom',
|
||||
customType: 'test2',
|
||||
segment: undefined
|
||||
segment: undefined,
|
||||
multiple: undefined
|
||||
});
|
||||
assert.deepEqual(dataCallback.getCall(2).args[0], {
|
||||
text: 'SOMETHING-ELSE',
|
||||
|
|
@ -1053,6 +1055,38 @@ QUnit.test('can set custom parsers', function(assert) {
|
|||
assert.strictEqual(parser.manifest.custom.framerate, '29.97', 'sets framerate');
|
||||
});
|
||||
|
||||
QUnit.test('maps custom tag with multiple instances', function(assert) {
|
||||
const parser = new Parser();
|
||||
const manifest = [
|
||||
'#EXTM3U',
|
||||
'#EXT-X-DATERANGE:ID="123"',
|
||||
'#EXT-X-DATERANGE:ID="456"',
|
||||
'#EXT-X-DATERANGE:ID="789"',
|
||||
''
|
||||
].join('\n');
|
||||
|
||||
parser.addParser({
|
||||
expression: /^#EXT-X-DATERANGE/,
|
||||
customType: 'dateRanges',
|
||||
multiple: true
|
||||
});
|
||||
|
||||
parser.push(manifest);
|
||||
assert.strictEqual(parser.manifest.custom.dateRanges.length, 3);
|
||||
assert.strictEqual(
|
||||
parser.manifest.custom.dateRanges[0],
|
||||
'#EXT-X-DATERANGE:ID="123"'
|
||||
);
|
||||
assert.strictEqual(
|
||||
parser.manifest.custom.dateRanges[1],
|
||||
'#EXT-X-DATERANGE:ID="456"'
|
||||
);
|
||||
assert.strictEqual(
|
||||
parser.manifest.custom.dateRanges[2],
|
||||
'#EXT-X-DATERANGE:ID="789"'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('segment level custom data', function(assert) {
|
||||
const parser = new Parser();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue