Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mpd-parser

Package Overview
Dependencies
Maintainers
15
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mpd-parser - npm Package Compare versions

Comparing version 0.16.0 to 0.17.0

test/manifests/608-captions.js

11

CHANGELOG.md

@@ -0,1 +1,12 @@

<a name="0.17.0"></a>
# [0.17.0](https://github.com/videojs/mpd-parser/compare/v0.16.0...v0.17.0) (2021-05-28)
### Features
* caption services metadata support ([#131](https://github.com/videojs/mpd-parser/issues/131)) ([75ecbc2](https://github.com/videojs/mpd-parser/commit/75ecbc2))
### Chores
* **package:** update to vhs-utils[@3](https://github.com/3).0.2 ([#134](https://github.com/videojs/mpd-parser/issues/134)) ([744142d](https://github.com/videojs/mpd-parser/commit/744142d))
<a name="0.16.0"></a>

@@ -2,0 +13,0 @@ # [0.16.0](https://github.com/videojs/mpd-parser/compare/v0.15.4...v0.16.0) (2021-03-26)

4

dist/mpd-parser.min.js

@@ -1,2 +0,2 @@

/*! @name mpd-parser @version 0.16.0 @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},o=function e(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return r.reduce((function(t,r){return"object"!=typeof r||Object.keys(r).forEach((function(n){Array.isArray(t[n])&&Array.isArray(r[n])?t[n]=t[n].concat(r[n]):a(t[n])&&a(r[n])?t[n]=e(t[n],r[n]):t[n]=r[n]})),t}),{})},u=function(e){return e.reduce((function(e,t){return e.concat(t)}),[])},s=function(e){if(!e.length)return[];for(var t=[],r=0;r<e.length;r++)t.push(e[r]);return t},c="INVALID_NUMBER_OF_PERIOD",d="DASH_EMPTY_MANIFEST",l="DASH_INVALID_XML",m="NO_BASE_URL",f="SEGMENT_TIME_UNSPECIFIED",p="UNSUPPORTED_UTC_TIMING_SCHEME";var h=function(e,t,r){return e(r={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&r.path)}},r.exports),r.exports}((function(e,t){var r,n,i,a,o;r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#.*)?$/,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=o.parseURL(e);if(!i)throw new Error("Error trying to parse base URL.");return i.path=o.normalizePath(i.path),o.buildURLFromParts(i)}var a=o.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=o.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 c={scheme:u.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(c.netLoc=u.netLoc,"/"!==a.path[0]))if(a.path){var d=u.path,l=d.substring(0,d.lastIndexOf("/")+1)+a.path;c.path=o.normalizePath(l)}else c.path=u.path,a.params||(c.params=u.params,a.query||(c.query=u.query));return null===c.path&&(c.path=r.alwaysNormalize?o.normalizePath(a.path):a.path),o.buildURLFromParts(c)},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})),v=function(e,t){return/^[a-z]+:/i.test(t)?t:(/\/\//i.test(e)||(e=h.buildAbsoluteURL(i.default.location&&i.default.location.href||"",e)),h.buildAbsoluteURL(e,t))},b=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=e.indexRange,s=void 0===u?"":u,c={uri:i,resolvedUri:v(r||"",i)};if(o||s){var d=(o||s).split("-"),l=parseInt(d[0],10),m=parseInt(d[1],10);c.byterange={length:m-l+1,offset:l}}return c},g=function(e){return e&&"number"!=typeof e&&(e=parseInt(e,10)),isNaN(e)?null:e},y={static:function(e){var t=e.duration,r=e.timescale,n=void 0===r?1:r,i=e.sourceDuration,a=g(e.endNumber);return{start:0,end:"number"==typeof a?a:Math.ceil(i/(t/n))}},dynamic:function(e){var t=e.NOW,r=e.clientOffset,n=e.availabilityStartTime,i=e.timescale,a=void 0===i?1:i,o=e.duration,u=e.start,s=void 0===u?0:u,c=e.minimumUpdatePeriod,d=void 0===c?0:c,l=e.timeShiftBufferDepth,m=void 0===l?1/0:l,f=g(e.endNumber),p=(t+r)/1e3,h=n+s,v=p+d-h,b=Math.ceil(v*a/o),y=Math.floor((p-h-m)*a/o),U=Math.floor((p-h)*a/o);return{start:Math.max(0,y),end:"number"==typeof f?f:Math.min(b,U)}}},U=function(e){var t=e.type,r=void 0===t?"static":t,n=e.duration,i=e.timescale,a=void 0===i?1:i,o=e.sourceDuration,u=y[r](e),s=function(e,t){for(var r=[],n=e;n<t;n++)r.push(n);return r}(u.start,u.end).map(function(e){return function(t,r){var n=e.duration,i=e.timescale,a=void 0===i?1:i,o=e.periodIndex,u=e.startNumber;return{number:(void 0===u?1:u)+t,duration:n/a,timeline:o,time:r*n}}}(e));if("static"===r){var c=s.length-1;s[c].duration=o-n/a*c}return s},I=function(e){var t=e.baseUrl,r=e.initialization,n=void 0===r?{}:r,i=e.sourceDuration,a=e.indexRange,o=void 0===a?"":a,u=e.duration;if(!t)throw new Error(m);var s=b({baseUrl:t,source:n.sourceURL,range:n.range}),c=b({baseUrl:t,source:t,indexRange:o});if(c.map=s,u){var d=U(e);d.length&&(c.duration=d[0].duration,c.timeline=d[0].timeline)}else i&&(c.duration=i,c.timeline=0);return c.number=0,[c]},D=function(e,t,r){for(var n=e.sidx.map?e.sidx.map:null,i=e.sidx.duration,a=e.timeline||0,o=e.sidx.byterange,u=o.offset+o.length,s=t.timescale,c=t.references.filter((function(e){return 1!==e.referenceType})),d=[],l=u+t.firstOffset,m=0;m<c.length;m++){var f=t.references[m],p=f.referencedSize,h=f.subsegmentDuration,v=I({baseUrl:r,timescale:s,timeline:a,periodIndex:a,duration:h,sourceDuration:i,indexRange:l+"-"+(l+p-1)})[0];n&&(v.map=n),d.push(v),l+=p}return e.segments=d,e},T=function(e){return e&&e.uri+"-"+(t=e.byterange,r=t.offset+t.length-1,t.offset+"-"+r);var t,r},L=function(e){var t;return(t=e.reduce((function(e,t){var r,n=t.attributes.id+(t.attributes.lang||"");return e[n]?(t.segments[0]&&(t.segments[0].discontinuity=!0),(r=e[n].segments).push.apply(r,t.segments),t.attributes.contentProtection&&(e[n].attributes.contentProtection=t.attributes.contentProtection)):e[n]=t,e}),{}),Object.keys(t).map((function(e){return t[e]}))).map((function(e){var t,r;return e.discontinuityStarts=(t=e.segments,r="discontinuity",t.reduce((function(e,t,n){return t[r]&&e.push(n),e}),[])),e}))},x=function(e,t){var r=T(e.sidx),n=r&&t[r]&&t[r].sidx;return n&&D(e,n,e.sidx.resolvedUri),e},w=function(e,t){if(void 0===t&&(t={}),!Object.keys(t).length)return e;for(var r in e)e[r]=x(e[r],t);return e},E=function(e){var t,r=e.attributes,n=e.segments,i=e.sidx,a={attributes:(t={NAME:r.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:r.width,height:r.height},CODECS:r.codecs,BANDWIDTH:r.bandwidth},t["PROGRAM-ID"]=1,t),uri:"",endList:"static"===(r.type||"static"),timeline:r.periodIndex,resolvedUri:"",targetDuration:r.duration,segments:n,mediaSequence:n.length?n[0].number:1};return r.contentProtection&&(a.contentProtection=r.contentProtection),i&&(a.sidx=i),a},P=function(e){var t=e.attributes;return"video/mp4"===t.mimeType||"video/webm"===t.mimeType||"video"===t.contentType},R=function(e){var t=e.attributes;return"audio/mp4"===t.mimeType||"audio/webm"===t.mimeType||"audio"===t.contentType},S=function(e){var t=e.attributes;return"text/vtt"===t.mimeType||"text"===t.contentType},O=function(e,t,r){var n;if(void 0===r&&(r={}),!e.length)return{};var i=e[0].attributes,a=i.sourceDuration,o=i.type,u=void 0===o?"static":o,s=i.suggestedPresentationDelay,c=i.minimumUpdatePeriod,d=L(e.filter(P)).map(E),l=L(e.filter(R)),m=e.filter(S),f={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(n={AUDIO:{},VIDEO:{}},n["CLOSED-CAPTIONS"]={},n.SUBTITLES={},n),uri:"",duration:a,playlists:w(d,r)};c>=0&&(f.minimumUpdatePeriod=1e3*c),t&&(f.locations=t),"dynamic"===u&&(f.suggestedPresentationDelay=s);var p=0===f.playlists.length;return l.length&&(f.mediaGroups.AUDIO.audio=function(e,t,r){var n;void 0===t&&(t={}),void 0===r&&(r=!1);var i=e.reduce((function(e,i){var a=i.attributes.role&&i.attributes.role.value||"",o=i.attributes.lang||"",u=i.attributes.label||"main";if(o&&!i.attributes.label){var s=a?" ("+a+")":"";u=""+i.attributes.lang+s}e[u]||(e[u]={language:o,autoselect:!0,default:"main"===a,playlists:[],uri:""});var c=x(function(e,t){var r,n=e.attributes,i=e.segments,a=e.sidx,o={attributes:(r={NAME:n.id,BANDWIDTH:n.bandwidth,CODECS:n.codecs},r["PROGRAM-ID"]=1,r),uri:"",endList:"static"===(n.type||"static"),timeline:n.periodIndex,resolvedUri:"",targetDuration:n.duration,segments:i,mediaSequence:i.length?i[0].number:1};return n.contentProtection&&(o.contentProtection=n.contentProtection),a&&(o.sidx=a),t&&(o.attributes.AUDIO="audio",o.attributes.SUBTITLES="subs"),o}(i,r),t);return e[u].playlists.push(c),void 0===n&&"main"===a&&((n=i).default=!0),e}),{});return n||(i[Object.keys(i)[0]].default=!0),i}(l,r,p)),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:[],uri:""}),e[n].playlists.push(x(function(e){var t,r=e.attributes,n=e.segments;void 0===n&&(n=[{uri:r.baseUrl,timeline:r.periodIndex,resolvedUri:r.baseUrl||"",duration:r.sourceDuration,number:0}],r.duration=r.sourceDuration);var i=((t={NAME:r.id,BANDWIDTH:r.bandwidth})["PROGRAM-ID"]=1,t);return r.codecs&&(i.CODECS=r.codecs),{attributes:i,uri:"",endList:"static"===(r.type||"static"),timeline:r.periodIndex,resolvedUri:r.baseUrl||"",targetDuration:r.duration,segments:n,mediaSequence:n.length?n[0].number:1}}(r),t)),e}),{})}(m,r)),f},N=function(e,t,r){var n=e.NOW,i=e.clientOffset,a=e.availabilityStartTime,o=e.timescale,u=void 0===o?1:o,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*u-t)/r)},A=function(e,t){for(var r=e.type,n=void 0===r?"static":r,i=e.minimumUpdatePeriod,a=void 0===i?0:i,o=e.media,u=void 0===o?"":o,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;v<t.length;v++){var b=t[v],g=b.d,y=b.r||0,U=b.t||0;h<0&&(h=U),U&&U>h&&(h=U);var I=void 0;if(y<0){var D=v+1;I=D===t.length?"dynamic"===n&&a>0&&u.indexOf("$Number$")>0?N(e,h,g):(s*d-h)/g:(t[D].t-h)/g}else I=y+1;for(var T=m+p.length+I,L=m+p.length;L<T;)p.push({number:L,duration:g/d,time:h,timeline:f}),h+=g,L++}return p},M=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,z=function(e,t){return e.replace(M,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))},B=function(e,t){var r={RepresentationID:e.id,Bandwidth:e.bandwidth||0},n=e.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=b({baseUrl:e.baseUrl,source:z(i.sourceURL,r),range:i.range});return function(e,t){return e.duration||t?e.duration?U(e):A(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=z(e.media||"",r),i={uri:n,timeline:t.timeline,duration:t.duration,resolvedUri:v(e.baseUrl||"",n),map:a,number:t.number};return e.presentationTimeOffset&&(i.presentationTimeOffset=e.presentationTimeOffset),i}))},C=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,o=i.map((function(t){return function(e,t){var r=e.baseUrl,n=e.initialization,i=void 0===n?{}:n,a=b({baseUrl:r,source:i.sourceURL,range:i.range}),o=b({baseUrl:r,source:t.media,range:t.mediaRange});return o.map=a,o}(e,t)}));return r&&(a=U(e)),t&&(a=A(e,t)),a.map((function(e,t){if(o[t]){var r=o[t];return r.timeline=e.timeline,r.duration=e.duration,r.number=e.number,r}})).filter((function(e){return e}))},F=function(e){var t,r,n=e.attributes,i=e.segmentInfo;i.template?(r=B,t=o(n,i.template),i.template.presentationTimeOffset&&(t.presentationTimeOffset=i.template.presentationTimeOffset/i.template.timescale)):i.base?(r=I,t=o(n,i.base)):i.list&&(r=C,t=o(n,i.list));var a={attributes:n};if(!r)return a;var u=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 u.length?t.duration=u.reduce((function(e,t){return Math.max(e,Math.ceil(t.duration))}),0):t.duration=0;return a.attributes=t,a.segments=u,i.base&&t.indexRange&&(a.sidx=u[0],a.segments=[]),a},_=function(e){return e.map(F)},j=function(e,t){return s(e.childNodes).filter((function(e){return e.tagName===t}))},q=function(e){return e.textContent.trim()},k=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)},$={mediaPresentationDuration:function(e){return k(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 k(e)},suggestedPresentationDelay:function(e){return k(e)},type:function(e){return e},timeShiftBufferDepth:function(e){return k(e)},start:function(e){return k(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)},presentationTimeOffset:function(e){return parseInt(e,10)},duration:function(e){var t=parseInt(e,10);return isNaN(t)?k(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}},G=function(e){return e&&e.attributes?s(e.attributes).reduce((function(e,t){var r=$[t.name]||$.DEFAULT;return e[t.name]=r(t.value),e}),{}):{}};function H(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;a<r.length;a++)n[a]=r.charCodeAt(a);return n}var W={"urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b":"org.w3.clearkey","urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":"com.widevine.alpha","urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":"com.microsoft.playready","urn:uuid:f239e769-efa3-4850-9c16-a903c6932efb":"com.adobe.primetime"},V=function(e,t){return t.length?u(e.map((function(e){return t.map((function(t){return v(e,q(t))}))}))):e},X=function(e){var t=j(e,"SegmentTemplate")[0],r=j(e,"SegmentList")[0],n=r&&j(r,"SegmentURL").map((function(e){return o({tag:"SegmentURL"},G(e))})),i=j(e,"SegmentBase")[0],a=r||t,u=a&&j(a,"SegmentTimeline")[0],s=r||i||t,c=s&&j(s,"Initialization")[0],d=t&&G(t);d&&c?d.initialization=c&&G(c):d&&d.initialization&&(d.initialization={sourceURL:d.initialization});var l={template:d,timeline:u&&j(u,"S").map((function(e){return G(e)})),list:r&&o(G(r),{segmentUrls:n,initialization:G(c)}),base:i&&o(G(i),{initialization:G(c)})};return Object.keys(l).forEach((function(e){l[e]||delete l[e]})),l},Y=function(e,t,r){return function(n){var i=G(n),a=V(t,j(n,"BaseURL")),s=j(n,"Role")[0],c={role:G(s)},d=o(e,i,c),l=j(n,"Label")[0];if(l&&l.childNodes.length){var m=l.childNodes[0].nodeValue.trim();d=o(d,{label:m})}var f=j(n,"ContentProtection").reduce((function(e,t){var r=G(t),n=W[r.schemeIdUri];if(n){e[n]={attributes:r};var i=j(t,"cenc:pssh")[0];if(i){var a=q(i),o=a&&H(a);e[n].pssh=o}}return e}),{});Object.keys(f).length&&(d=o(d,{contentProtection:f}));var p=X(n),h=j(n,"Representation"),v=o(r,p);return u(h.map(function(e,t,r){return function(n){var i=j(n,"BaseURL"),a=V(t,i),u=o(e,G(n)),s=X(n);return a.map((function(e){return{segmentInfo:o(r,s),attributes:o(u,{baseUrl:e})}}))}}(d,a,v)))}},Z=function(e,t){return function(r,n){var a=V(t,j(r,"BaseURL")),s=G(r),c=parseInt(s.id,10),d=i.default.isNaN(c)?n:c,l=o(e,{periodIndex:d}),m=j(r,"AdaptationSet"),f=X(r);return u(m.map(Y(l,a,f)))}},K=function(e,t){void 0===t&&(t={});var r=t,n=r.manifestUri,i=void 0===n?"":n,a=r.NOW,o=void 0===a?Date.now():a,s=r.clientOffset,d=void 0===s?0:s,l=j(e,"Period");if(!l.length)throw new Error(c);var m=j(e,"Location"),f=G(e),p=V([i],j(e,"BaseURL"));return f.sourceDuration=f.mediaPresentationDuration||0,f.NOW=o,f.clientOffset=d,m.length&&(f.locations=m.map(q)),{locations:f.locations,representationInfo:u(l.map(Z(f,p)))}},J=function(e){if(""===e)throw new Error(d);var t,n,i=new r.DOMParser;try{n=(t=i.parseFromString(e,"application/xml"))&&"MPD"===t.documentElement.tagName?t.documentElement:null}catch(e){}if(!n||n&&n.getElementsByTagName("parsererror").length>0)throw new Error(l);return n};e.VERSION="0.16.0",e.addSidxSegmentsToPlaylist=D,e.generateSidxKey=T,e.inheritAttributes=K,e.parse=function(e,t){void 0===t&&(t={});var r=K(J(e),t),n=_(r.representationInfo);return O(n,r.locations,t.sidxMapping)},e.parseUTCTiming=function(e){return function(e){var t=j(e,"UTCTiming")[0];if(!t)return null;var r=G(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}(J(e))},e.stringToMpdXml=J,e.toM3u8=O,e.toPlaylists=_,Object.defineProperty(e,"__esModule",{value:!0})}));
/*! @name mpd-parser @version 0.17.0 @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},o=function e(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return r.reduce((function(t,r){return"object"!=typeof r||Object.keys(r).forEach((function(n){Array.isArray(t[n])&&Array.isArray(r[n])?t[n]=t[n].concat(r[n]):a(t[n])&&a(r[n])?t[n]=e(t[n],r[n]):t[n]=r[n]})),t}),{})},u=function(e){return e.reduce((function(e,t){return e.concat(t)}),[])},s=function(e){if(!e.length)return[];for(var t=[],r=0;r<e.length;r++)t.push(e[r]);return t},c="INVALID_NUMBER_OF_PERIOD",d="DASH_EMPTY_MANIFEST",l="DASH_INVALID_XML",f="NO_BASE_URL",m="SEGMENT_TIME_UNSPECIFIED",p="UNSUPPORTED_UTC_TIMING_SCHEME";var h=function(e,t,r){return e(r={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&r.path)}},r.exports),r.exports}((function(e,t){var r,n,i,a,o;r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#[^]*)?$/,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=o.parseURL(e);if(!i)throw new Error("Error trying to parse base URL.");return i.path=o.normalizePath(i.path),o.buildURLFromParts(i)}var a=o.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=o.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 c={scheme:u.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(c.netLoc=u.netLoc,"/"!==a.path[0]))if(a.path){var d=u.path,l=d.substring(0,d.lastIndexOf("/")+1)+a.path;c.path=o.normalizePath(l)}else c.path=u.path,a.params||(c.params=u.params,a.query||(c.query=u.query));return null===c.path&&(c.path=r.alwaysNormalize?o.normalizePath(a.path):a.path),o.buildURLFromParts(c)},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})),v="http://example.com",g=function(e,t){if(/^[a-z]+:/i.test(t))return t;/^data:/.test(e)&&(e=i.default.location&&i.default.location.href||"");var r="function"==typeof i.default.URL,n=/^\/\//.test(e),a=!i.default.location&&!/\/\//i.test(e);if(r?e=new i.default.URL(e,i.default.location||v):/\/\//i.test(e)||(e=h.buildAbsoluteURL(i.default.location&&i.default.location.href||"",e)),r){var o=new URL(t,e);return a?o.href.slice(v.length):n?o.href.slice(o.protocol.length):o.href}return h.buildAbsoluteURL(e,t)},b=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=e.indexRange,s=void 0===u?"":u,c={uri:i,resolvedUri:g(r||"",i)};if(o||s){var d=(o||s).split("-"),l=parseInt(d[0],10),f=parseInt(d[1],10);c.byterange={length:f-l+1,offset:l}}return c},y=function(e){return e&&"number"!=typeof e&&(e=parseInt(e,10)),isNaN(e)?null:e},U={static:function(e){var t=e.duration,r=e.timescale,n=void 0===r?1:r,i=e.sourceDuration,a=y(e.endNumber);return{start:0,end:"number"==typeof a?a:Math.ceil(i/(t/n))}},dynamic:function(e){var t=e.NOW,r=e.clientOffset,n=e.availabilityStartTime,i=e.timescale,a=void 0===i?1:i,o=e.duration,u=e.start,s=void 0===u?0:u,c=e.minimumUpdatePeriod,d=void 0===c?0:c,l=e.timeShiftBufferDepth,f=void 0===l?1/0:l,m=y(e.endNumber),p=(t+r)/1e3,h=n+s,v=p+d-h,g=Math.ceil(v*a/o),b=Math.floor((p-h-f)*a/o),U=Math.floor((p-h)*a/o);return{start:Math.max(0,b),end:"number"==typeof m?m:Math.min(g,U)}}},I=function(e){var t=e.type,r=void 0===t?"static":t,n=e.duration,i=e.timescale,a=void 0===i?1:i,o=e.sourceDuration,u=U[r](e),s=function(e,t){for(var r=[],n=e;n<t;n++)r.push(n);return r}(u.start,u.end).map(function(e){return function(t,r){var n=e.duration,i=e.timescale,a=void 0===i?1:i,o=e.periodIndex,u=e.startNumber;return{number:(void 0===u?1:u)+t,duration:n/a,timeline:o,time:r*n}}}(e));if("static"===r){var c=s.length-1;s[c].duration=o-n/a*c}return s},D=function(e){var t=e.baseUrl,r=e.initialization,n=void 0===r?{}:r,i=e.sourceDuration,a=e.indexRange,o=void 0===a?"":a,u=e.duration;if(!t)throw new Error(f);var s=b({baseUrl:t,source:n.sourceURL,range:n.range}),c=b({baseUrl:t,source:t,indexRange:o});if(c.map=s,u){var d=I(e);d.length&&(c.duration=d[0].duration,c.timeline=d[0].timeline)}else i&&(c.duration=i,c.timeline=0);return c.number=0,[c]},R=function(e,t,r){for(var n=e.sidx.map?e.sidx.map:null,i=e.sidx.duration,a=e.timeline||0,o=e.sidx.byterange,u=o.offset+o.length,s=t.timescale,c=t.references.filter((function(e){return 1!==e.referenceType})),d=[],l=u+t.firstOffset,f=0;f<c.length;f++){var m=t.references[f],p=m.referencedSize,h=m.subsegmentDuration,v=D({baseUrl:r,timescale:s,timeline:a,periodIndex:a,duration:h,sourceDuration:i,indexRange:l+"-"+(l+p-1)})[0];n&&(v.map=n),d.push(v),l+=p}return e.segments=d,e},L=function(e){return e&&e.uri+"-"+(t=e.byterange,r=t.offset+t.length-1,t.offset+"-"+r);var t,r},T=function(e){var t;return(t=e.reduce((function(e,t){var r,n=t.attributes.id+(t.attributes.lang||"");return e[n]?(t.segments[0]&&(t.segments[0].discontinuity=!0),(r=e[n].segments).push.apply(r,t.segments),t.attributes.contentProtection&&(e[n].attributes.contentProtection=t.attributes.contentProtection)):e[n]=t,e}),{}),Object.keys(t).map((function(e){return t[e]}))).map((function(e){var t,r;return e.discontinuityStarts=(t=e.segments,r="discontinuity",t.reduce((function(e,t,n){return t[r]&&e.push(n),e}),[])),e}))},w=function(e,t){var r=L(e.sidx),n=r&&t[r]&&t[r].sidx;return n&&R(e,n,e.sidx.resolvedUri),e},E=function(e,t){if(void 0===t&&(t={}),!Object.keys(t).length)return e;for(var r in e)e[r]=w(e[r],t);return e},x=function(e){var t,r=e.attributes,n=e.segments,i=e.sidx,a={attributes:(t={NAME:r.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:r.width,height:r.height},CODECS:r.codecs,BANDWIDTH:r.bandwidth},t["PROGRAM-ID"]=1,t),uri:"",endList:"static"===(r.type||"static"),timeline:r.periodIndex,resolvedUri:"",targetDuration:r.duration,segments:n,mediaSequence:n.length?n[0].number:1};return r.contentProtection&&(a.contentProtection=r.contentProtection),i&&(a.sidx=i),a},S=function(e){var t=e.attributes;return"video/mp4"===t.mimeType||"video/webm"===t.mimeType||"video"===t.contentType},P=function(e){var t=e.attributes;return"audio/mp4"===t.mimeType||"audio/webm"===t.mimeType||"audio"===t.contentType},O=function(e){var t=e.attributes;return"text/vtt"===t.mimeType||"text"===t.contentType},N=function(e,t,r){var n;if(void 0===r&&(r={}),!e.length)return{};var i=e[0].attributes,a=i.sourceDuration,o=i.type,u=void 0===o?"static":o,s=i.suggestedPresentationDelay,c=i.minimumUpdatePeriod,d=T(e.filter(S)).map(x),l=T(e.filter(P)),f=e.filter(O),m=e.map((function(e){return e.attributes.captionServices})).filter(Boolean),p={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(n={AUDIO:{},VIDEO:{}},n["CLOSED-CAPTIONS"]={},n.SUBTITLES={},n),uri:"",duration:a,playlists:E(d,r)};c>=0&&(p.minimumUpdatePeriod=1e3*c),t&&(p.locations=t),"dynamic"===u&&(p.suggestedPresentationDelay=s);var h=0===p.playlists.length;return l.length&&(p.mediaGroups.AUDIO.audio=function(e,t,r){var n;void 0===t&&(t={}),void 0===r&&(r=!1);var i=e.reduce((function(e,i){var a=i.attributes.role&&i.attributes.role.value||"",o=i.attributes.lang||"",u=i.attributes.label||"main";if(o&&!i.attributes.label){var s=a?" ("+a+")":"";u=""+i.attributes.lang+s}e[u]||(e[u]={language:o,autoselect:!0,default:"main"===a,playlists:[],uri:""});var c=w(function(e,t){var r,n=e.attributes,i=e.segments,a=e.sidx,o={attributes:(r={NAME:n.id,BANDWIDTH:n.bandwidth,CODECS:n.codecs},r["PROGRAM-ID"]=1,r),uri:"",endList:"static"===(n.type||"static"),timeline:n.periodIndex,resolvedUri:"",targetDuration:n.duration,segments:i,mediaSequence:i.length?i[0].number:1};return n.contentProtection&&(o.contentProtection=n.contentProtection),a&&(o.sidx=a),t&&(o.attributes.AUDIO="audio",o.attributes.SUBTITLES="subs"),o}(i,r),t);return e[u].playlists.push(c),void 0===n&&"main"===a&&((n=i).default=!0),e}),{});return n||(i[Object.keys(i)[0]].default=!0),i}(l,r,h)),f.length&&(p.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:[],uri:""}),e[n].playlists.push(w(function(e){var t,r=e.attributes,n=e.segments;void 0===n&&(n=[{uri:r.baseUrl,timeline:r.periodIndex,resolvedUri:r.baseUrl||"",duration:r.sourceDuration,number:0}],r.duration=r.sourceDuration);var i=((t={NAME:r.id,BANDWIDTH:r.bandwidth})["PROGRAM-ID"]=1,t);return r.codecs&&(i.CODECS=r.codecs),{attributes:i,uri:"",endList:"static"===(r.type||"static"),timeline:r.periodIndex,resolvedUri:r.baseUrl||"",targetDuration:r.duration,segments:n,mediaSequence:n.length?n[0].number:1}}(r),t)),e}),{})}(f,r)),m.length&&(p.mediaGroups["CLOSED-CAPTIONS"].cc=m.reduce((function(e,t){return t?(t.forEach((function(t){var r=t.channel,n=t.language;e[n]={autoselect:!1,default:!1,instreamId:r,language:n},t.hasOwnProperty("aspectRatio")&&(e[n].aspectRatio=t.aspectRatio),t.hasOwnProperty("easyReader")&&(e[n].easyReader=t.easyReader),t.hasOwnProperty("3D")&&(e[n]["3D"]=t["3D"])})),e):e}),{})),p},A=function(e,t,r){var n=e.NOW,i=e.clientOffset,a=e.availabilityStartTime,o=e.timescale,u=void 0===o?1:o,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*u-t)/r)},M=function(e,t){for(var r=e.type,n=void 0===r?"static":r,i=e.minimumUpdatePeriod,a=void 0===i?0:i,o=e.media,u=void 0===o?"":o,s=e.sourceDuration,c=e.timescale,d=void 0===c?1:c,l=e.startNumber,f=void 0===l?1:l,m=e.periodIndex,p=[],h=-1,v=0;v<t.length;v++){var g=t[v],b=g.d,y=g.r||0,U=g.t||0;h<0&&(h=U),U&&U>h&&(h=U);var I=void 0;if(y<0){var D=v+1;I=D===t.length?"dynamic"===n&&a>0&&u.indexOf("$Number$")>0?A(e,h,b):(s*d-h)/b:(t[D].t-h)/b}else I=y+1;for(var R=f+p.length+I,L=f+p.length;L<R;)p.push({number:L,duration:b/d,time:h,timeline:m}),h+=b,L++}return p},C=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,z=function(e,t){return e.replace(C,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))},B=function(e,t){var r={RepresentationID:e.id,Bandwidth:e.bandwidth||0},n=e.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=b({baseUrl:e.baseUrl,source:z(i.sourceURL,r),range:i.range});return function(e,t){return e.duration||t?e.duration?I(e):M(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=z(e.media||"",r),i={uri:n,timeline:t.timeline,duration:t.duration,resolvedUri:g(e.baseUrl||"",n),map:a,number:t.number};return e.presentationTimeOffset&&(i.presentationTimeOffset=e.presentationTimeOffset),i}))},F=function(e,t){var r=e.duration,n=e.segmentUrls,i=void 0===n?[]:n;if(!r&&!t||r&&t)throw new Error(m);var a,o=i.map((function(t){return function(e,t){var r=e.baseUrl,n=e.initialization,i=void 0===n?{}:n,a=b({baseUrl:r,source:i.sourceURL,range:i.range}),o=b({baseUrl:r,source:t.media,range:t.mediaRange});return o.map=a,o}(e,t)}));return r&&(a=I(e)),t&&(a=M(e,t)),a.map((function(e,t){if(o[t]){var r=o[t];return r.timeline=e.timeline,r.duration=e.duration,r.number=e.number,r}})).filter((function(e){return e}))},_=function(e){var t,r,n=e.attributes,i=e.segmentInfo;i.template?(r=B,t=o(n,i.template),i.template.presentationTimeOffset&&(t.presentationTimeOffset=i.template.presentationTimeOffset/i.template.timescale)):i.base?(r=D,t=o(n,i.base)):i.list&&(r=F,t=o(n,i.list));var a={attributes:n};if(!r)return a;var u=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 u.length?t.duration=u.reduce((function(e,t){return Math.max(e,Math.ceil(t.duration))}),0):t.duration=0;return a.attributes=t,a.segments=u,i.base&&t.indexRange&&(a.sidx=u[0],a.segments=[]),a},j=function(e){return e.map(_)},q=function(e,t){return s(e.childNodes).filter((function(e){return e.tagName===t}))},$=function(e){return e.textContent.trim()},k=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)},G={mediaPresentationDuration:function(e){return k(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 k(e)},suggestedPresentationDelay:function(e){return k(e)},type:function(e){return e},timeShiftBufferDepth:function(e){return k(e)},start:function(e){return k(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)},presentationTimeOffset:function(e){return parseInt(e,10)},duration:function(e){var t=parseInt(e,10);return isNaN(t)?k(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}},H=function(e){return e&&e.attributes?s(e.attributes).reduce((function(e,t){var r=G[t.name]||G.DEFAULT;return e[t.name]=r(t.value),e}),{}):{}};function W(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;a<r.length;a++)n[a]=r.charCodeAt(a);return n}var V={"urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b":"org.w3.clearkey","urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":"com.widevine.alpha","urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":"com.microsoft.playready","urn:uuid:f239e769-efa3-4850-9c16-a903c6932efb":"com.adobe.primetime"},X=function(e,t){return t.length?u(e.map((function(e){return t.map((function(t){return g(e,$(t))}))}))):e},Y=function(e){var t=q(e,"SegmentTemplate")[0],r=q(e,"SegmentList")[0],n=r&&q(r,"SegmentURL").map((function(e){return o({tag:"SegmentURL"},H(e))})),i=q(e,"SegmentBase")[0],a=r||t,u=a&&q(a,"SegmentTimeline")[0],s=r||i||t,c=s&&q(s,"Initialization")[0],d=t&&H(t);d&&c?d.initialization=c&&H(c):d&&d.initialization&&(d.initialization={sourceURL:d.initialization});var l={template:d,timeline:u&&q(u,"S").map((function(e){return H(e)})),list:r&&o(H(r),{segmentUrls:n,initialization:H(c)}),base:i&&o(H(i),{initialization:H(c)})};return Object.keys(l).forEach((function(e){l[e]||delete l[e]})),l},Z=function(e,t,r){return function(n){var i,a=H(n),s=X(t,q(n,"BaseURL")),c=q(n,"Role")[0],d={role:H(c)},l=o(e,a,d),f=q(n,"Accessibility")[0],m="urn:scte:dash:cc:cea-608:2015"===(i=H(f)).schemeIdUri?i.value.split(";").map((function(e){var t,r;if(r=e,/^CC\d=/.test(e)){var n=e.split("=");t=n[0],r=n[1]}else/^CC\d$/.test(e)&&(t=e);return{channel:t,language:r}})):"urn:scte:dash:cc:cea-708:2015"===i.schemeIdUri?i.value.split(";").map((function(e){var t={channel:void 0,language:void 0,aspectRatio:1,easyReader:0,"3D":0};if(/=/.test(e)){var r=e.split("="),n=r[0],i=r[1],a=void 0===i?"":i;t.channel=n,t.language=e,a.split(",").forEach((function(e){var r=e.split(":"),n=r[0],i=r[1];"lang"===n?t.language=i:"er"===n?t.easyReader=Number(i):"war"===n?t.aspectRatio=Number(i):"3D"===n&&(t["3D"]=Number(i))}))}else t.language=e;return t.channel&&(t.channel="SERVICE"+t.channel),t})):void 0;m&&(l=o(l,{captionServices:m}));var p=q(n,"Label")[0];if(p&&p.childNodes.length){var h=p.childNodes[0].nodeValue.trim();l=o(l,{label:h})}var v=q(n,"ContentProtection").reduce((function(e,t){var r=H(t),n=V[r.schemeIdUri];if(n){e[n]={attributes:r};var i=q(t,"cenc:pssh")[0];if(i){var a=$(i),o=a&&W(a);e[n].pssh=o}}return e}),{});Object.keys(v).length&&(l=o(l,{contentProtection:v}));var g=Y(n),b=q(n,"Representation"),y=o(r,g);return u(b.map(function(e,t,r){return function(n){var i=q(n,"BaseURL"),a=X(t,i),u=o(e,H(n)),s=Y(n);return a.map((function(e){return{segmentInfo:o(r,s),attributes:o(u,{baseUrl:e})}}))}}(l,s,y)))}},K=function(e,t){return function(r,n){var a=X(t,q(r,"BaseURL")),s=H(r),c=parseInt(s.id,10),d=i.default.isNaN(c)?n:c,l=o(e,{periodIndex:d}),f=q(r,"AdaptationSet"),m=Y(r);return u(f.map(Z(l,a,m)))}},J=function(e,t){void 0===t&&(t={});var r=t,n=r.manifestUri,i=void 0===n?"":n,a=r.NOW,o=void 0===a?Date.now():a,s=r.clientOffset,d=void 0===s?0:s,l=q(e,"Period");if(!l.length)throw new Error(c);var f=q(e,"Location"),m=H(e),p=X([i],q(e,"BaseURL"));return m.sourceDuration=m.mediaPresentationDuration||0,m.NOW=o,m.clientOffset=d,f.length&&(m.locations=f.map($)),{locations:m.locations,representationInfo:u(l.map(K(m,p)))}},Q=function(e){if(""===e)throw new Error(d);var t,n,i=new r.DOMParser;try{n=(t=i.parseFromString(e,"application/xml"))&&"MPD"===t.documentElement.tagName?t.documentElement:null}catch(e){}if(!n||n&&n.getElementsByTagName("parsererror").length>0)throw new Error(l);return n};e.VERSION="0.17.0",e.addSidxSegmentsToPlaylist=R,e.generateSidxKey=L,e.inheritAttributes=J,e.parse=function(e,t){void 0===t&&(t={});var r=J(Q(e),t),n=j(r.representationInfo);return N(n,r.locations,t.sidxMapping)},e.parseUTCTiming=function(e){return function(e){var t=q(e,"UTCTiming")[0];if(!t)return null;var r=H(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}(Q(e))},e.stringToMpdXml=Q,e.toM3u8=N,e.toPlaylists=j,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "mpd-parser",
"version": "0.16.0",
"version": "0.17.0",
"description": "mpd parser",

@@ -60,3 +60,3 @@ "main": "dist/mpd-parser.cjs.js",

"@babel/runtime": "^7.12.5",
"@videojs/vhs-utils": "^3.0.0",
"@videojs/vhs-utils": "^3.0.2",
"global": "^4.4.0",

@@ -63,0 +63,0 @@ "xmldom": "^0.5.0"

@@ -198,2 +198,88 @@ import window from 'global/window';

// defined in ANSI_SCTE 214-1 2016
export const parseCaptionServiceMetadata = (service) => {
// 608 captions
if (service.schemeIdUri === 'urn:scte:dash:cc:cea-608:2015') {
const values = service.value.split(';');
return values.map((value) => {
let channel;
let language;
// default language to value
language = value;
if (/^CC\d=/.test(value)) {
[channel, language] = value.split('=');
} else if (/^CC\d$/.test(value)) {
channel = value;
}
return {channel, language};
});
} else if (service.schemeIdUri === 'urn:scte:dash:cc:cea-708:2015') {
const values = service.value.split(';');
return values.map((value) => {
const flags = {
// service or channel number 1-63
'channel': undefined,
// language is a 3ALPHA per ISO 639.2/B
// field is required
'language': undefined,
// BIT 1/0 or ?
// default value is 1, meaning 16:9 aspect ratio, 0 is 4:3, ? is unknown
'aspectRatio': 1,
// BIT 1/0
// easy reader flag indicated the text is tailed to the needs of beginning readers
// default 0, or off
'easyReader': 0,
// BIT 1/0
// If 3d metadata is present (CEA-708.1) then 1
// default 0
'3D': 0
};
if (/=/.test(value)) {
const [channel, opts = ''] = value.split('=');
flags.channel = channel;
flags.language = value;
opts.split(',').forEach((opt) => {
const [name, val] = opt.split(':');
if (name === 'lang') {
flags.language = val;
// er for easyReadery
} else if (name === 'er') {
flags.easyReader = Number(val);
// war for wide aspect ratio
} else if (name === 'war') {
flags.aspectRatio = Number(val);
} else if (name === '3D') {
flags['3D'] = Number(val);
}
});
} else {
flags.language = value;
}
if (flags.channel) {
flags.channel = 'SERVICE' + flags.channel;
}
return flags;
});
}
};
/**

@@ -236,5 +322,12 @@ * Maps an AdaptationSet node to a list of Representation information objects

adaptationSetAttributes,
roleAttributes
roleAttributes,
);
const accessibility = findChildren(adaptationSet, 'Accessibility')[0];
const captionServices = parseCaptionServiceMetadata(parseAttributes(accessibility));
if (captionServices) {
attrs = merge(attrs, { captionServices });
}
const label = findChildren(adaptationSet, 'Label')[0];

@@ -241,0 +334,0 @@

@@ -204,2 +204,35 @@ import { values } from './utils/object';

const organizeCaptionServices = (captionServices) => captionServices.reduce((svcObj, svc) => {
if (!svc) {
return svcObj;
}
svc.forEach((service) => {
const {
channel,
language
} = service;
svcObj[language] = {
autoselect: false,
default: false,
instreamId: channel,
language
};
if (service.hasOwnProperty('aspectRatio')) {
svcObj[language].aspectRatio = service.aspectRatio;
}
if (service.hasOwnProperty('easyReader')) {
svcObj[language].easyReader = service.easyReader;
}
if (service.hasOwnProperty('3D')) {
svcObj[language]['3D'] = service['3D'];
}
});
return svcObj;
}, {});
export const formatVideoPlaylist = ({ attributes, segments, sidx }) => {

@@ -262,2 +295,3 @@ const playlist = {

const vttPlaylists = dashPlaylists.filter(vttOnly);
const captions = dashPlaylists.map((playlist) => playlist.attributes.captionServices).filter(Boolean);

@@ -302,3 +336,7 @@ const master = {

if (captions.length) {
master.mediaGroups['CLOSED-CAPTIONS'].cc = organizeCaptionServices(captions);
}
return master;
};

@@ -11,2 +11,4 @@ import { parse, VERSION } from '../src';

import segmentListTemplate from './manifests/segmentList.mpd';
import cc608CaptionsTemplate from './manifests/608-captions.mpd';
import cc708CaptionsTemplate from './manifests/708-captions.mpd';
import locationTemplate from './manifests/location.mpd';

@@ -28,2 +30,8 @@ import locationsTemplate from './manifests/locations.mpd';

import {
parsedManifest as cc608CaptionsManifest
} from './manifests/608-captions.js';
import {
parsedManifest as cc708CaptionsManifest
} from './manifests/708-captions.js';
import {
parsedManifest as multiperiodManifest

@@ -75,2 +83,10 @@ } from './manifests/multiperiod.js';

}, {
name: '608-captions',
input: cc608CaptionsTemplate,
expected: cc608CaptionsManifest
}, {
name: '708-captions',
input: cc708CaptionsTemplate,
expected: cc708CaptionsManifest
}, {
name: 'multiperiod',

@@ -77,0 +93,0 @@ input: multiperiod,

import {
inheritAttributes,
buildBaseUrls,
parseCaptionServiceMetadata,
getSegmentInformation

@@ -177,2 +178,260 @@ } from '../src/inheritAttributes';

QUnit.module('caption service metadata');
QUnit.test('parsed 608 metadata', function(assert) {
const getmd = (value) => ({
schemeIdUri: 'urn:scte:dash:cc:cea-608:2015',
value
});
const assertServices = (services, expected, message) => {
if (!services) {
assert.notOk(expected, message);
return;
}
services.forEach((service, i) => {
assert.deepEqual(service, expected[i], message);
});
};
assertServices(parseCaptionServiceMetadata({
schemeIdUri: 'random scheme',
value: 'CC1'
}), undefined, 'dont parse incorrect scheme ID for 608');
assertServices(parseCaptionServiceMetadata(getmd('CC1')), [{
channel: 'CC1',
language: 'CC1'
}], 'CC1');
assertServices(parseCaptionServiceMetadata(getmd('CC2')), [{
channel: 'CC2',
language: 'CC2'
}], 'CC2');
assertServices(parseCaptionServiceMetadata(getmd('English')), [{
channel: undefined,
language: 'English'
}], 'English');
assertServices(parseCaptionServiceMetadata(getmd('CC1;CC2')), [{
channel: 'CC1',
language: 'CC1'
}, {
channel: 'CC2',
language: 'CC2'
}], 'CC1;CC2');
assertServices(parseCaptionServiceMetadata(getmd('CC1=eng;CC3=swe')), [{
channel: 'CC1',
language: 'eng'
}, {
channel: 'CC3',
language: 'swe'
}], 'CC1=eng;CC3=swe');
assertServices(parseCaptionServiceMetadata(getmd('CC1=Hello;CC3=World')), [{
channel: 'CC1',
language: 'Hello'
}, {
channel: 'CC3',
language: 'World'
}], 'CC1=Hello;CC3=World');
assertServices(parseCaptionServiceMetadata(getmd('eng;swe')), [{
channel: undefined,
language: 'eng'
}, {
channel: undefined,
language: 'swe'
}], 'eng;CC3');
});
QUnit.test('parsed 708 metadata', function(assert) {
const getmd = (value) => ({
schemeIdUri: 'urn:scte:dash:cc:cea-708:2015',
value
});
const assertServices = (services, expected, message) => {
if (!services) {
assert.notOk(expected, message);
return;
}
services.forEach((service, i) => {
assert.deepEqual(service, expected[i], message);
});
};
assertServices(parseCaptionServiceMetadata({
schemeIdUri: 'random scheme',
value: 'eng'
}), undefined, 'dont parse incorrect scheme for 708');
assertServices(parseCaptionServiceMetadata(getmd('eng')), [{
'channel': undefined,
'language': 'eng',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}], 'simple eng');
assertServices(parseCaptionServiceMetadata(getmd('eng;swe')), [{
'channel': undefined,
'language': 'eng',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'swe',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}], 'eng;swe');
assertServices(parseCaptionServiceMetadata(getmd('1=lang:eng;2=lang:swe')), [{
'channel': 'SERVICE1',
'language': 'eng',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': 'SERVICE2',
'language': 'swe',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}], '1=lang:eng;2=lang:swe');
assertServices(parseCaptionServiceMetadata(getmd('1=lang:eng;swe')), [{
'channel': 'SERVICE1',
'language': 'eng',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'swe',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}], 'mixed 1=lang:eng;swe');
assertServices(parseCaptionServiceMetadata(getmd('1=lang:eng;2=lang:eng,war:1,er:1')), [{
'channel': 'SERVICE1',
'language': 'eng',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': 'SERVICE2',
'language': 'eng',
'aspectRatio': 1,
'easyReader': 1,
'3D': 0
}], '1=lang:eng;2=lang:eng,war:1,er:1');
assertServices(parseCaptionServiceMetadata(getmd('1=lang:eng,war:0;2=lang:eng,3D:1,er:1')), [{
'channel': 'SERVICE1',
'language': 'eng',
'aspectRatio': 0,
'easyReader': 0,
'3D': 0
}, {
'channel': 'SERVICE2',
'language': 'eng',
'aspectRatio': 1,
'easyReader': 1,
'3D': 1
}], '1=lang:eng,war:0;2=lang:eng,3D:1,er:1');
assertServices(parseCaptionServiceMetadata(getmd('eng;fre;spa;jpn;deu;swe;kor;lat;zho;heb;rus;ara;hin;por;tur')), [{
'channel': undefined,
'language': 'eng',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'fre',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'spa',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'jpn',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'deu',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'swe',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'kor',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'lat',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'zho',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'heb',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'rus',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'ara',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'hin',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'por',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}, {
'channel': undefined,
'language': 'tur',
'aspectRatio': 1,
'easyReader': 0,
'3D': 0
}], 'make sure that parsing 15 services works');
});
QUnit.module('inheritAttributes');

@@ -179,0 +438,0 @@

@@ -10,4 +10,4 @@ import QUnit from 'qunit';

QUnit.test('returns correct object if given baseUrl only', function(assert) {
assert.deepEqual(urlTypeConverter({ baseUrl: 'http://example.com' }), {
resolvedUri: 'http://example.com',
assert.deepEqual(urlTypeConverter({ baseUrl: 'http://example.com/' }), {
resolvedUri: 'http://example.com/',
uri: ''

@@ -59,6 +59,6 @@ });

assert.deepEqual(urlTypeConverter({
baseUrl: 'http://example.com',
baseUrl: 'http://example.com/',
range: '101-105'
}), {
resolvedUri: 'http://example.com',
resolvedUri: 'http://example.com/',
uri: '',

@@ -74,6 +74,6 @@ byterange: {

assert.deepEqual(urlTypeConverter({
baseUrl: 'http://example.com',
baseUrl: 'http://example.com/',
indexRange: '101-105'
}), {
resolvedUri: 'http://example.com',
resolvedUri: 'http://example.com/',
uri: '',

@@ -80,0 +80,0 @@ byterange: {

@@ -851,2 +851,69 @@ import { toM3u8, generateSidxKey } from '../src/toM3u8';

QUnit.test('608 captions', function(assert) {
const input = [{
attributes: {
captionServices: [{
channel: 'CC1',
language: 'CC1'
}, {
channel: 'CC2',
language: 'CC2'
}, {
channel: undefined,
language: 'English'
}, {
channel: 'CC4',
language: 'eng'
}],
id: '1',
codecs: 'foo;bar',
sourceDuration: 100,
duration: 0,
bandwidth: 20000,
periodIndex: 1,
mimeType: 'audio/mp4',
type: 'dynamic'
},
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);
const cc = output.mediaGroups['CLOSED-CAPTIONS'].cc;
Object.keys(cc).forEach((key) => {
assert.notOk(cc[key].autoselect, 'no autoselect');
assert.notOk(cc[key].default, 'no default');
});
assert.deepEqual(Object.keys(cc), ['CC1', 'CC2', 'English', 'eng'], 'we have 4 channels');
assert.equal(cc.CC1.instreamId, 'CC1', 'CC1 has an instreamId of CC1');
assert.equal(cc.CC2.instreamId, 'CC2', 'CC2 has an instreamId of CC1');
assert.equal(cc.English.instreamId, undefined, 'English captions dont have an instreamId');
assert.equal(cc.eng.instreamId, 'CC4', 'eng captions have an instreamId of CC4');
});
QUnit.module('generateSidxKey');

@@ -853,0 +920,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc