From 8ae4948c44142bced0ddf0a421710857366d91de Mon Sep 17 00:00:00 2001 From: Roman Pylypets Date: Wed, 2 Dec 2020 15:50:17 +0100 Subject: [PATCH] feat: parse Label element --- src/inheritAttributes.js | 8 +++++++ src/toM3u8.js | 4 ++-- test/toM3u8.test.js | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/inheritAttributes.js b/src/inheritAttributes.js index dd033640..f148c456 100644 --- a/src/inheritAttributes.js +++ b/src/inheritAttributes.js @@ -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) { diff --git a/src/toM3u8.js b/src/toM3u8.js index da87259e..872e746a 100644 --- a/src/toM3u8.js +++ b/src/toM3u8.js @@ -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}`; diff --git a/test/toM3u8.test.js b/test/toM3u8.test.js index 9d1eb813..c3238025 100644 --- a/test/toM3u8.test.js +++ b/test/toM3u8.test.js @@ -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'); +});