Skip to content

Commit

Permalink
feat: parse Label element and use as m3u8 group label (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroDiver authored Mar 15, 2021
1 parent e132e40 commit 5dde0e9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/inheritAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ export const toRepresentations =
roleAttributes
);

const label = findChildren(adaptationSet, 'Label')[0];

if (label && label.childNodes.length) {
const labelVal = label.childNodes[0].nodeValue.trim();

attrs = merge(attrs, { label: labelVal });
}

const contentProtection = generateKeySystemInformation(findChildren(adaptationSet, 'ContentProtection'));

if (Object.keys(contentProtection).length) {
Expand Down
4 changes: 2 additions & 2 deletions src/toM3u8.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ export const organizeAudioPlaylists = (playlists, sidxMapping = {}) => {
playlist.attributes.role.value || '';
const language = playlist.attributes.lang || '';

let label = 'main';
let label = playlist.attributes.label || 'main';

if (language) {
if (language && !playlist.attributes.label) {
const roleLabel = role ? ` (${role})` : '';

label = `${playlist.attributes.lang}${roleLabel}`;
Expand Down
45 changes: 45 additions & 0 deletions test/toM3u8.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,3 +701,48 @@ QUnit.test('dynamic playlists with suggestedPresentationDelay', function(assert)
assert.ok('suggestedPresentationDelay' in output);
assert.deepEqual(output.suggestedPresentationDelay, 18);
});

QUnit.test('playlists with label', function(assert) {
const label = 'English with commentary';
const input = [{
attributes: {
id: '1',
codecs: 'foo;bar',
sourceDuration: 100,
duration: 0,
bandwidth: 20000,
periodIndex: 1,
mimeType: 'audio/mp4',
type: 'dynamic',
label
},
segments: []
}, {
attributes: {
id: '2',
codecs: 'foo;bar',
sourceDuration: 100,
duration: 0,
bandwidth: 10000,
periodIndex: 1,
mimeType: 'audio/mp4'
},
segments: []
}, {
attributes: {
sourceDuration: 100,
id: '1',
width: 800,
height: 600,
codecs: 'foo;bar',
duration: 0,
bandwidth: 10000,
periodIndex: 1,
mimeType: 'video/mp4'
},
segments: []
}];
const output = toM3u8(input);

assert.ok(label in output.mediaGroups.AUDIO.audio, 'label exists');
});

0 comments on commit 5dde0e9

Please sign in to comment.