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

mpd-parser

Package Overview
Dependencies
Maintainers
14
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.8.2-1 to 0.8.2

7

CHANGELOG.md

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

<a name="0.8.2"></a>
## [0.8.2](https://github.com/videojs/mpd-parser/compare/v0.8.1...v0.8.2) (2019-08-22)
### Chores
* update generator and use [@videojs](https://github.com/videojs)/vhs-utils ([#76](https://github.com/videojs/mpd-parser/issues/76)) ([1238749](https://github.com/videojs/mpd-parser/commit/1238749))
<a name="0.8.1"></a>

@@ -2,0 +9,0 @@ ## [0.8.1](https://github.com/videojs/mpd-parser/compare/v0.8.0...v0.8.1) (2019-05-01)

8

dist/mpd-parser.cjs.js

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

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

@@ -8,7 +8,7 @@

var resolveUrl = _interopDefault(require('@videojs/vhs-utils/dist/resolve-url.es.js'));
var resolveUrl = _interopDefault(require('@videojs/vhs-utils/dist/resolve-url'));
var window = _interopDefault(require('global/window'));
var decodeB64ToUint8Array = _interopDefault(require('@videojs/vhs-utils/dist/decode-b64-to-uint8-array.es.js'));
var decodeB64ToUint8Array = _interopDefault(require('@videojs/vhs-utils/dist/decode-b64-to-uint8-array'));
var version = "0.8.2-1";
var version = "0.8.2";

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

@@ -1,7 +0,7 @@

/*! @name mpd-parser @version 0.8.2-1 @license Apache-2.0 */
import resolveUrl from '@videojs/vhs-utils/dist/resolve-url.es.js';
/*! @name mpd-parser @version 0.8.2 @license Apache-2.0 */
import resolveUrl from '@videojs/vhs-utils/dist/resolve-url';
import window from 'global/window';
import decodeB64ToUint8Array from '@videojs/vhs-utils/dist/decode-b64-to-uint8-array.es.js';
import decodeB64ToUint8Array from '@videojs/vhs-utils/dist/decode-b64-to-uint8-array';
var version = "0.8.2-1";
var version = "0.8.2";

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

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

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

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

"@babel/runtime": "^7.5.5",
"@videojs/vhs-utils": "github:videojs/vhs-utils#force-dist",
"@videojs/vhs-utils": "^1.0.0",
"global": "^4.3.2"

@@ -62,13 +62,12 @@ },

"karma": "^4.0.0",
"postcss-cli": "^6.0.0",
"rollup": "^1.19.4",
"rollup-plugin-string": "^2.0.2",
"sinon": "^7.2.2",
"videojs-generate-karma-config": "~5.3.0",
"videojs-generate-karma-config": "~5.3.1",
"videojs-generate-rollup-config": "~5.0.1",
"videojs-generator-verify": "~1.2.0",
"videojs-generator-verify": "~2.0.0",
"videojs-standard": "^8.0.3"
},
"generator-videojs-plugin": {
"version": "7.7.0"
"version": "7.7.3"
},

@@ -75,0 +74,0 @@ "browserslist": [

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

import errors from './errors';
import decodeB64ToUint8Array from '@videojs/vhs-utils/dist/decode-b64-to-uint8-array.es.js';
import resolveUrl from '@videojs/vhs-utils/dist/resolve-url.es.js';
import resolveUrl from '@videojs/vhs-utils/dist/resolve-url';
import decodeB64ToUint8Array from '@videojs/vhs-utils/dist/decode-b64-to-uint8-array';

@@ -33,3 +33,7 @@ const keySystemsMap = {

return flatten(referenceUrls.map(reference => baseUrlElements.map(baseUrlElement => resolveUrl(reference, getContent(baseUrlElement)))));
return flatten(referenceUrls.map(function(reference) {
return baseUrlElements.map(function(baseUrlElement) {
return resolveUrl(reference, getContent(baseUrlElement));
});
}));
};

@@ -36,0 +40,0 @@

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

import resolveUrl from '@videojs/vhs-utils/dist/resolve-url.es.js';
import resolveUrl from '@videojs/vhs-utils/dist/resolve-url';
import urlTypeToSegment from './urlType';

@@ -3,0 +3,0 @@ import { parseByTimeline } from './timelineTimeParser';

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

import resolveUrl from '@videojs/vhs-utils/dist/resolve-url.es.js';
import resolveUrl from '@videojs/vhs-utils/dist/resolve-url';

@@ -3,0 +3,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