/*! @name mpd-parser @version 0.15.4 @license Apache-2.0 */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("global/window"),require("xmldom")):"function"==typeof define&&define.amd?define(["exports","global/window","xmldom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).mpdParser={},e.window,e.window)}(this,(function(e,t,r){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=n(t),a=function(e){return!!e&&"object"==typeof e},u=function e(){for(var t=arguments.length,r=new Array(t),n=0;n=0&&(f.minimumUpdatePeriod=1e3*c),t&&(f.locations=t),"dynamic"===o&&(f.suggestedPresentationDelay=s),l.length&&(f.mediaGroups.AUDIO.audio=function(e,t){var r;void 0===t&&(t={});var n=e.reduce((function(e,n){var i=n.attributes.role&&n.attributes.role.value||"",a=n.attributes.lang||"",u="main";if(a){var o=i?" ("+i+")":"";u=""+n.attributes.lang+o}return e[u]&&e[u].playlists[0].attributes.BANDWIDTH>n.attributes.bandwidth||(e[u]={language:a,autoselect:!0,default:"main"===i,playlists:w([L(n)],t),uri:""},void 0===r&&"main"===i&&((r=n).default=!0)),e}),{});return r||(n[Object.keys(n)[0]].default=!0),n}(l,r)),m.length&&(f.mediaGroups.SUBTITLES.subs=function(e,t){return void 0===t&&(t={}),e.reduce((function(e,r){var n=r.attributes.lang||"text";return e[n]||(e[n]={language:n,default:!1,autoselect:!1,playlists:w([E(r)],t),uri:""}),e}),{})}(m,r)),f},R=function(e,t,r){var n=e.NOW,i=e.clientOffset,a=e.availabilityStartTime,u=e.timescale,o=void 0===u?1:u,s=e.start,c=void 0===s?0:s,d=e.minimumUpdatePeriod,l=(n+i)/1e3+(void 0===d?0:d)-(a+c);return Math.ceil((l*o-t)/r)},S=function(e,t){for(var r=e.type,n=void 0===r?"static":r,i=e.minimumUpdatePeriod,a=void 0===i?0:i,u=e.media,o=void 0===u?"":u,s=e.sourceDuration,c=e.timescale,d=void 0===c?1:c,l=e.startNumber,m=void 0===l?1:l,f=e.periodIndex,p=[],h=-1,v=0;vh&&(h=U);var I=void 0;if(y<0){var D=v+1;I=D===t.length?"dynamic"===n&&a>0&&o.indexOf("$Number$")>0?R(e,h,b):(s*d-h)/b:(t[D].t-h)/b}else I=y+1;for(var x=m+p.length+I,w=m+p.length;w=i?a:""+new Array(i-a.length+1).join("0")+a)}}(t))},O=function(e,t){var r={RepresentationID:e.id,Bandwidth:e.bandwidth||0},n=e.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=g({baseUrl:e.baseUrl,source:A(i.sourceURL,r),range:i.range});return function(e,t){return e.duration||t?e.duration?U(e):S(e,t):[{number:e.startNumber||1,duration:e.sourceDuration,time:0,timeline:e.periodIndex}]}(e,t).map((function(t){r.Number=t.number,r.Time=t.time;var n=A(e.media||"",r);return{uri:n,timeline:t.timeline,duration:t.duration,resolvedUri:v(e.baseUrl||"",n),map:a,number:t.number}}))},M=function(e,t){var r=e.duration,n=e.segmentUrls,i=void 0===n?[]:n;if(!r&&!t||r&&t)throw new Error(f);var a,u=i.map((function(t){return function(e,t){var r=e.baseUrl,n=e.initialization,i=void 0===n?{}:n,a=g({baseUrl:r,source:i.sourceURL,range:i.range}),u=g({baseUrl:r,source:t.media,range:t.mediaRange});return u.map=a,u}(e,t)}));return r&&(a=U(e)),t&&(a=S(e,t)),a.map((function(e,t){if(u[t]){var r=u[t];return r.timeline=e.timeline,r.duration=e.duration,r.number=e.number,r}})).filter((function(e){return e}))},z=function(e){var t,r,n=e.attributes,i=e.segmentInfo;i.template?(r=O,t=u(n,i.template)):i.base?(r=I,t=u(n,i.base)):i.list&&(r=M,t=u(n,i.list));var a={attributes:n};if(!r)return a;var o=r(t,i.timeline);if(t.duration){var s=t,c=s.duration,d=s.timescale,l=void 0===d?1:d;t.duration=c/l}else o.length?t.duration=o.reduce((function(e,t){return Math.max(e,Math.ceil(t.duration))}),0):t.duration=0;return a.attributes=t,a.segments=o,i.base&&t.indexRange&&(a.sidx=o[0],a.segments=[]),a},B=function(e){return e.map(z)},C=function(e,t){return s(e.childNodes).filter((function(e){return e.tagName===t}))},F=function(e){return e.textContent.trim()},_=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],u=r[3],o=r[4],s=r[5];return 31536e3*parseFloat(n||0)+2592e3*parseFloat(i||0)+86400*parseFloat(a||0)+3600*parseFloat(u||0)+60*parseFloat(o||0)+parseFloat(s||0)},j={mediaPresentationDuration:function(e){return _(e)},availabilityStartTime:function(e){return/^\d+-\d+-\d+T\d+:\d+:\d+(\.\d+)?$/.test(t=e)&&(t+="Z"),Date.parse(t)/1e3;var t},minimumUpdatePeriod:function(e){return _(e)},suggestedPresentationDelay:function(e){return _(e)},type:function(e){return e},timeShiftBufferDepth:function(e){return _(e)},start:function(e){return _(e)},width:function(e){return parseInt(e,10)},height:function(e){return parseInt(e,10)},bandwidth:function(e){return parseInt(e,10)},startNumber:function(e){return parseInt(e,10)},timescale:function(e){return parseInt(e,10)},duration:function(e){var t=parseInt(e,10);return isNaN(t)?_(e):t},d:function(e){return parseInt(e,10)},t:function(e){return parseInt(e,10)},r:function(e){return parseInt(e,10)},DEFAULT:function(e){return e}},q=function(e){return e&&e.attributes?s(e.attributes).reduce((function(e,t){var r=j[t.name]||j.DEFAULT;return e[t.name]=r(t.value),e}),{}):{}};function k(e){for(var t,r=(t=e,i.default.atob?i.default.atob(t):Buffer.from(t,"base64").toString("binary")),n=new Uint8Array(r.length),a=0;a0)throw new Error(l);return n},Z=D;e.VERSION="0.15.4",e.addSidxSegmentsToPlaylist=Z,e.inheritAttributes=X,e.parse=function(e,t){void 0===t&&(t={});var r=X(Y(e),t),n=B(r.representationInfo);return P(n,r.locations,t.sidxMapping)},e.parseUTCTiming=function(e){return function(e){var t=C(e,"UTCTiming")[0];if(!t)return null;var r=q(t);switch(r.schemeIdUri){case"urn:mpeg:dash:utc:http-head:2014":case"urn:mpeg:dash:utc:http-head:2012":r.method="HEAD";break;case"urn:mpeg:dash:utc:http-xsdate:2014":case"urn:mpeg:dash:utc:http-iso:2014":case"urn:mpeg:dash:utc:http-xsdate:2012":case"urn:mpeg:dash:utc:http-iso:2012":r.method="GET";break;case"urn:mpeg:dash:utc:direct:2014":case"urn:mpeg:dash:utc:direct:2012":r.method="DIRECT",r.value=Date.parse(r.value);break;case"urn:mpeg:dash:utc:http-ntp:2014":case"urn:mpeg:dash:utc:ntp:2014":case"urn:mpeg:dash:utc:sntp:2014":default:throw new Error(p)}return r}(Y(e))},e.stringToMpdXml=Y,e.toM3u8=P,e.toPlaylists=B,Object.defineProperty(e,"__esModule",{value:!0})}));