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.13.0 to 0.14.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

<a name="0.14.0"></a>
# [0.14.0](https://github.com/videojs/mpd-parser/compare/v0.13.0...v0.14.0) (2020-11-03)
### Chores
* **package:** update to vhs-utils[@2](https://github.com/2) ([#108](https://github.com/videojs/mpd-parser/issues/108)) ([8337333](https://github.com/videojs/mpd-parser/commit/8337333))
<a name="0.13.0"></a>

@@ -2,0 +9,0 @@ # [0.13.0](https://github.com/videojs/mpd-parser/compare/v0.12.0...v0.13.0) (2020-09-29)

4

dist/mpd-parser.cjs.js

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

/*! @name mpd-parser @version 0.13.0 @license Apache-2.0 */
/*! @name mpd-parser @version 0.14.0 @license Apache-2.0 */
'use strict';

@@ -13,3 +13,3 @@

var version = "0.13.0";
var version = "0.14.0";

@@ -16,0 +16,0 @@ var isObject = function isObject(obj) {

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

/*! @name mpd-parser @version 0.13.0 @license Apache-2.0 */
/*! @name mpd-parser @version 0.14.0 @license Apache-2.0 */
import resolveUrl from '@videojs/vhs-utils/dist/resolve-url';

@@ -7,3 +7,3 @@ import window from 'global/window';

var version = "0.13.0";
var version = "0.14.0";

@@ -10,0 +10,0 @@ var isObject = function isObject(obj) {

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

/*! @name mpd-parser @version 0.13.0 @license Apache-2.0 */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("global/window"),require("xmldom")):"function"==typeof define&&define.amd?define(["exports","global/window","xmldom"],e):e((t=t||self).mpdParser={},t.window,t.window)}(this,function(t,e,r){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var n=function(t){return!!t&&"object"==typeof t},i=function t(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];return r.reduce(function(e,r){return Object.keys(r).forEach(function(i){Array.isArray(e[i])&&Array.isArray(r[i])?e[i]=e[i].concat(r[i]):n(e[i])&&n(r[i])?e[i]=t(e[i],r[i]):e[i]=r[i]}),e},{})},a=function(t){return t.reduce(function(t,e){return t.concat(e)},[])},o=function(t){if(!t.length)return[];for(var e=[],r=0;r<t.length;r++)e.push(t[r]);return e},u="INVALID_NUMBER_OF_PERIOD",s="DASH_EMPTY_MANIFEST",c="DASH_INVALID_XML",d="NO_BASE_URL",l="SEGMENT_TIME_UNSPECIFIED",m="UNSUPPORTED_UTC_TIMING_SCHEME";function f(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var p=f(function(t,e){return t(e={exports:{}},e.exports),e.exports}(function(t,e){!function(e){var r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/\?#]*\/)*.*?)??(;.*?)?(\?.*?)?(#.*?)?$/,n=/^([^\/?#]*)(.*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g,o={buildAbsoluteURL:function(t,e,r){if(r=r||{},t=t.trim(),!(e=e.trim())){if(!r.alwaysNormalize)return t;var i=o.parseURL(t);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(e);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)):e;var u=o.parseURL(t);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(t){var e=r.exec(t);return e?{scheme:e[1]||"",netLoc:e[2]||"",path:e[3]||"",params:e[4]||"",query:e[5]||"",fragment:e[6]||""}:null},normalizePath:function(t){for(t=t.split("").reverse().join("").replace(i,"");t.length!==(t=t.replace(a,"")).length;);return t.split("").reverse().join("")},buildURLFromParts:function(t){return t.scheme+t.netLoc+t.path+t.params+t.query+t.fragment}};t.exports=o}()})),v=f(e),h=function(t,e){return/^[a-z]+:/i.test(e)?e:(/\/\//i.test(t)||(t=p.buildAbsoluteURL(v.location&&v.location.href||"",t)),p.buildAbsoluteURL(t,e))},g=function(t){var e=t.baseUrl,r=void 0===e?"":e,n=t.source,i=void 0===n?"":n,a=t.range,o=void 0===a?"":a,u=t.indexRange,s=void 0===u?"":u,c={uri:i,resolvedUri:h(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},b={static:function(t){var e=t.duration,r=t.timescale,n=void 0===r?1:r,i=t.sourceDuration;return{start:0,end:Math.ceil(i/(e/n))}},dynamic:function(t){var e=t.NOW,r=t.clientOffset,n=t.availabilityStartTime,i=t.timescale,a=void 0===i?1:i,o=t.duration,u=t.start,s=void 0===u?0:u,c=t.minimumUpdatePeriod,d=void 0===c?0:c,l=t.timeShiftBufferDepth,m=void 0===l?1/0:l,f=(e+r)/1e3,p=n+s,v=f+d-p,h=Math.ceil(v*a/o),g=Math.floor((f-p-m)*a/o),b=Math.floor((f-p)*a/o);return{start:Math.max(0,g),end:Math.min(h,b)}}},U=function(t){var e=t.type,r=void 0===e?"static":e,n=t.duration,i=t.timescale,a=void 0===i?1:i,o=t.sourceDuration,u=b[r](t),s=function(t,e){for(var r=[],n=t;n<e;n++)r.push(n);return r}(u.start,u.end).map(function(t){return function(e,r){var n=t.duration,i=t.timescale,a=void 0===i?1:i,o=t.periodIndex,u=t.startNumber;return{number:(void 0===u?1:u)+e,duration:n/a,timeline:o,time:r*n}}}(t));if("static"===r){var c=s.length-1;s[c].duration=o-n/a*c}return s},y=function(t){var e=t.baseUrl,r=t.initialization,n=void 0===r?{}:r,i=t.sourceDuration,a=t.indexRange,o=void 0===a?"":a,u=t.duration;if(!e)throw new Error(d);var s=g({baseUrl:e,source:n.sourceURL,range:n.range}),c=g({baseUrl:e,source:e,indexRange:o});if(c.map=s,u){var l=U(t);l.length&&(c.duration=l[0].duration,c.timeline=l[0].timeline)}else i&&(c.duration=i,c.timeline=0);return c.number=0,[c]},I=function(t,e,r){for(var n=t.sidx.map?t.sidx.map:null,i=t.sidx.duration,a=t.timeline||0,o=t.sidx.byterange,u=o.offset+o.length,s=e.timescale,c=e.references.filter(function(t){return 1!==t.referenceType}),d=[],l=u+e.firstOffset,m=0;m<c.length;m++){var f=e.references[m],p=f.referencedSize,v=f.subsegmentDuration,h=y({baseUrl:r,timescale:s,timeline:a,periodIndex:a,duration:v,sourceDuration:i,indexRange:l+"-"+(l+p-1)})[0];n&&(h.map=n),d.push(h),l+=p}return t.segments=d,t},D=function(t){var e;return(e=t.reduce(function(t,e){var r,n=e.attributes.id+(e.attributes.lang||"");return t[n]?(e.segments[0]&&(e.segments[0].discontinuity=!0),(r=t[n].segments).push.apply(r,e.segments),e.attributes.contentProtection&&(t[n].attributes.contentProtection=e.attributes.contentProtection)):t[n]=e,t},{}),Object.keys(e).map(function(t){return e[t]})).map(function(t){var e,r;return t.discontinuityStarts=(e=t.segments,r="discontinuity",e.reduce(function(t,e,n){return e[r]&&t.push(n),t},[])),t})},x=function(t,e){if(void 0===e&&(e={}),!Object.keys(e).length)return t;for(var r in t){var n=t[r];if(n.sidx){var i=n.sidx.uri+"-"+(o=n.sidx.byterange,u=void 0,u=o.offset+o.length-1,o.offset+"-"+u),a=e[i]&&e[i].sidx;n.sidx&&a&&I(n,a,n.sidx.resolvedUri)}}var o,u;return t},L=function(t){var e,r=t.attributes,n=t.segments,i=t.sidx,a={attributes:(e={NAME:r.id,BANDWIDTH:r.bandwidth,CODECS:r.codecs},e["PROGRAM-ID"]=1,e),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},w=function(t){var e,r=t.attributes,n=t.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=((e={NAME:r.id,BANDWIDTH:r.bandwidth})["PROGRAM-ID"]=1,e);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}},E=function(t){var e,r=t.attributes,n=t.segments,i=t.sidx,a={attributes:(e={NAME:r.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:r.width,height:r.height},CODECS:r.codecs,BANDWIDTH:r.bandwidth},e["PROGRAM-ID"]=1,e),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(t,e,r){var n;if(void 0===r&&(r={}),!t.length)return{};var i=t[0].attributes,a=i.sourceDuration,o=i.type,u=void 0===o?"static":o,s=i.suggestedPresentationDelay,c=i.minimumUpdatePeriod,d=D(t.filter(function(t){var e=t.attributes;return"video/mp4"===e.mimeType||"video"===e.contentType})).map(E),l=D(t.filter(function(t){var e=t.attributes;return"audio/mp4"===e.mimeType||"audio"===e.contentType})),m=t.filter(function(t){var e=t.attributes;return"text/vtt"===e.mimeType||"text"===e.contentType}),f={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(n={AUDIO:{},VIDEO:{}},n["CLOSED-CAPTIONS"]={},n.SUBTITLES={},n),uri:"",duration:a,playlists:x(d,r)};return c>=0&&(f.minimumUpdatePeriod=1e3*c),e&&(f.locations=e),"dynamic"===u&&(f.suggestedPresentationDelay=s),l.length&&(f.mediaGroups.AUDIO.audio=function(t,e){var r;void 0===e&&(e={});var n=t.reduce(function(t,n){var i=n.attributes.role&&n.attributes.role.value||"",a=n.attributes.lang||"",o="main";if(a){var u=i?" ("+i+")":"";o=""+n.attributes.lang+u}return t[o]&&t[o].playlists[0].attributes.BANDWIDTH>n.attributes.bandwidth?t:(t[o]={language:a,autoselect:!0,default:"main"===i,playlists:x([L(n)],e),uri:""},void 0===r&&"main"===i&&((r=n).default=!0),t)},{});r||(n[Object.keys(n)[0]].default=!0);return n}(l,r)),m.length&&(f.mediaGroups.SUBTITLES.subs=function(t,e){return void 0===e&&(e={}),t.reduce(function(t,r){var n=r.attributes.lang||"text";return t[n]?t:(t[n]={language:n,default:!1,autoselect:!1,playlists:x([w(r)],e),uri:""},t)},{})}(m,r)),f},R=function(t,e,r){var n=t.NOW,i=t.clientOffset,a=t.availabilityStartTime,o=t.timescale,u=void 0===o?1:o,s=t.start,c=void 0===s?0:s,d=t.minimumUpdatePeriod,l=(n+i)/1e3+(void 0===d?0:d)-(a+c);return Math.ceil((l*u-e)/r)},T=function(t,e){for(var r=t.type,n=void 0===r?"static":r,i=t.minimumUpdatePeriod,a=void 0===i?0:i,o=t.media,u=void 0===o?"":o,s=t.sourceDuration,c=t.timescale,d=void 0===c?1:c,l=t.startNumber,m=void 0===l?1:l,f=t.periodIndex,p=[],v=-1,h=0;h<e.length;h++){var g=e[h],b=g.d,U=g.r||0,y=g.t||0;v<0&&(v=y),y&&y>v&&(v=y);var I=void 0;if(U<0){var D=h+1;I=D===e.length?"dynamic"===n&&a>0&&u.indexOf("$Number$")>0?R(t,v,b):(s*d-v)/b:(e[D].t-v)/b}else I=U+1;for(var x=m+p.length+I,L=m+p.length;L<x;)p.push({number:L,duration:b/d,time:v,timeline:f}),v+=b,L++}return p},S=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,N=function(t,e){return t.replace(S,function(t){return function(e,r,n,i){if("$$"===e)return"$";if(void 0===t[r])return e;var a=""+t[r];return"RepresentationID"===r?a:(i=n?parseInt(i,10):1,a.length>=i?a:""+new Array(i-a.length+1).join("0")+a)}}(e))},O=function(t,e){var r={RepresentationID:t.id,Bandwidth:t.bandwidth||0},n=t.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=g({baseUrl:t.baseUrl,source:N(i.sourceURL,r),range:i.range});return function(t,e){return t.duration||e?t.duration?U(t):T(t,e):[{number:t.startNumber||1,duration:t.sourceDuration,time:0,timeline:t.periodIndex}]}(t,e).map(function(e){r.Number=e.number,r.Time=e.time;var n=N(t.media||"",r);return{uri:n,timeline:e.timeline,duration:e.duration,resolvedUri:h(t.baseUrl||"",n),map:a,number:e.number}})},A=function(t,e){var r=t.duration,n=t.segmentUrls,i=void 0===n?[]:n;if(!r&&!e||r&&e)throw new Error(l);var a,o=i.map(function(e){return function(t,e){var r=t.baseUrl,n=t.initialization,i=void 0===n?{}:n,a=g({baseUrl:r,source:i.sourceURL,range:i.range}),o=g({baseUrl:r,source:e.media,range:e.mediaRange});return o.map=a,o}(t,e)});return r&&(a=U(t)),e&&(a=T(t,e)),a.map(function(t,e){if(o[e]){var r=o[e];return r.timeline=t.timeline,r.duration=t.duration,r.number=t.number,r}}).filter(function(t){return t})},M=function(t){var e,r,n=t.attributes,a=t.segmentInfo;a.template?(r=O,e=i(n,a.template)):a.base?(r=y,e=i(n,a.base)):a.list&&(r=A,e=i(n,a.list));var o={attributes:n};if(!r)return o;var u=r(e,a.timeline);if(e.duration){var s=e,c=s.duration,d=s.timescale,l=void 0===d?1:d;e.duration=c/l}else u.length?e.duration=u.reduce(function(t,e){return Math.max(t,Math.ceil(e.duration))},0):e.duration=0;return o.attributes=e,o.segments=u,a.base&&e.indexRange&&(o.sidx=u[0],o.segments=[]),o},z=function(t){return t.map(M)},B=function(t,e){return o(t.childNodes).filter(function(t){return t.tagName===e})},C=function(t){return t.textContent.trim()},F=function(t){var e=/P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/.exec(t);if(!e)return 0;var r=e.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(t){return F(t)},availabilityStartTime:function(t){return/^\d+-\d+-\d+T\d+:\d+:\d+(\.\d+)?$/.test(e=t)&&(e+="Z"),Date.parse(e)/1e3;var e},minimumUpdatePeriod:function(t){return F(t)},suggestedPresentationDelay:function(t){return F(t)},type:function(t){return t},timeShiftBufferDepth:function(t){return F(t)},start:function(t){return F(t)},width:function(t){return parseInt(t,10)},height:function(t){return parseInt(t,10)},bandwidth:function(t){return parseInt(t,10)},startNumber:function(t){return parseInt(t,10)},timescale:function(t){return parseInt(t,10)},duration:function(t){var e=parseInt(t,10);return isNaN(e)?F(t):e},d:function(t){return parseInt(t,10)},t:function(t){return parseInt(t,10)},r:function(t){return parseInt(t,10)},DEFAULT:function(t){return t}},j=function(t){return t&&t.attributes?o(t.attributes).reduce(function(t,e){var r=_[e.name]||_.DEFAULT;return t[e.name]=r(e.value),t},{}):{}};var q,k=(q=e)&&"object"==typeof q&&"default"in q?q.default:q,$=function(t){return k.atob?k.atob(t):Buffer.from(t,"base64").toString("binary")};var G=function(t){for(var e=$(t),r=new Uint8Array(e.length),n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r},H={"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"},W=function(t,e){return e.length?a(t.map(function(t){return e.map(function(e){return h(t,C(e))})})):t},V=function(t){var e=B(t,"SegmentTemplate")[0],r=B(t,"SegmentList")[0],n=r&&B(r,"SegmentURL").map(function(t){return i({tag:"SegmentURL"},j(t))}),a=B(t,"SegmentBase")[0],o=r||e,u=o&&B(o,"SegmentTimeline")[0],s=r||a||e,c=s&&B(s,"Initialization")[0],d=e&&j(e);d&&c?d.initialization=c&&j(c):d&&d.initialization&&(d.initialization={sourceURL:d.initialization});var l={template:d,timeline:u&&B(u,"S").map(function(t){return j(t)}),list:r&&i(j(r),{segmentUrls:n,initialization:j(c)}),base:a&&i(j(a),{initialization:j(c)})};return Object.keys(l).forEach(function(t){l[t]||delete l[t]}),l},X=function(t,e,r){return function(n){var o=j(n),u=W(e,B(n,"BaseURL")),s=B(n,"Role")[0],c={role:j(s)},d=i(t,o,c),l=B(n,"ContentProtection").reduce(function(t,e){var r=j(e),n=H[r.schemeIdUri];if(n){t[n]={attributes:r};var i=B(e,"cenc:pssh")[0];if(i){var a=C(i),o=a&&G(a);t[n].pssh=o}}return t},{});Object.keys(l).length&&(d=i(d,{contentProtection:l}));var m=V(n),f=B(n,"Representation"),p=i(r,m);return a(f.map(function(t,e,r){return function(n){var a=B(n,"BaseURL"),o=W(e,a),u=i(t,j(n)),s=V(n);return o.map(function(t){return{segmentInfo:i(r,s),attributes:i(u,{baseUrl:t})}})}}(d,u,p)))}},Y=function(t,r){return function(n,o){var u=W(r,B(n,"BaseURL")),s=j(n),c=parseInt(s.id,10),d=e.isNaN(c)?o:c,l=i(t,{periodIndex:d}),m=B(n,"AdaptationSet"),f=V(n);return a(m.map(X(l,u,f)))}},Z=function(t,e){void 0===e&&(e={});var r=e,n=r.manifestUri,i=void 0===n?"":n,o=r.NOW,s=void 0===o?Date.now():o,c=r.clientOffset,d=void 0===c?0:c,l=B(t,"Period");if(!l.length)throw new Error(u);var m=B(t,"Location"),f=j(t),p=W([i],B(t,"BaseURL"));return f.sourceDuration=f.mediaPresentationDuration||0,f.NOW=s,f.clientOffset=d,m.length&&(f.locations=m.map(C)),{locations:f.locations,representationInfo:a(l.map(Y(f,p)))}},J=function(t){if(""===t)throw new Error(s);var e=(new r.DOMParser).parseFromString(t,"application/xml"),n=e&&"MPD"===e.documentElement.tagName?e.documentElement:null;if(!n||n&&n.getElementsByTagName("parsererror").length>0)throw new Error(c);return n};t.VERSION="0.13.0",t.inheritAttributes=Z,t.parse=function(t,e){void 0===e&&(e={});var r=Z(J(t),e),n=z(r.representationInfo);return P(n,r.locations,e.sidxMapping)},t.parseUTCTiming=function(t){return function(t){var e=B(t,"UTCTiming")[0];if(!e)return null;var r=j(e);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(m)}return r}(J(t))},t.stringToMpdXml=J,t.toM3u8=P,t.toPlaylists=z,Object.defineProperty(t,"__esModule",{value:!0})});
/*! @name mpd-parser @version 0.14.0 @license Apache-2.0 */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("global/window"),require("xmldom")):"function"==typeof define&&define.amd?define(["exports","global/window","xmldom"],e):e((t=t||self).mpdParser={},t.window,t.window)}(this,function(t,e,r){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var n=function(t){return!!t&&"object"==typeof t},i=function t(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];return r.reduce(function(e,r){return Object.keys(r).forEach(function(i){Array.isArray(e[i])&&Array.isArray(r[i])?e[i]=e[i].concat(r[i]):n(e[i])&&n(r[i])?e[i]=t(e[i],r[i]):e[i]=r[i]}),e},{})},a=function(t){return t.reduce(function(t,e){return t.concat(e)},[])},u=function(t){if(!t.length)return[];for(var e=[],r=0;r<t.length;r++)e.push(t[r]);return e},o="INVALID_NUMBER_OF_PERIOD",s="DASH_EMPTY_MANIFEST",c="DASH_INVALID_XML",d="NO_BASE_URL",l="SEGMENT_TIME_UNSPECIFIED",f="UNSUPPORTED_UTC_TIMING_SCHEME";function m(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var p=m(function(t,e){return t(e={exports:{}},e.exports),e.exports}(function(t,e){var r,n,i,a,u;r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#.*)?$/,n=/^([^\/?#]*)(.*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,u={buildAbsoluteURL:function(t,e,r){if(r=r||{},t=t.trim(),!(e=e.trim())){if(!r.alwaysNormalize)return t;var i=u.parseURL(t);if(!i)throw new Error("Error trying to parse base URL.");return i.path=u.normalizePath(i.path),u.buildURLFromParts(i)}var a=u.parseURL(e);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=u.normalizePath(a.path),u.buildURLFromParts(a)):e;var o=u.parseURL(t);if(!o)throw new Error("Error trying to parse base URL.");if(!o.netLoc&&o.path&&"/"!==o.path[0]){var s=n.exec(o.path);o.netLoc=s[1],o.path=s[2]}o.netLoc&&!o.path&&(o.path="/");var c={scheme:o.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(c.netLoc=o.netLoc,"/"!==a.path[0]))if(a.path){var d=o.path,l=d.substring(0,d.lastIndexOf("/")+1)+a.path;c.path=u.normalizePath(l)}else c.path=o.path,a.params||(c.params=o.params,a.query||(c.query=o.query));return null===c.path&&(c.path=r.alwaysNormalize?u.normalizePath(a.path):a.path),u.buildURLFromParts(c)},parseURL:function(t){var e=r.exec(t);return e?{scheme:e[1]||"",netLoc:e[2]||"",path:e[3]||"",params:e[4]||"",query:e[5]||"",fragment:e[6]||""}:null},normalizePath:function(t){for(t=t.split("").reverse().join("").replace(i,"");t.length!==(t=t.replace(a,"")).length;);return t.split("").reverse().join("")},buildURLFromParts:function(t){return t.scheme+t.netLoc+t.path+t.params+t.query+t.fragment}},t.exports=u})),v=m(e),h=function(t,e){return/^[a-z]+:/i.test(e)?e:(/\/\//i.test(t)||(t=p.default.buildAbsoluteURL(v.default.location&&v.default.location.href||"",t)),p.default.buildAbsoluteURL(t,e))},g=function(t){var e=t.baseUrl,r=void 0===e?"":e,n=t.source,i=void 0===n?"":n,a=t.range,u=void 0===a?"":a,o=t.indexRange,s=void 0===o?"":o,c={uri:i,resolvedUri:h(r||"",i)};if(u||s){var d=(u||s).split("-"),l=parseInt(d[0],10),f=parseInt(d[1],10);c.byterange={length:f-l+1,offset:l}}return c},b={static:function(t){var e=t.duration,r=t.timescale,n=void 0===r?1:r,i=t.sourceDuration;return{start:0,end:Math.ceil(i/(e/n))}},dynamic:function(t){var e=t.NOW,r=t.clientOffset,n=t.availabilityStartTime,i=t.timescale,a=void 0===i?1:i,u=t.duration,o=t.start,s=void 0===o?0:o,c=t.minimumUpdatePeriod,d=void 0===c?0:c,l=t.timeShiftBufferDepth,f=void 0===l?1/0:l,m=(e+r)/1e3,p=n+s,v=m+d-p,h=Math.ceil(v*a/u),g=Math.floor((m-p-f)*a/u),b=Math.floor((m-p)*a/u);return{start:Math.max(0,g),end:Math.min(h,b)}}},U=function(t){var e=t.type,r=void 0===e?"static":e,n=t.duration,i=t.timescale,a=void 0===i?1:i,u=t.sourceDuration,o=b[r](t),s=function(t,e){for(var r=[],n=t;n<e;n++)r.push(n);return r}(o.start,o.end).map(function(t){return function(e,r){var n=t.duration,i=t.timescale,a=void 0===i?1:i,u=t.periodIndex,o=t.startNumber;return{number:(void 0===o?1:o)+e,duration:n/a,timeline:u,time:r*n}}}(t));if("static"===r){var c=s.length-1;s[c].duration=u-n/a*c}return s},y=function(t){var e=t.baseUrl,r=t.initialization,n=void 0===r?{}:r,i=t.sourceDuration,a=t.indexRange,u=void 0===a?"":a,o=t.duration;if(!e)throw new Error(d);var s=g({baseUrl:e,source:n.sourceURL,range:n.range}),c=g({baseUrl:e,source:e,indexRange:u});if(c.map=s,o){var l=U(t);l.length&&(c.duration=l[0].duration,c.timeline=l[0].timeline)}else i&&(c.duration=i,c.timeline=0);return c.number=0,[c]},I=function(t,e,r){for(var n=t.sidx.map?t.sidx.map:null,i=t.sidx.duration,a=t.timeline||0,u=t.sidx.byterange,o=u.offset+u.length,s=e.timescale,c=e.references.filter(function(t){return 1!==t.referenceType}),d=[],l=o+e.firstOffset,f=0;f<c.length;f++){var m=e.references[f],p=m.referencedSize,v=m.subsegmentDuration,h=y({baseUrl:r,timescale:s,timeline:a,periodIndex:a,duration:v,sourceDuration:i,indexRange:l+"-"+(l+p-1)})[0];n&&(h.map=n),d.push(h),l+=p}return t.segments=d,t},D=function(t){var e;return(e=t.reduce(function(t,e){var r,n=e.attributes.id+(e.attributes.lang||"");return t[n]?(e.segments[0]&&(e.segments[0].discontinuity=!0),(r=t[n].segments).push.apply(r,e.segments),e.attributes.contentProtection&&(t[n].attributes.contentProtection=e.attributes.contentProtection)):t[n]=e,t},{}),Object.keys(e).map(function(t){return e[t]})).map(function(t){var e,r;return t.discontinuityStarts=(e=t.segments,r="discontinuity",e.reduce(function(t,e,n){return e[r]&&t.push(n),t},[])),t})},x=function(t,e){if(void 0===e&&(e={}),!Object.keys(e).length)return t;for(var r in t){var n=t[r];if(n.sidx){var i=n.sidx.uri+"-"+(u=n.sidx.byterange,o=void 0,o=u.offset+u.length-1,u.offset+"-"+o),a=e[i]&&e[i].sidx;n.sidx&&a&&I(n,a,n.sidx.resolvedUri)}}var u,o;return t},L=function(t){var e,r=t.attributes,n=t.segments,i=t.sidx,a={attributes:(e={NAME:r.id,BANDWIDTH:r.bandwidth,CODECS:r.codecs},e["PROGRAM-ID"]=1,e),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},w=function(t){var e,r=t.attributes,n=t.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=((e={NAME:r.id,BANDWIDTH:r.bandwidth})["PROGRAM-ID"]=1,e);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}},E=function(t){var e,r=t.attributes,n=t.segments,i=t.sidx,a={attributes:(e={NAME:r.id,AUDIO:"audio",SUBTITLES:"subs",RESOLUTION:{width:r.width,height:r.height},CODECS:r.codecs,BANDWIDTH:r.bandwidth},e["PROGRAM-ID"]=1,e),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(t,e,r){var n;if(void 0===r&&(r={}),!t.length)return{};var i=t[0].attributes,a=i.sourceDuration,u=i.type,o=void 0===u?"static":u,s=i.suggestedPresentationDelay,c=i.minimumUpdatePeriod,d=D(t.filter(function(t){var e=t.attributes;return"video/mp4"===e.mimeType||"video"===e.contentType})).map(E),l=D(t.filter(function(t){var e=t.attributes;return"audio/mp4"===e.mimeType||"audio"===e.contentType})),f=t.filter(function(t){var e=t.attributes;return"text/vtt"===e.mimeType||"text"===e.contentType}),m={allowCache:!0,discontinuityStarts:[],segments:[],endList:!0,mediaGroups:(n={AUDIO:{},VIDEO:{}},n["CLOSED-CAPTIONS"]={},n.SUBTITLES={},n),uri:"",duration:a,playlists:x(d,r)};return c>=0&&(m.minimumUpdatePeriod=1e3*c),e&&(m.locations=e),"dynamic"===o&&(m.suggestedPresentationDelay=s),l.length&&(m.mediaGroups.AUDIO.audio=function(t,e){var r;void 0===e&&(e={});var n=t.reduce(function(t,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 t[u]&&t[u].playlists[0].attributes.BANDWIDTH>n.attributes.bandwidth?t:(t[u]={language:a,autoselect:!0,default:"main"===i,playlists:x([L(n)],e),uri:""},void 0===r&&"main"===i&&((r=n).default=!0),t)},{});r||(n[Object.keys(n)[0]].default=!0);return n}(l,r)),f.length&&(m.mediaGroups.SUBTITLES.subs=function(t,e){return void 0===e&&(e={}),t.reduce(function(t,r){var n=r.attributes.lang||"text";return t[n]?t:(t[n]={language:n,default:!1,autoselect:!1,playlists:x([w(r)],e),uri:""},t)},{})}(f,r)),m},R=function(t,e,r){var n=t.NOW,i=t.clientOffset,a=t.availabilityStartTime,u=t.timescale,o=void 0===u?1:u,s=t.start,c=void 0===s?0:s,d=t.minimumUpdatePeriod,l=(n+i)/1e3+(void 0===d?0:d)-(a+c);return Math.ceil((l*o-e)/r)},T=function(t,e){for(var r=t.type,n=void 0===r?"static":r,i=t.minimumUpdatePeriod,a=void 0===i?0:i,u=t.media,o=void 0===u?"":u,s=t.sourceDuration,c=t.timescale,d=void 0===c?1:c,l=t.startNumber,f=void 0===l?1:l,m=t.periodIndex,p=[],v=-1,h=0;h<e.length;h++){var g=e[h],b=g.d,U=g.r||0,y=g.t||0;v<0&&(v=y),y&&y>v&&(v=y);var I=void 0;if(U<0){var D=h+1;I=D===e.length?"dynamic"===n&&a>0&&o.indexOf("$Number$")>0?R(t,v,b):(s*d-v)/b:(e[D].t-v)/b}else I=U+1;for(var x=f+p.length+I,L=f+p.length;L<x;)p.push({number:L,duration:b/d,time:v,timeline:m}),v+=b,L++}return p},S=/\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g,N=function(t,e){return t.replace(S,function(t){return function(e,r,n,i){if("$$"===e)return"$";if(void 0===t[r])return e;var a=""+t[r];return"RepresentationID"===r?a:(i=n?parseInt(i,10):1,a.length>=i?a:""+new Array(i-a.length+1).join("0")+a)}}(e))},O=function(t,e){var r={RepresentationID:t.id,Bandwidth:t.bandwidth||0},n=t.initialization,i=void 0===n?{sourceURL:"",range:""}:n,a=g({baseUrl:t.baseUrl,source:N(i.sourceURL,r),range:i.range});return function(t,e){return t.duration||e?t.duration?U(t):T(t,e):[{number:t.startNumber||1,duration:t.sourceDuration,time:0,timeline:t.periodIndex}]}(t,e).map(function(e){r.Number=e.number,r.Time=e.time;var n=N(t.media||"",r);return{uri:n,timeline:e.timeline,duration:e.duration,resolvedUri:h(t.baseUrl||"",n),map:a,number:e.number}})},A=function(t,e){var r=t.duration,n=t.segmentUrls,i=void 0===n?[]:n;if(!r&&!e||r&&e)throw new Error(l);var a,u=i.map(function(e){return function(t,e){var r=t.baseUrl,n=t.initialization,i=void 0===n?{}:n,a=g({baseUrl:r,source:i.sourceURL,range:i.range}),u=g({baseUrl:r,source:e.media,range:e.mediaRange});return u.map=a,u}(t,e)});return r&&(a=U(t)),e&&(a=T(t,e)),a.map(function(t,e){if(u[e]){var r=u[e];return r.timeline=t.timeline,r.duration=t.duration,r.number=t.number,r}}).filter(function(t){return t})},M=function(t){var e,r,n=t.attributes,a=t.segmentInfo;a.template?(r=O,e=i(n,a.template)):a.base?(r=y,e=i(n,a.base)):a.list&&(r=A,e=i(n,a.list));var u={attributes:n};if(!r)return u;var o=r(e,a.timeline);if(e.duration){var s=e,c=s.duration,d=s.timescale,l=void 0===d?1:d;e.duration=c/l}else o.length?e.duration=o.reduce(function(t,e){return Math.max(t,Math.ceil(e.duration))},0):e.duration=0;return u.attributes=e,u.segments=o,a.base&&e.indexRange&&(u.sidx=o[0],u.segments=[]),u},z=function(t){return t.map(M)},B=function(t,e){return u(t.childNodes).filter(function(t){return t.tagName===e})},C=function(t){return t.textContent.trim()},F=function(t){var e=/P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/.exec(t);if(!e)return 0;var r=e.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)},_={mediaPresentationDuration:function(t){return F(t)},availabilityStartTime:function(t){return/^\d+-\d+-\d+T\d+:\d+:\d+(\.\d+)?$/.test(e=t)&&(e+="Z"),Date.parse(e)/1e3;var e},minimumUpdatePeriod:function(t){return F(t)},suggestedPresentationDelay:function(t){return F(t)},type:function(t){return t},timeShiftBufferDepth:function(t){return F(t)},start:function(t){return F(t)},width:function(t){return parseInt(t,10)},height:function(t){return parseInt(t,10)},bandwidth:function(t){return parseInt(t,10)},startNumber:function(t){return parseInt(t,10)},timescale:function(t){return parseInt(t,10)},duration:function(t){var e=parseInt(t,10);return isNaN(e)?F(t):e},d:function(t){return parseInt(t,10)},t:function(t){return parseInt(t,10)},r:function(t){return parseInt(t,10)},DEFAULT:function(t){return t}},j=function(t){return t&&t.attributes?u(t.attributes).reduce(function(t,e){var r=_[e.name]||_.DEFAULT;return t[e.name]=r(e.value),t},{}):{}};function q(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var k=q(e),$=function(t){return k.default.atob?k.default.atob(t):Buffer.from(t,"base64").toString("binary")};var G=function(t){for(var e=$(t),r=new Uint8Array(e.length),n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r},H={"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"},W=function(t,e){return e.length?a(t.map(function(t){return e.map(function(e){return h(t,C(e))})})):t},V=function(t){var e=B(t,"SegmentTemplate")[0],r=B(t,"SegmentList")[0],n=r&&B(r,"SegmentURL").map(function(t){return i({tag:"SegmentURL"},j(t))}),a=B(t,"SegmentBase")[0],u=r||e,o=u&&B(u,"SegmentTimeline")[0],s=r||a||e,c=s&&B(s,"Initialization")[0],d=e&&j(e);d&&c?d.initialization=c&&j(c):d&&d.initialization&&(d.initialization={sourceURL:d.initialization});var l={template:d,timeline:o&&B(o,"S").map(function(t){return j(t)}),list:r&&i(j(r),{segmentUrls:n,initialization:j(c)}),base:a&&i(j(a),{initialization:j(c)})};return Object.keys(l).forEach(function(t){l[t]||delete l[t]}),l},X=function(t,e,r){return function(n){var u=j(n),o=W(e,B(n,"BaseURL")),s=B(n,"Role")[0],c={role:j(s)},d=i(t,u,c),l=B(n,"ContentProtection").reduce(function(t,e){var r=j(e),n=H[r.schemeIdUri];if(n){t[n]={attributes:r};var i=B(e,"cenc:pssh")[0];if(i){var a=C(i),u=a&&G(a);t[n].pssh=u}}return t},{});Object.keys(l).length&&(d=i(d,{contentProtection:l}));var f=V(n),m=B(n,"Representation"),p=i(r,f);return a(m.map(function(t,e,r){return function(n){var a=B(n,"BaseURL"),u=W(e,a),o=i(t,j(n)),s=V(n);return u.map(function(t){return{segmentInfo:i(r,s),attributes:i(o,{baseUrl:t})}})}}(d,o,p)))}},Y=function(t,r){return function(n,u){var o=W(r,B(n,"BaseURL")),s=j(n),c=parseInt(s.id,10),d=e.isNaN(c)?u:c,l=i(t,{periodIndex:d}),f=B(n,"AdaptationSet"),m=V(n);return a(f.map(X(l,o,m)))}},Z=function(t,e){void 0===e&&(e={});var r=e,n=r.manifestUri,i=void 0===n?"":n,u=r.NOW,s=void 0===u?Date.now():u,c=r.clientOffset,d=void 0===c?0:c,l=B(t,"Period");if(!l.length)throw new Error(o);var f=B(t,"Location"),m=j(t),p=W([i],B(t,"BaseURL"));return m.sourceDuration=m.mediaPresentationDuration||0,m.NOW=s,m.clientOffset=d,f.length&&(m.locations=f.map(C)),{locations:m.locations,representationInfo:a(l.map(Y(m,p)))}},J=function(t){if(""===t)throw new Error(s);var e=(new r.DOMParser).parseFromString(t,"application/xml"),n=e&&"MPD"===e.documentElement.tagName?e.documentElement:null;if(!n||n&&n.getElementsByTagName("parsererror").length>0)throw new Error(c);return n};t.VERSION="0.14.0",t.inheritAttributes=Z,t.parse=function(t,e){void 0===e&&(e={});var r=Z(J(t),e),n=z(r.representationInfo);return P(n,r.locations,e.sidxMapping)},t.parseUTCTiming=function(t){return function(t){var e=B(t,"UTCTiming")[0];if(!e)return null;var r=j(e);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(f)}return r}(J(t))},t.stringToMpdXml=J,t.toM3u8=P,t.toPlaylists=z,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "mpd-parser",
"version": "0.13.0",
"version": "0.14.0",
"description": "mpd parser",

@@ -57,4 +57,4 @@ "main": "dist/mpd-parser.cjs.js",

"@babel/runtime": "^7.5.5",
"@videojs/vhs-utils": "^2.2.1",
"global": "^4.3.2",
"@videojs/vhs-utils": "^1.1.0",
"xmldom": "^0.1.27"

@@ -61,0 +61,0 @@ },

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

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