Skip to content

Commit

Permalink
feat: parse Label element
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroDiver committed Dec 2, 2020
1 parent 7bf58e9 commit 1a4420b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/inheritAttributes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import decodeB64ToUint8Array from '@videojs/vhs-utils/dist/decode-b64-to-uint8-array';
import resolveUrl from '@videojs/vhs-utils/dist/resolve-url';
import window from 'global/window';
import errors from './errors';
import { parseAttributes } from './parseAttributes';
import { flatten } from './utils/list';
import { merge } from './utils/object';
import { findChildren, getContent } from './utils/xml';
import { parseAttributes } from './parseAttributes';
import errors from './errors';
import resolveUrl from '@videojs/vhs-utils/dist/resolve-url';
import decodeB64ToUint8Array from '@videojs/vhs-utils/dist/decode-b64-to-uint8-array';

const keySystemsMap = {
'urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b': 'org.w3.clearkey',
Expand Down Expand Up @@ -232,9 +232,17 @@ export const toRepresentations =
let attrs = merge(
periodAttributes,
adaptationSetAttributes,
roleAttributes
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
8 changes: 4 additions & 4 deletions src/toM3u8.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { values } from './utils/object';
import { findIndexes } from './utils/list';
import { addSegmentsToPlaylist } from './segment/segmentBase';
import { byteRangeToString } from './segment/urlType';
import { findIndexes } from './utils/list';
import { values } from './utils/object';

const mergeDiscontiguousPlaylists = playlists => {
const mergedPlaylists = values(playlists.reduce((acc, playlist) => {
Expand Down 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);
});

0 comments on commit 1a4420b

Please sign in to comment.