Skip to content

Commit

Permalink
feat: expose custom M3U8 parser APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jforbes committed Jan 4, 2019
1 parent c14d415 commit 493a101
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ export default class PlaylistLoader extends EventTarget {
this.hls_ = hls;
this.withCredentials = withCredentials;

const options = hls.options_;

this.parsers = (options && options.parsers) || [];

if (!this.srcUrl) {
throw new Error('A non-empty playlist URL is required');
}
Expand Down Expand Up @@ -266,6 +270,9 @@ export default class PlaylistLoader extends EventTarget {

const parser = new M3u8Parser();

// adding custom tag parsers
this.parsers.forEach(customParser => parser.addParser(customParser));

parser.push(xhr.responseText);
parser.end();
parser.manifest.uri = url;
Expand Down Expand Up @@ -505,6 +512,9 @@ export default class PlaylistLoader extends EventTarget {

const parser = new M3u8Parser();

// adding custom tag parsers
this.parsers.forEach(customParser => parser.addParser(customParser));

parser.push(req.responseText);
parser.end();

Expand Down
26 changes: 26 additions & 0 deletions test/playlist-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,32 @@ QUnit.test('logs warning for master playlist with invalid STREAM-INF', function(
'logged a warning');
});

QUnit.test('executes custom parsers', function(assert) {
const parsers = [{
expression: /#PARSER/,
customType: 'test',
segment: true
}];

this.fakeHls.options_ = { parsers };

let loader = new PlaylistLoader('master.m3u8', this.fakeHls);

loader.load();
this.requests.pop().respond(200, null,
'#EXTM3U\n' +
'#PARSER:parsed\n' +
'#EXTINF:10,\n' +
'0.ts\n' +
'#EXT-X-ENDLIST\n');

const segment = loader.master.playlists[0].segments[0];

assert.strictEqual(segment.custom.test, '#PARSER:parsed', 'parsed custom tag');

delete this.fakeHls.options_;
});

QUnit.test('jumps to HAVE_METADATA when initialized with a media playlist',
function(assert) {
let loadedmetadatas = 0;
Expand Down

0 comments on commit 493a101

Please sign in to comment.