mpd-parser
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -0,1 +1,8 @@ | ||
<a name="0.4.0"></a> | ||
# [0.4.0](https://github.com/videojs/mpd-parser/compare/v0.3.0...v0.4.0) (2018-02-26) | ||
### Features | ||
* Adding support for segments in Period and Representation. ([#19](https://github.com/videojs/mpd-parser/issues/19)) ([8e59b38](https://github.com/videojs/mpd-parser/commit/8e59b38)) | ||
<a name="0.3.0"></a> | ||
@@ -2,0 +9,0 @@ # [0.3.0](https://github.com/videojs/mpd-parser/compare/v0.2.1...v0.3.0) (2018-02-06) |
/** | ||
* mpd-parser | ||
* @version 0.3.0 | ||
* @version 0.4.0 | ||
* @copyright 2018 Brightcove, Inc | ||
@@ -14,3 +14,3 @@ * @license Apache-2.0 | ||
var version = "0.3.0"; | ||
var version = "0.4.0"; | ||
@@ -223,3 +223,13 @@ var formatAudioPlaylist = function formatAudioPlaylist(_ref) { | ||
var shallowMerge = function shallowMerge() { | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var isObject = function isObject(obj) { | ||
return !!obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; | ||
}; | ||
var merge = function merge() { | ||
for (var _len = arguments.length, objects = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -229,8 +239,15 @@ objects[_key] = arguments[_key]; | ||
return objects.reduce(function (x, y) { | ||
return Object.keys(y).reduce(function (o, key) { | ||
o[key] = y[key]; | ||
return objects.reduce(function (result, source) { | ||
return o; | ||
}, x); | ||
Object.keys(source).forEach(function (key) { | ||
if (Array.isArray(result[key]) && Array.isArray(source[key])) { | ||
result[key] = result[key].concat(source[key]); | ||
} else if (isObject(result[key]) && isObject(source[key])) { | ||
result[key] = merge(result[key], source[key]); | ||
} else { | ||
result[key] = source[key]; | ||
} | ||
}); | ||
return result; | ||
}, {}); | ||
@@ -765,11 +782,9 @@ }; | ||
if (segmentInfo.template) { | ||
return segmentsFromTemplate(shallowMerge(segmentInfo.template, attributes), segmentInfo.timeline); | ||
return segmentsFromTemplate(merge(attributes, segmentInfo.template), segmentInfo.timeline); | ||
} | ||
if (segmentInfo.base) { | ||
return segmentsFromBase(shallowMerge(segmentInfo.base, attributes)); | ||
return segmentsFromBase(merge(attributes, segmentInfo.base)); | ||
} | ||
if (segmentInfo.list) { | ||
return segmentsFromList(shallowMerge(segmentInfo.list, attributes), segmentInfo.timeline); | ||
return segmentsFromList(merge(attributes, segmentInfo.list), segmentInfo.timeline); | ||
} | ||
@@ -874,3 +889,3 @@ }; | ||
var segmentUrls = segmentList && findChildren(segmentList, 'SegmentURL').map(function (s) { | ||
return shallowMerge({ tag: 'SegmentURL' }, getAttributes(s)); | ||
return merge({ tag: 'SegmentURL' }, getAttributes(s)); | ||
}); | ||
@@ -899,3 +914,3 @@ var segmentBase = findChildren(adaptationSet, 'SegmentBase')[0]; | ||
return { | ||
var segmentInfo = { | ||
template: template, | ||
@@ -905,10 +920,18 @@ timeline: segmentTimeline && findChildren(segmentTimeline, 'S').map(function (s) { | ||
}), | ||
list: segmentList && shallowMerge(getAttributes(segmentList), { | ||
list: segmentList && merge(getAttributes(segmentList), { | ||
segmentUrls: segmentUrls, | ||
initialization: getAttributes(segmentInitialization) | ||
}), | ||
base: segmentBase && shallowMerge(getAttributes(segmentBase), { | ||
base: segmentBase && merge(getAttributes(segmentBase), { | ||
initialization: getAttributes(segmentInitialization) | ||
}) | ||
}; | ||
Object.keys(segmentInfo).forEach(function (key) { | ||
if (!segmentInfo[key]) { | ||
delete segmentInfo[key]; | ||
} | ||
}); | ||
return segmentInfo; | ||
}; | ||
@@ -951,12 +974,13 @@ | ||
*/ | ||
var inheritBaseUrls = function inheritBaseUrls(adaptationSetAttributes, adaptationSetBaseUrls, segmentInfo) { | ||
var inheritBaseUrls = function inheritBaseUrls(adaptationSetAttributes, adaptationSetBaseUrls, adaptationSetSegmentInfo) { | ||
return function (representation) { | ||
var repBaseUrlElements = findChildren(representation, 'BaseURL'); | ||
var repBaseUrls = buildBaseUrls(adaptationSetBaseUrls, repBaseUrlElements); | ||
var attributes = shallowMerge(adaptationSetAttributes, getAttributes(representation)); | ||
var attributes = merge(adaptationSetAttributes, getAttributes(representation)); | ||
var representationSegmentInfo = getSegmentInformation(representation); | ||
return repBaseUrls.map(function (baseUrl) { | ||
return { | ||
segmentInfo: segmentInfo, | ||
attributes: shallowMerge(attributes, { baseUrl: baseUrl }) | ||
segmentInfo: merge(adaptationSetSegmentInfo, representationSegmentInfo), | ||
attributes: merge(attributes, { baseUrl: baseUrl }) | ||
}; | ||
@@ -989,3 +1013,3 @@ }); | ||
*/ | ||
var toRepresentations = function toRepresentations(periodAttributes, periodBaseUrls) { | ||
var toRepresentations = function toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo) { | ||
return function (adaptationSet) { | ||
@@ -996,7 +1020,8 @@ var adaptationSetAttributes = getAttributes(adaptationSet); | ||
var roleAttributes = { role: getAttributes(role) }; | ||
var attrs = shallowMerge(periodAttributes, adaptationSetAttributes, roleAttributes); | ||
var attrs = merge(periodAttributes, adaptationSetAttributes, roleAttributes); | ||
var segmentInfo = getSegmentInformation(adaptationSet); | ||
var representations = findChildren(adaptationSet, 'Representation'); | ||
var adaptationSetSegmentInfo = merge(periodSegmentInfo, segmentInfo); | ||
return flatten(representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, segmentInfo))); | ||
return flatten(representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, adaptationSetSegmentInfo))); | ||
}; | ||
@@ -1033,6 +1058,8 @@ }; | ||
var periodBaseUrls = buildBaseUrls(mpdBaseUrls, findChildren(period, 'BaseURL')); | ||
var periodAttributes = shallowMerge({ periodIndex: periodIndex }, mpdAttributes); | ||
var periodAtt = getAttributes(period); | ||
var periodAttributes = merge(mpdAttributes, periodAtt, { periodIndex: periodIndex }); | ||
var adaptationSets = findChildren(period, 'AdaptationSet'); | ||
var periodSegmentInfo = getSegmentInformation(period); | ||
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls))); | ||
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo))); | ||
}; | ||
@@ -1039,0 +1066,0 @@ }; |
/** | ||
* mpd-parser | ||
* @version 0.3.0 | ||
* @version 0.4.0 | ||
* @copyright 2018 Brightcove, Inc | ||
@@ -10,3 +10,3 @@ * @license Apache-2.0 | ||
var version = "0.3.0"; | ||
var version = "0.4.0"; | ||
@@ -219,3 +219,13 @@ var formatAudioPlaylist = function formatAudioPlaylist(_ref) { | ||
var shallowMerge = function shallowMerge() { | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var isObject = function isObject(obj) { | ||
return !!obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; | ||
}; | ||
var merge = function merge() { | ||
for (var _len = arguments.length, objects = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -225,8 +235,15 @@ objects[_key] = arguments[_key]; | ||
return objects.reduce(function (x, y) { | ||
return Object.keys(y).reduce(function (o, key) { | ||
o[key] = y[key]; | ||
return objects.reduce(function (result, source) { | ||
return o; | ||
}, x); | ||
Object.keys(source).forEach(function (key) { | ||
if (Array.isArray(result[key]) && Array.isArray(source[key])) { | ||
result[key] = result[key].concat(source[key]); | ||
} else if (isObject(result[key]) && isObject(source[key])) { | ||
result[key] = merge(result[key], source[key]); | ||
} else { | ||
result[key] = source[key]; | ||
} | ||
}); | ||
return result; | ||
}, {}); | ||
@@ -761,11 +778,9 @@ }; | ||
if (segmentInfo.template) { | ||
return segmentsFromTemplate(shallowMerge(segmentInfo.template, attributes), segmentInfo.timeline); | ||
return segmentsFromTemplate(merge(attributes, segmentInfo.template), segmentInfo.timeline); | ||
} | ||
if (segmentInfo.base) { | ||
return segmentsFromBase(shallowMerge(segmentInfo.base, attributes)); | ||
return segmentsFromBase(merge(attributes, segmentInfo.base)); | ||
} | ||
if (segmentInfo.list) { | ||
return segmentsFromList(shallowMerge(segmentInfo.list, attributes), segmentInfo.timeline); | ||
return segmentsFromList(merge(attributes, segmentInfo.list), segmentInfo.timeline); | ||
} | ||
@@ -870,3 +885,3 @@ }; | ||
var segmentUrls = segmentList && findChildren(segmentList, 'SegmentURL').map(function (s) { | ||
return shallowMerge({ tag: 'SegmentURL' }, getAttributes(s)); | ||
return merge({ tag: 'SegmentURL' }, getAttributes(s)); | ||
}); | ||
@@ -895,3 +910,3 @@ var segmentBase = findChildren(adaptationSet, 'SegmentBase')[0]; | ||
return { | ||
var segmentInfo = { | ||
template: template, | ||
@@ -901,10 +916,18 @@ timeline: segmentTimeline && findChildren(segmentTimeline, 'S').map(function (s) { | ||
}), | ||
list: segmentList && shallowMerge(getAttributes(segmentList), { | ||
list: segmentList && merge(getAttributes(segmentList), { | ||
segmentUrls: segmentUrls, | ||
initialization: getAttributes(segmentInitialization) | ||
}), | ||
base: segmentBase && shallowMerge(getAttributes(segmentBase), { | ||
base: segmentBase && merge(getAttributes(segmentBase), { | ||
initialization: getAttributes(segmentInitialization) | ||
}) | ||
}; | ||
Object.keys(segmentInfo).forEach(function (key) { | ||
if (!segmentInfo[key]) { | ||
delete segmentInfo[key]; | ||
} | ||
}); | ||
return segmentInfo; | ||
}; | ||
@@ -947,12 +970,13 @@ | ||
*/ | ||
var inheritBaseUrls = function inheritBaseUrls(adaptationSetAttributes, adaptationSetBaseUrls, segmentInfo) { | ||
var inheritBaseUrls = function inheritBaseUrls(adaptationSetAttributes, adaptationSetBaseUrls, adaptationSetSegmentInfo) { | ||
return function (representation) { | ||
var repBaseUrlElements = findChildren(representation, 'BaseURL'); | ||
var repBaseUrls = buildBaseUrls(adaptationSetBaseUrls, repBaseUrlElements); | ||
var attributes = shallowMerge(adaptationSetAttributes, getAttributes(representation)); | ||
var attributes = merge(adaptationSetAttributes, getAttributes(representation)); | ||
var representationSegmentInfo = getSegmentInformation(representation); | ||
return repBaseUrls.map(function (baseUrl) { | ||
return { | ||
segmentInfo: segmentInfo, | ||
attributes: shallowMerge(attributes, { baseUrl: baseUrl }) | ||
segmentInfo: merge(adaptationSetSegmentInfo, representationSegmentInfo), | ||
attributes: merge(attributes, { baseUrl: baseUrl }) | ||
}; | ||
@@ -985,3 +1009,3 @@ }); | ||
*/ | ||
var toRepresentations = function toRepresentations(periodAttributes, periodBaseUrls) { | ||
var toRepresentations = function toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo) { | ||
return function (adaptationSet) { | ||
@@ -992,7 +1016,8 @@ var adaptationSetAttributes = getAttributes(adaptationSet); | ||
var roleAttributes = { role: getAttributes(role) }; | ||
var attrs = shallowMerge(periodAttributes, adaptationSetAttributes, roleAttributes); | ||
var attrs = merge(periodAttributes, adaptationSetAttributes, roleAttributes); | ||
var segmentInfo = getSegmentInformation(adaptationSet); | ||
var representations = findChildren(adaptationSet, 'Representation'); | ||
var adaptationSetSegmentInfo = merge(periodSegmentInfo, segmentInfo); | ||
return flatten(representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, segmentInfo))); | ||
return flatten(representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, adaptationSetSegmentInfo))); | ||
}; | ||
@@ -1029,6 +1054,8 @@ }; | ||
var periodBaseUrls = buildBaseUrls(mpdBaseUrls, findChildren(period, 'BaseURL')); | ||
var periodAttributes = shallowMerge({ periodIndex: periodIndex }, mpdAttributes); | ||
var periodAtt = getAttributes(period); | ||
var periodAttributes = merge(mpdAttributes, periodAtt, { periodIndex: periodIndex }); | ||
var adaptationSets = findChildren(period, 'AdaptationSet'); | ||
var periodSegmentInfo = getSegmentInformation(period); | ||
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls))); | ||
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo))); | ||
}; | ||
@@ -1035,0 +1062,0 @@ }; |
/** | ||
* mpd-parser | ||
* @version 0.3.0 | ||
* @version 0.4.0 | ||
* @copyright 2018 Brightcove, Inc | ||
@@ -13,3 +13,3 @@ * @license Apache-2.0 | ||
var version = "0.3.0"; | ||
var version = "0.4.0"; | ||
@@ -222,3 +222,13 @@ var formatAudioPlaylist = function formatAudioPlaylist(_ref) { | ||
var shallowMerge = function shallowMerge() { | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var isObject = function isObject(obj) { | ||
return !!obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; | ||
}; | ||
var merge = function merge() { | ||
for (var _len = arguments.length, objects = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -228,8 +238,15 @@ objects[_key] = arguments[_key]; | ||
return objects.reduce(function (x, y) { | ||
return Object.keys(y).reduce(function (o, key) { | ||
o[key] = y[key]; | ||
return objects.reduce(function (result, source) { | ||
return o; | ||
}, x); | ||
Object.keys(source).forEach(function (key) { | ||
if (Array.isArray(result[key]) && Array.isArray(source[key])) { | ||
result[key] = result[key].concat(source[key]); | ||
} else if (isObject(result[key]) && isObject(source[key])) { | ||
result[key] = merge(result[key], source[key]); | ||
} else { | ||
result[key] = source[key]; | ||
} | ||
}); | ||
return result; | ||
}, {}); | ||
@@ -947,11 +964,9 @@ }; | ||
if (segmentInfo.template) { | ||
return segmentsFromTemplate(shallowMerge(segmentInfo.template, attributes), segmentInfo.timeline); | ||
return segmentsFromTemplate(merge(attributes, segmentInfo.template), segmentInfo.timeline); | ||
} | ||
if (segmentInfo.base) { | ||
return segmentsFromBase(shallowMerge(segmentInfo.base, attributes)); | ||
return segmentsFromBase(merge(attributes, segmentInfo.base)); | ||
} | ||
if (segmentInfo.list) { | ||
return segmentsFromList(shallowMerge(segmentInfo.list, attributes), segmentInfo.timeline); | ||
return segmentsFromList(merge(attributes, segmentInfo.list), segmentInfo.timeline); | ||
} | ||
@@ -1056,3 +1071,3 @@ }; | ||
var segmentUrls = segmentList && findChildren(segmentList, 'SegmentURL').map(function (s) { | ||
return shallowMerge({ tag: 'SegmentURL' }, getAttributes(s)); | ||
return merge({ tag: 'SegmentURL' }, getAttributes(s)); | ||
}); | ||
@@ -1081,3 +1096,3 @@ var segmentBase = findChildren(adaptationSet, 'SegmentBase')[0]; | ||
return { | ||
var segmentInfo = { | ||
template: template, | ||
@@ -1087,10 +1102,18 @@ timeline: segmentTimeline && findChildren(segmentTimeline, 'S').map(function (s) { | ||
}), | ||
list: segmentList && shallowMerge(getAttributes(segmentList), { | ||
list: segmentList && merge(getAttributes(segmentList), { | ||
segmentUrls: segmentUrls, | ||
initialization: getAttributes(segmentInitialization) | ||
}), | ||
base: segmentBase && shallowMerge(getAttributes(segmentBase), { | ||
base: segmentBase && merge(getAttributes(segmentBase), { | ||
initialization: getAttributes(segmentInitialization) | ||
}) | ||
}; | ||
Object.keys(segmentInfo).forEach(function (key) { | ||
if (!segmentInfo[key]) { | ||
delete segmentInfo[key]; | ||
} | ||
}); | ||
return segmentInfo; | ||
}; | ||
@@ -1133,12 +1156,13 @@ | ||
*/ | ||
var inheritBaseUrls = function inheritBaseUrls(adaptationSetAttributes, adaptationSetBaseUrls, segmentInfo) { | ||
var inheritBaseUrls = function inheritBaseUrls(adaptationSetAttributes, adaptationSetBaseUrls, adaptationSetSegmentInfo) { | ||
return function (representation) { | ||
var repBaseUrlElements = findChildren(representation, 'BaseURL'); | ||
var repBaseUrls = buildBaseUrls(adaptationSetBaseUrls, repBaseUrlElements); | ||
var attributes = shallowMerge(adaptationSetAttributes, getAttributes(representation)); | ||
var attributes = merge(adaptationSetAttributes, getAttributes(representation)); | ||
var representationSegmentInfo = getSegmentInformation(representation); | ||
return repBaseUrls.map(function (baseUrl) { | ||
return { | ||
segmentInfo: segmentInfo, | ||
attributes: shallowMerge(attributes, { baseUrl: baseUrl }) | ||
segmentInfo: merge(adaptationSetSegmentInfo, representationSegmentInfo), | ||
attributes: merge(attributes, { baseUrl: baseUrl }) | ||
}; | ||
@@ -1171,3 +1195,3 @@ }); | ||
*/ | ||
var toRepresentations = function toRepresentations(periodAttributes, periodBaseUrls) { | ||
var toRepresentations = function toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo) { | ||
return function (adaptationSet) { | ||
@@ -1178,7 +1202,8 @@ var adaptationSetAttributes = getAttributes(adaptationSet); | ||
var roleAttributes = { role: getAttributes(role) }; | ||
var attrs = shallowMerge(periodAttributes, adaptationSetAttributes, roleAttributes); | ||
var attrs = merge(periodAttributes, adaptationSetAttributes, roleAttributes); | ||
var segmentInfo = getSegmentInformation(adaptationSet); | ||
var representations = findChildren(adaptationSet, 'Representation'); | ||
var adaptationSetSegmentInfo = merge(periodSegmentInfo, segmentInfo); | ||
return flatten(representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, segmentInfo))); | ||
return flatten(representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, adaptationSetSegmentInfo))); | ||
}; | ||
@@ -1215,6 +1240,8 @@ }; | ||
var periodBaseUrls = buildBaseUrls(mpdBaseUrls, findChildren(period, 'BaseURL')); | ||
var periodAttributes = shallowMerge({ periodIndex: periodIndex }, mpdAttributes); | ||
var periodAtt = getAttributes(period); | ||
var periodAttributes = merge(mpdAttributes, periodAtt, { periodIndex: periodIndex }); | ||
var adaptationSets = findChildren(period, 'AdaptationSet'); | ||
var periodSegmentInfo = getSegmentInformation(period); | ||
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls))); | ||
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo))); | ||
}; | ||
@@ -1221,0 +1248,0 @@ }; |
/** | ||
* mpd-parser | ||
* @version 0.3.0 | ||
* @version 0.4.0 | ||
* @copyright 2018 Brightcove, Inc | ||
* @license Apache-2.0 | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.mpdParser={})}(this,function(e){"use strict";var t=function(e){return e.reduce(function(e,t){var r=t.attributes.role&&t.attributes.role.value||"main",n=t.attributes.lang||"",i="main";return n&&(i=t.attributes.lang+" ("+r+")"),e[i]&&e[i].playlists[0].attributes.BANDWIDTH>t.attributes.bandwidth?e:(e[i]={language:n,autoselect:!0,default:"main"===r,playlists:[function(e){var t,r=e.attributes,n=e.segments;return{attributes:(t={NAME:r.id,BANDWIDTH:parseInt(r.bandwidth,10),CODECS:r.codecs},t["PROGRAM-ID"]=1,t),uri:"",endList:!0,timeline:r.periodIndex,resolvedUri:"",segments:n}}(t)],uri:""},e)},{})},r=function(e){return e.reduce(function(e,t){var r=t.attributes.lang||"text";return e[r]?e:(e[r]={language:r,default:!1,autoselect:!1,playlists:[function(e){var t,r=e.attributes,n=e.segments;return void 0===n&&(n=[{uri:r.baseUrl,timeline:r.periodIndex,resolvedUri:r.baseUrl||"",duration:r.sourceDuration}]),{attributes:(t={NAME:r.id,BANDWIDTH:parseInt(r.bandwidth,10)},t["PROGRAM-ID"]=1,t),uri:"",endList:!0,timeline:r.periodIndex,resolvedUri:r.baseUrl||"",segments:n}}(t)],uri:""},e)},{})},n=function(e){var t,r=e.attributes,n=e.segments;return{attributes:(t={NAME:r.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:parseInt(r.width,10),height:parseInt(r.height,10)},CODECS:r.codecs,BANDWIDTH:parseInt(r.bandwidth,10)},t["PROGRAM-ID"]=1,t),uri:"",endList:!0,timeline:r.periodIndex,resolvedUri:"",segments:n}},i=function(e){return e.reduce(function(e,t){return e.concat(t)},[])},a=function(e){if(!e.length)return[];for(var t=[],r=0;r<e.length;r++)t.push(e[r]);return t},o=function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.reduce(function(e,t){return Object.keys(t).reduce(function(e,r){return e[r]=t[r],e},e)},{})},u=function(e){return e&&e.attributes?a(e.attributes).reduce(function(e,t){return e[t.name]=t.value,e},{}):{}},s="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},l=function(e,t){return t={exports:{}},e(t,t.exports),t.exports}(function(e,t){!function(t){var r=/^((?:[^\/;?#]+:)?)(\/\/[^\/\;?#]*)?(.*?)??(;.*?)?(\?.*?)?(#.*?)?$/,n=/^([^\/;?#]*)(.*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g,o={buildAbsoluteURL:function(e,t,r){if(r=r||{},e=e.trim(),!(t=t.trim())){if(!r.alwaysNormalize)return e;var i=this.parseURL(e);if(!u)throw new Error("Error trying to parse base URL.");return i.path=o.normalizePath(i.path),o.buildURLFromParts(i)}var a=this.parseURL(t);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=o.normalizePath(a.path),o.buildURLFromParts(a)):t;var u=this.parseURL(e);if(!u)throw new Error("Error trying to parse base URL.");if(!u.netLoc&&u.path&&"/"!==u.path[0]){var s=n.exec(u.path);u.netLoc=s[1],u.path=s[2]}u.netLoc&&!u.path&&(u.path="/");var l={scheme:u.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(l.netLoc=u.netLoc,"/"!==a.path[0]))if(a.path){var d=u.path,p=d.substring(0,d.lastIndexOf("/")+1)+a.path;l.path=o.normalizePath(p)}else l.path=u.path,a.params||(l.params=u.params,a.query||(l.query=u.query));return null===l.path&&(l.path=r.alwaysNormalize?o.normalizePath(a.path):a.path),o.buildURLFromParts(l)},parseURL:function(e){var t=r.exec(e);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(i,"");e.length!==(e=e.replace(a,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}};e.exports=o}()}),d="undefined"!=typeof window?window:void 0!==s?s:"undefined"!=typeof self?self:{},p=function(e,t){return/^[a-z]+:/i.test(t)?t:(/\/\//i.test(e)||(e=l.buildAbsoluteURL(d.location.href,e)),l.buildAbsoluteURL(e,t))},c=function(e){var t=e.baseUrl,r=void 0===t?"":t,n=e.source,i=void 0===n?"":n,a=e.range,o=void 0===a?"":a,u={uri:i,resolvedUri:p(r||"",i)};if(o){var s=o.split("-"),l=parseInt(s[0],10),d=parseInt(s[1],10);u.byterange={length:d-l,offset:l}}return u},f=function(e,t,r,n,i){for(var a=[],o=-1,u=0;u<n.length;u++){var s=n[u],l=parseInt(s.d,10),d=parseInt(s.r||0,10),p=parseInt(s.t||0,10);o<0&&(o=p),p&&p>o&&(o=p);var c=void 0;if(d<0){var f=u+1;c=f===n.length?(i*r-o)/l:(parseInt(n[f].t,10)-o)/l}else c=d+1;for(var m=e+a.length+c,v=e+a.length;v<m;)a.push({number:v,duration:l/r,time:o,timeline:t}),o+=l,v++}return a},m=function(e,t,r,n,i){var a=Math.ceil(i/(n/r));return function(e,t){for(var r=[],n=e;n<t;n++)r.push(n);return r}(e,e+a).map(function(o,u){var s={number:o,duration:n/r,timeline:t};return u===a-1&&(s.duration=i-s.duration*u),s.time=(s.number-e)*n,s})},v=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,h=function(e,t){return e.replace(v,function(e){return function(t,r,n,i){if("$$"===t)return"$";if(void 0===e[r])return t;var a=""+e[r];return"RepresentationID"===r?a:(i=n?parseInt(i,10):1,a.length>=i?a:""+new Array(i-a.length+1).join("0")+a)}}(t))},g=function(e,t){var r={RepresentationID:e.id,Bandwidth:parseInt(e.bandwidth||0,10)},n=e.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=c({baseUrl:e.baseUrl,source:h(i.sourceURL,r),range:i.range});return function(e,t){var r=parseInt(e.startNumber||1,10),n=parseInt(e.timescale||1,10);return e.duration||t?e.duration?m(r,e.periodIndex,n,parseInt(e.duration,10),e.sourceDuration):f(r,e.periodIndex,n,t,e.sourceDuration):[{number:r,duration:e.sourceDuration,time:0,timeline:e.periodIndex}]}(e,t).map(function(t){r.Number=t.number,r.Time=t.time;var n=h(e.media||"",r);return{uri:n,timeline:t.timeline,duration:t.duration,resolvedUri:p(e.baseUrl||"",n),map:a}})},b="INVALID_NUMBER_OF_PERIOD",I="DASH_EMPTY_MANIFEST",U="DASH_INVALID_XML",L="NO_BASE_URL",R="SEGMENT_TIME_UNSPECIFIED",D=function(e,t){var r=e.timescale,n=void 0===r?1:r,i=e.duration,a=e.segmentUrls,o=void 0===a?[]:a,u=e.periodIndex,s=void 0===u?0:u,l=e.startNumber,d=void 0===l?1:l;if(!i&&!t||i&&t)throw new Error(R);var p=parseInt(n,10),v=parseInt(d,10),h=o.map(function(t){return function(e,t){var r=e.baseUrl,n=e.initialization,i=void 0===n?{}:n,a=c({baseUrl:r,source:i.sourceURL,range:i.range}),o=c({baseUrl:r,source:t.media,range:t.mediaRange});return o.map=a,o}(e,t)}),g=void 0;if(i){var b=parseInt(i,10);g=m(v,s,p,b,e.sourceDuration)}t&&(g=f(v,s,p,t,e.sourceDuration));return g.map(function(e,t){if(h[t]){var r=h[t];return r.timeline=e.timeline,r.duration=e.duration,r}}).filter(function(e){return e})},w=function(e,t){return e.template?g(o(e.template,t),e.timeline):e.base?function(e){var t=e.baseUrl,r=e.initialization,n=void 0===r?{}:r,i=e.sourceDuration,a=e.timescale,o=void 0===a?1:a,u=e.startNumber,s=void 0===u?1:u,l=e.periodIndex,d=void 0===l?0:l,p=e.indexRange,f=void 0===p?"":p,v=e.duration;if(!t)throw new Error(L);var h=c({baseUrl:t,source:n.sourceURL,range:n.range}),g=c({baseUrl:t,source:t,range:f});g.map=h;var b=parseInt(o,10);if(v){var I=parseInt(v,10),U=parseInt(s,10),R=m(U,d,b,I,i);R.length>=1&&(g.duration=R[0].duration,g.timeline=R[0].timeline)}else i&&(g.duration=i/b,g.timeline=0);return[g]}(o(e.base,t)):e.list?D(o(e.list,t),e.timeline):void 0},y=function(e,t){return a(e.childNodes).filter(function(e){return e.tagName===t})},E=function(e,t){return t.length?i(e.map(function(e){return t.map(function(t){return p(e,function(e){return e.textContent.trim()}(t))})})):e},S=function(e,t){return function(r){var n=u(r),a=E(t,y(r,"BaseURL")),s=y(r,"Role")[0],l={role:u(s)},d=o(e,n,l),p=function(e){var t=y(e,"SegmentTemplate")[0],r=y(e,"SegmentList")[0],n=r&&y(r,"SegmentURL").map(function(e){return o({tag:"SegmentURL"},u(e))}),i=y(e,"SegmentBase")[0],a=r||t,s=a&&y(a,"SegmentTimeline")[0],l=r||i||t,d=l&&y(l,"Initialization")[0],p=t&&u(t);return p&&d?p.initialization=d&&u(d):p&&p.initialization&&(p.initialization={sourceURL:p.initialization}),{template:p,timeline:s&&y(s,"S").map(function(e){return u(e)}),list:r&&o(u(r),{segmentUrls:n,initialization:u(d)}),base:i&&o(u(i),{initialization:u(d)})}}(r),c=y(r,"Representation");return i(c.map(function(e,t,r){return function(n){var i=y(n,"BaseURL"),a=E(t,i),s=o(e,u(n));return a.map(function(e){return{segmentInfo:r,attributes:o(s,{baseUrl:e})}})}}(d,a,p)))}},N=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=y(e,"Period");if(1!==r.length)throw new Error(b);var n=u(e),a=E([t],y(e,"BaseURL"));return n.sourceDuration=n.mediaPresentationDuration?function(e){var t=/P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/.exec(e);if(!t)return 0;var r=t.slice(1),n=r[0],i=r[1],a=r[2],o=r[3],u=r[4],s=r[5];return 31536e3*parseFloat(n||0)+2592e3*parseFloat(i||0)+86400*parseFloat(a||0)+3600*parseFloat(o||0)+60*parseFloat(u||0)+parseFloat(s||0)}(n.mediaPresentationDuration):0,i(r.map(function(e,t){return function(r,n){var a=E(t,y(r,"BaseURL")),u=o({periodIndex:n},e),s=y(r,"AdaptationSet");return i(s.map(S(u,a)))}}(n,a)))};e.VERSION="0.3.0",e.parse=function(e,i){return function(e){var i;if(!e.length)return{};var a=e[0].attributes.sourceDuration,o=e.filter(function(e){var t=e.attributes;return"video/mp4"===t.mimeType||"video"===t.contentType}).map(n),u=e.filter(function(e){var t=e.attributes;return"audio/mp4"===t.mimeType||"audio"===t.contentType}),s=e.filter(function(e){var t=e.attributes;return"text/vtt"===t.mimeType||"text"===t.contentType}),l={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(i={AUDIO:{},VIDEO:{}},i["CLOSED-CAPTIONS"]={},i.SUBTITLES={},i),uri:"",duration:a,playlists:o};return u.length&&(l.mediaGroups.AUDIO.audio=t(u)),s.length&&(l.mediaGroups.SUBTITLES.subs=r(s)),l}(function(e){return e.map(function(e){var t=e.attributes,r=e.segmentInfo;return{attributes:t,segments:w(r,t)}})}(N(function(e){if(""===e)throw new Error(I);var t=(new d.DOMParser).parseFromString(e,"application/xml"),r=t&&"MPD"===t.documentElement.tagName?t.documentElement:null;if(!r||r&&r.getElementsByTagName("parsererror").length>0)throw new Error(U);return r}(e),i)))}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.mpdParser={})}(this,function(e){"use strict";var t=function(e){return e.reduce(function(e,t){var r=t.attributes.role&&t.attributes.role.value||"main",n=t.attributes.lang||"",i="main";return n&&(i=t.attributes.lang+" ("+r+")"),e[i]&&e[i].playlists[0].attributes.BANDWIDTH>t.attributes.bandwidth?e:(e[i]={language:n,autoselect:!0,default:"main"===r,playlists:[function(e){var t,r=e.attributes,n=e.segments;return{attributes:(t={NAME:r.id,BANDWIDTH:parseInt(r.bandwidth,10),CODECS:r.codecs},t["PROGRAM-ID"]=1,t),uri:"",endList:!0,timeline:r.periodIndex,resolvedUri:"",segments:n}}(t)],uri:""},e)},{})},r=function(e){return e.reduce(function(e,t){var r=t.attributes.lang||"text";return e[r]?e:(e[r]={language:r,default:!1,autoselect:!1,playlists:[function(e){var t,r=e.attributes,n=e.segments;return void 0===n&&(n=[{uri:r.baseUrl,timeline:r.periodIndex,resolvedUri:r.baseUrl||"",duration:r.sourceDuration}]),{attributes:(t={NAME:r.id,BANDWIDTH:parseInt(r.bandwidth,10)},t["PROGRAM-ID"]=1,t),uri:"",endList:!0,timeline:r.periodIndex,resolvedUri:r.baseUrl||"",segments:n}}(t)],uri:""},e)},{})},n=function(e){var t,r=e.attributes,n=e.segments;return{attributes:(t={NAME:r.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:parseInt(r.width,10),height:parseInt(r.height,10)},CODECS:r.codecs,BANDWIDTH:parseInt(r.bandwidth,10)},t["PROGRAM-ID"]=1,t),uri:"",endList:!0,timeline:r.periodIndex,resolvedUri:"",segments:n}},i=function(e){return e.reduce(function(e,t){return e.concat(t)},[])},a=function(e){if(!e.length)return[];for(var t=[],r=0;r<e.length;r++)t.push(e[r]);return t},o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u=function(e){return!!e&&"object"===(void 0===e?"undefined":o(e))},s=function e(){for(var t=arguments.length,r=Array(t),n=0;n<t;n++)r[n]=arguments[n];return r.reduce(function(t,r){return Object.keys(r).forEach(function(n){Array.isArray(t[n])&&Array.isArray(r[n])?t[n]=t[n].concat(r[n]):u(t[n])&&u(r[n])?t[n]=e(t[n],r[n]):t[n]=r[n]}),t},{})},l=function(e){return e&&e.attributes?a(e.attributes).reduce(function(e,t){return e[t.name]=t.value,e},{}):{}},d="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},c=function(e,t){return t={exports:{}},e(t,t.exports),t.exports}(function(e,t){!function(t){var r=/^((?:[^\/;?#]+:)?)(\/\/[^\/\;?#]*)?(.*?)??(;.*?)?(\?.*?)?(#.*?)?$/,n=/^([^\/;?#]*)(.*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g,o={buildAbsoluteURL:function(e,t,r){if(r=r||{},e=e.trim(),!(t=t.trim())){if(!r.alwaysNormalize)return e;var i=this.parseURL(e);if(!u)throw new Error("Error trying to parse base URL.");return i.path=o.normalizePath(i.path),o.buildURLFromParts(i)}var a=this.parseURL(t);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=o.normalizePath(a.path),o.buildURLFromParts(a)):t;var u=this.parseURL(e);if(!u)throw new Error("Error trying to parse base URL.");if(!u.netLoc&&u.path&&"/"!==u.path[0]){var s=n.exec(u.path);u.netLoc=s[1],u.path=s[2]}u.netLoc&&!u.path&&(u.path="/");var l={scheme:u.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(l.netLoc=u.netLoc,"/"!==a.path[0]))if(a.path){var d=u.path,c=d.substring(0,d.lastIndexOf("/")+1)+a.path;l.path=o.normalizePath(c)}else l.path=u.path,a.params||(l.params=u.params,a.query||(l.query=u.query));return null===l.path&&(l.path=r.alwaysNormalize?o.normalizePath(a.path):a.path),o.buildURLFromParts(l)},parseURL:function(e){var t=r.exec(e);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(i,"");e.length!==(e=e.replace(a,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}};e.exports=o}()}),p="undefined"!=typeof window?window:void 0!==d?d:"undefined"!=typeof self?self:{},f=function(e,t){return/^[a-z]+:/i.test(t)?t:(/\/\//i.test(e)||(e=c.buildAbsoluteURL(p.location.href,e)),c.buildAbsoluteURL(e,t))},m=function(e){var t=e.baseUrl,r=void 0===t?"":t,n=e.source,i=void 0===n?"":n,a=e.range,o=void 0===a?"":a,u={uri:i,resolvedUri:f(r||"",i)};if(o){var s=o.split("-"),l=parseInt(s[0],10),d=parseInt(s[1],10);u.byterange={length:d-l,offset:l}}return u},v=function(e,t,r,n,i){for(var a=[],o=-1,u=0;u<n.length;u++){var s=n[u],l=parseInt(s.d,10),d=parseInt(s.r||0,10),c=parseInt(s.t||0,10);o<0&&(o=c),c&&c>o&&(o=c);var p=void 0;if(d<0){var f=u+1;p=f===n.length?(i*r-o)/l:(parseInt(n[f].t,10)-o)/l}else p=d+1;for(var m=e+a.length+p,v=e+a.length;v<m;)a.push({number:v,duration:l/r,time:o,timeline:t}),o+=l,v++}return a},h=function(e,t,r,n,i){var a=Math.ceil(i/(n/r));return function(e,t){for(var r=[],n=e;n<t;n++)r.push(n);return r}(e,e+a).map(function(o,u){var s={number:o,duration:n/r,timeline:t};return u===a-1&&(s.duration=i-s.duration*u),s.time=(s.number-e)*n,s})},b=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,g=function(e,t){return e.replace(b,function(e){return function(t,r,n,i){if("$$"===t)return"$";if(void 0===e[r])return t;var a=""+e[r];return"RepresentationID"===r?a:(i=n?parseInt(i,10):1,a.length>=i?a:""+new Array(i-a.length+1).join("0")+a)}}(t))},I=function(e,t){var r={RepresentationID:e.id,Bandwidth:parseInt(e.bandwidth||0,10)},n=e.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=m({baseUrl:e.baseUrl,source:g(i.sourceURL,r),range:i.range});return function(e,t){var r=parseInt(e.startNumber||1,10),n=parseInt(e.timescale||1,10);return e.duration||t?e.duration?h(r,e.periodIndex,n,parseInt(e.duration,10),e.sourceDuration):v(r,e.periodIndex,n,t,e.sourceDuration):[{number:r,duration:e.sourceDuration,time:0,timeline:e.periodIndex}]}(e,t).map(function(t){r.Number=t.number,r.Time=t.time;var n=g(e.media||"",r);return{uri:n,timeline:t.timeline,duration:t.duration,resolvedUri:f(e.baseUrl||"",n),map:a}})},U="INVALID_NUMBER_OF_PERIOD",y="DASH_EMPTY_MANIFEST",L="DASH_INVALID_XML",R="NO_BASE_URL",D="SEGMENT_TIME_UNSPECIFIED",w=function(e,t){var r=e.timescale,n=void 0===r?1:r,i=e.duration,a=e.segmentUrls,o=void 0===a?[]:a,u=e.periodIndex,s=void 0===u?0:u,l=e.startNumber,d=void 0===l?1:l;if(!i&&!t||i&&t)throw new Error(D);var c=parseInt(n,10),p=parseInt(d,10),f=o.map(function(t){return function(e,t){var r=e.baseUrl,n=e.initialization,i=void 0===n?{}:n,a=m({baseUrl:r,source:i.sourceURL,range:i.range}),o=m({baseUrl:r,source:t.media,range:t.mediaRange});return o.map=a,o}(e,t)}),b=void 0;if(i){var g=parseInt(i,10);b=h(p,s,c,g,e.sourceDuration)}t&&(b=v(p,s,c,t,e.sourceDuration));return b.map(function(e,t){if(f[t]){var r=f[t];return r.timeline=e.timeline,r.duration=e.duration,r}}).filter(function(e){return e})},E=function(e,t){return e.template?I(s(t,e.template),e.timeline):e.base?function(e){var t=e.baseUrl,r=e.initialization,n=void 0===r?{}:r,i=e.sourceDuration,a=e.timescale,o=void 0===a?1:a,u=e.startNumber,s=void 0===u?1:u,l=e.periodIndex,d=void 0===l?0:l,c=e.indexRange,p=void 0===c?"":c,f=e.duration;if(!t)throw new Error(R);var v=m({baseUrl:t,source:n.sourceURL,range:n.range}),b=m({baseUrl:t,source:t,range:p});b.map=v;var g=parseInt(o,10);if(f){var I=parseInt(f,10),U=parseInt(s,10),y=h(U,d,g,I,i);y.length>=1&&(b.duration=y[0].duration,b.timeline=y[0].timeline)}else i&&(b.duration=i/g,b.timeline=0);return[b]}(s(t,e.base)):e.list?w(s(t,e.list),e.timeline):void 0},S=function(e,t){return a(e.childNodes).filter(function(e){return e.tagName===t})},A=function(e,t){return t.length?i(e.map(function(e){return t.map(function(t){return f(e,function(e){return e.textContent.trim()}(t))})})):e},N=function(e){var t=S(e,"SegmentTemplate")[0],r=S(e,"SegmentList")[0],n=r&&S(r,"SegmentURL").map(function(e){return s({tag:"SegmentURL"},l(e))}),i=S(e,"SegmentBase")[0],a=r||t,o=a&&S(a,"SegmentTimeline")[0],u=r||i||t,d=u&&S(u,"Initialization")[0],c=t&&l(t);c&&d?c.initialization=d&&l(d):c&&c.initialization&&(c.initialization={sourceURL:c.initialization});var p={template:c,timeline:o&&S(o,"S").map(function(e){return l(e)}),list:r&&s(l(r),{segmentUrls:n,initialization:l(d)}),base:i&&s(l(i),{initialization:l(d)})};return Object.keys(p).forEach(function(e){p[e]||delete p[e]}),p},x=function(e,t,r){return function(n){var a=l(n),o=A(t,S(n,"BaseURL")),u=S(n,"Role")[0],d={role:l(u)},c=s(e,a,d),p=N(n),f=S(n,"Representation"),m=s(r,p);return i(f.map(function(e,t,r){return function(n){var i=S(n,"BaseURL"),a=A(t,i),o=s(e,l(n)),u=N(n);return a.map(function(e){return{segmentInfo:s(r,u),attributes:s(o,{baseUrl:e})}})}}(c,o,m)))}},T=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=S(e,"Period");if(1!==r.length)throw new Error(U);var n=l(e),a=A([t],S(e,"BaseURL"));return n.sourceDuration=n.mediaPresentationDuration?function(e){var t=/P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/.exec(e);if(!t)return 0;var r=t.slice(1),n=r[0],i=r[1],a=r[2],o=r[3],u=r[4],s=r[5];return 31536e3*parseFloat(n||0)+2592e3*parseFloat(i||0)+86400*parseFloat(a||0)+3600*parseFloat(o||0)+60*parseFloat(u||0)+parseFloat(s||0)}(n.mediaPresentationDuration):0,i(r.map(function(e,t){return function(r,n){var a=A(t,S(r,"BaseURL")),o=l(r),u=s(e,o,{periodIndex:n}),d=S(r,"AdaptationSet"),c=N(r);return i(d.map(x(u,a,c)))}}(n,a)))};e.VERSION="0.4.0",e.parse=function(e,i){return function(e){var i;if(!e.length)return{};var a=e[0].attributes.sourceDuration,o=e.filter(function(e){var t=e.attributes;return"video/mp4"===t.mimeType||"video"===t.contentType}).map(n),u=e.filter(function(e){var t=e.attributes;return"audio/mp4"===t.mimeType||"audio"===t.contentType}),s=e.filter(function(e){var t=e.attributes;return"text/vtt"===t.mimeType||"text"===t.contentType}),l={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(i={AUDIO:{},VIDEO:{}},i["CLOSED-CAPTIONS"]={},i.SUBTITLES={},i),uri:"",duration:a,playlists:o};return u.length&&(l.mediaGroups.AUDIO.audio=t(u)),s.length&&(l.mediaGroups.SUBTITLES.subs=r(s)),l}(function(e){return e.map(function(e){var t=e.attributes,r=e.segmentInfo;return{attributes:t,segments:E(r,t)}})}(T(function(e){if(""===e)throw new Error(y);var t=(new p.DOMParser).parseFromString(e,"application/xml"),r=t&&"MPD"===t.documentElement.tagName?t.documentElement:null;if(!r||r&&r.getElementsByTagName("parsererror").length>0)throw new Error(L);return r}(e),i)))}}); |
{ | ||
"name": "mpd-parser", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "mpd parser", | ||
@@ -52,2 +52,3 @@ "main": "dist/mpd-parser.cjs.js", | ||
"devDependencies": { | ||
"babel-eslint": "^8.2.1", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
@@ -54,0 +55,0 @@ "babel-plugin-transform-object-assign": "^6.8.0", |
import { flatten } from './utils/list'; | ||
import { shallowMerge, getAttributes } from './utils/object'; | ||
import { getAttributes, merge } from './utils/object'; | ||
import { parseDuration } from './utils/time'; | ||
@@ -55,3 +55,3 @@ import { findChildren, getContent } from './utils/xml'; | ||
const segmentUrls = segmentList && findChildren(segmentList, 'SegmentURL') | ||
.map(s => shallowMerge({ tag: 'SegmentURL' }, getAttributes(s))); | ||
.map(s => merge({ tag: 'SegmentURL' }, getAttributes(s))); | ||
const segmentBase = findChildren(adaptationSet, 'SegmentBase')[0]; | ||
@@ -82,7 +82,7 @@ const segmentTimelineParentNode = segmentList || segmentTemplate; | ||
return { | ||
const segmentInfo = { | ||
template, | ||
timeline: segmentTimeline && | ||
findChildren(segmentTimeline, 'S').map(s => getAttributes(s)), | ||
list: segmentList && shallowMerge( | ||
list: segmentList && merge( | ||
getAttributes(segmentList), | ||
@@ -93,3 +93,3 @@ { | ||
}), | ||
base: segmentBase && shallowMerge( | ||
base: segmentBase && merge( | ||
getAttributes(segmentBase), { | ||
@@ -99,2 +99,10 @@ initialization: getAttributes(segmentInitialization) | ||
}; | ||
Object.keys(segmentInfo).forEach(key => { | ||
if (!segmentInfo[key]) { | ||
delete segmentInfo[key]; | ||
} | ||
}); | ||
return segmentInfo; | ||
}; | ||
@@ -138,11 +146,12 @@ | ||
export const inheritBaseUrls = | ||
(adaptationSetAttributes, adaptationSetBaseUrls, segmentInfo) => (representation) => { | ||
(adaptationSetAttributes, adaptationSetBaseUrls, adaptationSetSegmentInfo) => (representation) => { | ||
const repBaseUrlElements = findChildren(representation, 'BaseURL'); | ||
const repBaseUrls = buildBaseUrls(adaptationSetBaseUrls, repBaseUrlElements); | ||
const attributes = shallowMerge(adaptationSetAttributes, getAttributes(representation)); | ||
const attributes = merge(adaptationSetAttributes, getAttributes(representation)); | ||
const representationSegmentInfo = getSegmentInformation(representation); | ||
return repBaseUrls.map(baseUrl => { | ||
return { | ||
segmentInfo, | ||
attributes: shallowMerge(attributes, { baseUrl }) | ||
segmentInfo: merge(adaptationSetSegmentInfo, representationSegmentInfo), | ||
attributes: merge(attributes, { baseUrl }) | ||
}; | ||
@@ -175,3 +184,3 @@ }); | ||
export const toRepresentations = | ||
(periodAttributes, periodBaseUrls) => (adaptationSet) => { | ||
(periodAttributes, periodBaseUrls, periodSegmentInfo) => (adaptationSet) => { | ||
const adaptationSetAttributes = getAttributes(adaptationSet); | ||
@@ -182,3 +191,3 @@ const adaptationSetBaseUrls = buildBaseUrls(periodBaseUrls, | ||
const roleAttributes = { role: getAttributes(role) }; | ||
const attrs = shallowMerge(periodAttributes, | ||
const attrs = merge(periodAttributes, | ||
adaptationSetAttributes, | ||
@@ -188,5 +197,6 @@ roleAttributes); | ||
const representations = findChildren(adaptationSet, 'Representation'); | ||
const adaptationSetSegmentInfo = merge(periodSegmentInfo, segmentInfo); | ||
return flatten( | ||
representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, segmentInfo))); | ||
representations.map(inheritBaseUrls(attrs, adaptationSetBaseUrls, adaptationSetSegmentInfo))); | ||
}; | ||
@@ -221,6 +231,8 @@ | ||
const periodBaseUrls = buildBaseUrls(mpdBaseUrls, findChildren(period, 'BaseURL')); | ||
const periodAttributes = shallowMerge({ periodIndex }, mpdAttributes); | ||
const periodAtt = getAttributes(period); | ||
const periodAttributes = merge(mpdAttributes, periodAtt, { periodIndex }); | ||
const adaptationSets = findChildren(period, 'AdaptationSet'); | ||
const periodSegmentInfo = getSegmentInformation(period); | ||
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls))); | ||
return flatten(adaptationSets.map(toRepresentations(periodAttributes, periodBaseUrls, periodSegmentInfo))); | ||
}; | ||
@@ -255,2 +267,1 @@ | ||
}; | ||
@@ -1,2 +0,2 @@ | ||
import { shallowMerge } from './utils/object'; | ||
import { merge } from './utils/object'; | ||
import { segmentsFromTemplate } from './segment/segmentTemplate'; | ||
@@ -9,14 +9,12 @@ import { segmentsFromList } from './segment/segmentList'; | ||
return segmentsFromTemplate( | ||
shallowMerge(segmentInfo.template, attributes), | ||
merge(attributes, segmentInfo.template), | ||
segmentInfo.timeline | ||
); | ||
} | ||
if (segmentInfo.base) { | ||
return segmentsFromBase(shallowMerge(segmentInfo.base, attributes)); | ||
return segmentsFromBase(merge(attributes, segmentInfo.base)); | ||
} | ||
if (segmentInfo.list) { | ||
return segmentsFromList( | ||
shallowMerge(segmentInfo.list, attributes), segmentInfo.timeline | ||
merge(attributes, segmentInfo.list), segmentInfo.timeline | ||
); | ||
@@ -26,3 +24,3 @@ } | ||
export const toPlaylists = representations => { | ||
export const toPlaylists = (representations) => { | ||
return representations.map(({ attributes, segmentInfo }) => { | ||
@@ -29,0 +27,0 @@ const segments = generateSegments(segmentInfo, attributes); |
import { from } from './list'; | ||
export const shallowMerge = (...objects) => { | ||
return objects.reduce((x, y) => { | ||
return Object.keys(y) | ||
.reduce((o, key) => { | ||
o[key] = y[key]; | ||
const isObject = (obj) => { | ||
return !!obj && typeof obj === 'object'; | ||
}; | ||
return o; | ||
}, x); | ||
export const merge = (...objects) => { | ||
return objects.reduce((result, source) => { | ||
Object.keys(source).forEach(key => { | ||
if (Array.isArray(result[key]) && Array.isArray(source[key])) { | ||
result[key] = result[key].concat(source[key]); | ||
} else if (isObject(result[key]) && isObject(source[key])) { | ||
result[key] = merge(result[key], source[key]); | ||
} else { | ||
result[key] = source[key]; | ||
} | ||
}); | ||
return result; | ||
}, {}); | ||
@@ -12,0 +23,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
177609
4070
1
33