import {clpp} from "./cl.core.js";import './cl.mse.js';let g={};const _ = clpp._;var f=function(window){'use strict';var EJ="CLOSED-CAPTIONS",FJ="Could not parse MP4 segment start time.",GJ="DURATION",HJ="EXT-X-DATERANGE",IJ="EXT-X-DISCONTINUITY",JJ="EXT-X-KEY",KJ="EXT-X-MAP",LJ="EXT-X-MEDIA",MJ="EXT-X-MEDIA-SEQUENCE",NJ="EXT-X-STREAM-INF",OJ="Failed to infer discontinuity number",PJ="Guessing audio-only",QJ="METHOD",RJ="SAMPLE-AES-CTR",SJ="SUBTITLES",TJ="application/vnd.apple.mpegurl",UJ="manifestloaded",VJ="sample",WJ=function(a,b){return _.J(a,b,void 0,{required:!0})},XJ=function(a){if(1>a.a)throw _.Zl();
--a.a},YJ=function(a,b){for(const c in a){if(!(c in b))return!1;const d=a[c],e=b[c];if(d&&typeof d===_.Ce&&e&&typeof e===_.Ce){if(!YJ(d,e))return!1}else if(void 0!==d&&void 0!==e&&d!==e)return!1}return!0},ZJ=function(a,b){if(!YJ(a,b))return!1;for(const c in b){if(!(c in a))return!0;const d=a[c],e=b[c];if(!d&&e||d&&typeof d===_.Ce&&e&&typeof e===_.Ce&&ZJ(d,e))return!0}return!1},$J=function(a){if(null!==a&&void 0!==a)return Number(a)},aK=function(a,b){return a.filter(c=>c.name===b)},bK=function(a){const b=
/^[a-zA-Z0-9_-]+$/,c=new Set;a.forEach(d=>{const e=_.J(d,"VALUE"),f=_.J(d,_.Sa),g=_.J(d,"IMPORT"),h=_.J(d,"QUERYPARAM");if(1!==[f,g,h].filter(Boolean).length||f&&null==e)throw new _.I(_.G,4,4044,{message:"Invalid tag.",text:d.toString()});d=f||g||h;if(c.has(d))throw new _.I(_.G,4,4044,`EXT-X-DEFINE redefined variable "${d}".`);if(!b.test(d))throw new _.I(_.G,4,4044,`EXT-X-DEFINE invalid variable name "${d}".`);c.add(d)})},cK=function(a,b){const c=Array.isArray(b)?b:[b];return a.filter(d=>{d=WJ(d,
_.rb);return c.includes(d)})},dK=function(a,b){return a.some(c=>c.name===b)},eK=function(a,b,c){c=void 0===c?{}:c;a=a.find(d=>d.name===b)||null;if(!a&&c.required)throw new _.I(_.G,4,4024,{missingTag:b});return a},fK=function(a){var b=eK(a,"EXT-X-TILES");if(!b)return{ld:1,Fd:1,durationPerTile:null};a=_.J(b,"LAYOUT")||"1x1";b=_.J(b,GJ);a=_.uC(a);return{ld:a.ld,Fd:a.Fd,durationPerTile:b?Number(b):null}},gK=function(a,b){var c=void 0===c?!0:c;a=new _.mi(a);b=new _.mi(b);b=a.resolve(b).toString();return c?
b:decodeURI(b)},hK=function(a){const b=new Set;a.variants.forEach(c=>{c.audio&&b.add(c.audio);c.video&&b.add(c.video)});a.textStreams.forEach(c=>b.add(c));a.thumbStreams.forEach(c=>b.add(c));return Array.from(b)},iK=function(a,b){Array.isArray(a)||(a=[a]);a.forEach(c=>{for(const d of hK(c))b(d,c)})},jK=function(a){return a.some(b=>dK(b.ha,"EXT-X-ENDLIST"))},kK=function(a){return a.type===_.p||a.type===_.w},lK=function(a){if(eK(a,"EXT-X-ENDLIST"))return _.Cb;a=eK(a,"EXT-X-PLAYLIST-TYPE");if(!a)return"LIVE";
if(a.value===_.Cb)return _.Cb;if("EVENT"===a.value)return"EVENT";throw new _.I(_.G,4,4044,`Invalid EXT-X-PLAYLIST-TYPE value: ${a.value}`);},mK=function(a){a={AUDIO:_.p,VIDEO:_.w,SUBTITLES:_.H,"CLOSED-CAPTIONS":_.H}[a.toUpperCase()];if(!a)throw new _.I(_.G,4,4044,"EXT-X-MEDIA tag has an invalid TYPE attribute.");return a},nK=function(a,b,c){c=void 0===c?!1:c;var d=0;let e=null;if(a){d=a.split("@");a=Number(d[0]);if(0>=a)throw new _.I(_.G,4,4044,"Byte range length must be positive.");if(d[1]){if(d=
Number(d[1]),0>d)throw new _.I(_.G,4,4044,"Byte range start byte must not be negative.");}else{if(c)throw new _.I(_.G,4,4044,"Invalid byte range, offset is required but missing.");if(null==b)throw new _.I(_.G,4,4044,"Invalid byte range, cannot calculate offset based on previous byte ranges.");d=b+1}e=d+a-1}return{ya:d,pa:e}},oK=function(a,b){a=eK(a,"EXT-X-BYTERANGE");return nK(a?a.value:null,b)},pK=function(a){a=eK(a,"EXTINF",{required:!0}).value.split(",");return{duration:Number(a[0]),title:a[1]||
null}},qK=function(a,b){b=void 0===b?{}:b;const c={Kf:!1,fh:!1,gh:null,Mh:null,tg:null};a=eK(a,"EXT-X-SERVER-CONTROL",{required:b.zg});if(!a)return c;const d=e=>null==e?null:Number(e);c.Kf="YES"===_.J(a,"CAN-BLOCK-RELOAD");c.fh="YES"===_.J(a,"CAN-SKIP-DATERANGES");c.gh=d(_.J(a,"CAN-SKIP-UNTIL"));c.Mh=d(_.J(a,"HOLD-BACK"));c.tg=d(_.J(a,"PART-HOLD-BACK",void 0,{required:b.zg}));return c},rK=function(a,b,c){c=void 0===c?!1:c;a=_.J(a,"BYTERANGE");return nK(a,b,c)},sK=function(a){const b=aK(a,LJ),c=aK(a,
NJ);a=aK(a,"EXT-X-IMAGE-STREAM-INF");return{Bc:{Ff:cK(b,[_.rB,_.Bb]),closedCaptions:cK(b,EJ),Fi:cK(b,SJ)},Gd:c,Fe:a}},uK=function(a,b){const c=oK(a.ha,null);return new tK(0,0,0,()=>[a.a],c.ya,c.pa,0,b)},vK=function(a){let b=Infinity,c=Infinity;hK(a).filter(kK).forEach(d=>{{d=d.U;var e=d[0].startTime;const f=d[d.length-1].endTime;d=e;e=f-e}b=Math.min(b,d);c=Math.min(c,e)});return{Uc:b,duration:c}},wK=function(a){return a.map(b=>{({duration:b}=vK(b));return b}).reduce((b,c)=>b+c,0)},xK=function(a){return(a.video?
a.video.Da:"")+" - "+(a.audio?a.audio.Da:"")},yK=function(a,b,c,d,e){if(b===_.Cb)return{delay:0,Ed:0};b=eK(a,"EXT-X-PART-INF");if(c&&b){e=Number(WJ(b,"PART-TARGET"));if(null!=d)return{delay:d,Ed:e};({tg:d}=qK(a,{zg:!0}));return{delay:d,Ed:e}}a=eK(a,"EXT-X-TARGETDURATION",{required:!0});a=Number(a.value);e=e||a;return null!=d?{delay:d,Ed:e}:{delay:3*a,Ed:e}},AK=function(a){const b=new Map;a.forEach(c=>{var d=`${zK(c).type}:${zK(c).groupId}`;b.has(d)?(d=b.get(d),d.includes(c)||d.push(c)):b.set(d,[c])});
return b},BK=function(a){const b=new Map;for(const c of a){a=_.J(c,_.Ka);a=_.Bi(a||_.dg);const d=WJ(c,_.Ea),e=WJ(c,"INSTREAM-ID");b.has(d)||b.set(d,new Map);b.get(d).set(e,a)}return b},CK=function(a){return a.filter(b=>"mp4a.40.34"!==b)},DK=function(a,b){if(!a)return null;const c=a.Da;return b.find(d=>zK(d).Da===c)||null},EK=function(a){return(a=_.J(a,"CHANNELS"))?parseInt(a.split("/")[0],10):null},FK=function(a){return a.some(b=>b.startsWith("#EXT-X-TARGETDURATION"))?1:0},GK=function(a,b){const c=
new Map,d=new URL(b);a.forEach(e=>{var f=_.J(e,_.Sa),g=_.J(e,"QUERYPARAM");if(f)g=WJ(e,"VALUE"),c.set(f,g);else if(g){f=d.searchParams.get(g);if(null==f)throw new _.I(_.G,4,4044,`Query param '${g}' missing in playlist URI.`);if(!f)throw new _.I(_.G,4,4044,`Query param '${g}' has no associated value`+" in playlist URI.");c.set(g,decodeURIComponent(f))}});return c},HK=function(a,b){return a.replace(/\{\$([a-zA-Z0-9_-]+)\}/g,(c,d)=>{c=b.get(d);if(null==c)throw new _.I(_.G,4,4044,`Undefined variable '${d}'`);
return c})},IK=function(a,b){a.forEach(c=>{c.attributes.forEach(d=>{d.value=HK(d.value,b)})})},LK=function(a,b,c){const d=[];for(let e=0;e<b.length;e++){const f=JK(a,b[e]);d.push(f);if(f.name===NJ){const g=b[e+1];if(!g)throw new _.I(_.G,4,4044,"EXT-X-STREAM-INF is not followed by a URI.");f.attributes.push(new _.Gi(_.tb,g));e++}}b=aK(d,"EXT-X-DEFINE");bK(b);b=GK(b,c);a.a=b;IK(d,a.a);return new KK(c,0,d)},PK=function(a,b,c){const {si:d,Jh:e,Oi:f}=MK(b),g=NK(a,f,c);b=e.map(k=>JK(a,k,g));const h=OK(a,
c,d,g);return new KK(c,1,b,h)},QK=function(a,b,c){b=b.trim().split(/\n+/m).map(d=>d.trim()).filter(d=>d.length&&!/^#(?!EXT)/m.test(d));if(!/^#EXTM3U($|[ \t\n])/m.test(b[0]))throw new _.I(_.G,4,4015);b=b.slice(1);return 0===FK(b)?LK(a,b,c):PK(a,b,c)},MK=function(a){const b=[],c=[],d=[];for(const e of a)RK.test(e)?d.push(e):SK.test(e)?c.push(e):b.push(e);return{si:b,Jh:c,Oi:d}},NK=function(a,b,c){b=b.map(e=>JK(a,e));bK(b);const d=GK(b,c);b.map(e=>_.J(e,"IMPORT")).filter(Boolean).forEach(e=>{const f=
a.a.get(e);if(null==f)throw new _.I(_.G,4,4044,`Cannot import variable '${e}' as it is not defined `+"in the master playlist");d.set(e,f)});return d},JK=function(a,b,c){a=_.Ii(a.h++,b);c&&IK([a],c);return a},OK=function(a,b,c,d){const e=[];let f=[],g=[];c.forEach(h=>{/^(#EXT)/.test(h)?(h=JK(a,h,d),"EXT-X-PART"===h.name||"EXT-X-PRELOAD-HINT"===h.name&&"PART"===_.J(h,_.rb)?g.push(h):f.push(h)):(dK(f,"EXT-X-GAP")||(h=HK(h,d),h=gK(b,h),e.push(new TK(h,f,g))),f=[],g=[])});0<g.length&&e.push(new TK(null,
f,g));return e},UK=function(a,b,c){const d=[],e=[];e.push(new _.Gi(_.la,"0"));e.push(new _.Gi(_.tb,b));c.length&&e.push(new _.Gi(_.oa,c));d.push(new _.Hi(a.h++,NJ,e));return new KK(b,0,d)},VK=function*(a){let b=-1,c=void 0,d=void 0;for(const e of a)0<=b&&(yield{eg:b,item:d,ii:c,next:e}),b++,c=d,d=e;-1!==b&&(yield{eg:b,ii:c,item:d,next:void 0})},WK=function(a){return 0>a?[]:Array.from({length:a},(b,c)=>c)},XK=function(a){return new Uint8Array([a>>24&255,a>>16&255,a>>8&255,a&255])},YK=function(a,b=
0){return b+10<=a.length&&73===a[b]&&68===a[b+1]&&51===a[b+2]&&255>a[b+3]&&255>a[b+4]&&128>a[b+6]&&128>a[b+7]&&128>a[b+8]&&128>a[b+9]?!0:!1},ZK=function(a){function b(h,k,l){let m="";for(;k<l;k++)m+="%"+("00"+h[k].toString(16)).slice(-2);return m}function c(h){return h[0]<<21|h[1]<<14|h[2]<<7|h[3]}function d(){throw new _.I(_.G,4,4030);}YK(a)||d();let e=10;a[5]&64&&(e=e+4+c(a.subarray(10,14)));do{var f=c(a.subarray(e+4,e+8));1>f&&d();var g=String.fromCharCode(a[e],a[e+1],a[e+2],a[e+3]);if("PRIV"===
g){g=a.subarray(e+10,e+f+10);for(let h=0;h<g.byteLength;h++)if(0===g[h]){if("com.apple.streaming.transportStreamTimestamp"===unescape(b(g,0,h)))return a=g.subarray(h+1),f=(a[3]&1)<<30|a[4]<<22|a[5]<<14|a[6]<<6|a[7]>>>2,f*=4,f+=a[7]&3,Math.round(f/9E4);break}}YK(a,e)||d();e+=10;e+=f}while(e<a.byteLength);return d()},$K=function(a,b){let c=null,d=0;try{(new _.om).N(_.ye,_.hm).N(_.ag,_.hm).N(_.qe,_.hm).ea("mdhd",g=>{g.reader.skip(0===g.version?8:16);d=_.P(g.reader);g.parser.stop()}).parse(b,!0)}catch(g){c=
g}if(c||!d)throw _.Jv.error("Unable to find timescale in init segment!"),new _.I(_.G,4,4030,FJ,c);let e=0,f=!1;try{(new _.om).N("moof",_.hm).N("traf",_.hm).ea("tfdt",g=>{var h=d;if(0===g.version)h=_.P(g.reader)/h;else{{const k=_.P(g.reader),l=_.P(g.reader);if(!(2097151>=k||h>=Math.pow(2,12)))throw Error("Cannot accurately parse MP4 timestamp, base time is too high and timescale is \x3c\x3d 2^12");h=k/h*Math.pow(2,32)+l/h}}e=h;f=!0;g.parser.stop()}).parse(a,!0)}catch(g){c=g}if(c||!f)throw new _.I(_.G,
4,4030,FJ,c);return e},aL=function(a){for(;a.getPosition()<a.Na()-1;){const b=a.getPosition();if(71===_.$l(a))return XJ(a),b}return-1},bL=function(a){function b(){d.seek(e+188);f=_.$l(d);71!==f&&(d.seek(e+192),f=_.$l(d));71!==f&&(d.seek(e+204),f=_.$l(d));71!==f&&c();XJ(d)}function c(){throw new _.I(_.G,4,4030);}const d=new _.ln(new DataView(a),!1);let e=0,f=0;e=aL(d);0>e&&(_.Jv.error("Unable to find sync byte in TS after scanning."),c());for(;;){e=d.getPosition();f=_.$l(d);71!==f&&c();a=_.am(d);if(8191===
(a&8191)){b();continue}if(!(a&16384)){b();continue}a=(_.$l(d)&48)>>4;0!==a&&2!==a||c();3===a&&(a=_.$l(d),d.skip(a));if(1!==_.P(d)>>8){b();continue}d.skip(3);a=_.$l(d)>>6;0!==a&&1!==a||c();0===_.$l(d)&&c();a=_.$l(d);const g=_.am(d),h=_.am(d);return(1073741824*((a&14)>>1)+((g&65534)<<14|(h&65534)>>1))/9E4}},eL=function(a){const b=cL(a),c=dL(a);a.forEach(d=>{const e=d.U,f=e.findIndex(h=>h.oa===b);let g=e.findIndex(h=>h.oa===c+1);-1===g&&(g=e.length);d.U=e.slice(f,g)})},dL=function(a){a=a.map(b=>b.U[b.U.length-
1].oa);return Math.min(...a)},cL=function(a){a=a.map(b=>b.U[0].oa);return Math.max(...a)},hL=function(a){var b=WJ(a,QJ);if(!fL.includes(b))return gL.error("PlayReady in HLS is only supported with [",fL.join(", "),"], not",b),null;a=WJ(a,_.tb);b=_.vt(a);a=null;b=_.K(b.data);try{a=_.cC(_.tn(b))}catch(c){a=b}return _.qC(_.rd,[{initDataType:_.Tc,initData:a}],"")},jL=function(a){if(0===a.length)return iL();if(a.some(c=>"whole-segment"===c.type)||a.every(c=>c.type===_.Be))return a[0];a=a.filter(c=>c.type===
VJ);const b=_.di(a.flatMap(c=>c.drmInfos));return{keyId:a[a.length-1].keyId,type:VJ,drmInfos:b}},mL=function(a,b){return kL(a).map(c=>lL(c.ha,b)).filter(Boolean)},kL=function(a){return a.filter(b=>dK(b.ha,JJ))},lL=function(a,b){a=aK(a,JJ).filter(d=>"AES-128"!==WJ(d,QJ));if(0===a.length)return null;var c=WJ(a[0],QJ);if(1===a.length&&"NONE"===c)return iL();c=a.map(d=>WJ(d,QJ));if(!c.every(d=>"SAMPLE-AES"===d)&&!c.every(d=>d===RJ))throw nL.warn(`EXT-X-KEY methods ${c.join(", ")} are incompatible.`),
new _.I(_.G,4,4044,"Multiple EXT-X-KEY tags with incompatible METHOD values.");a=a.map(d=>{const e=_.J(d,"KEYFORMAT","identity");{const f=oL[e]||null;d=f?f(d,b):null}d||nL.warn("Unsupported HLS KEYFORMAT",e);return d}).filter(Boolean);if(0===a.length)throw new _.I(_.G,4,4026);return{keyId:a.map(d=>d.keyIds).reduce((d,e)=>d.concat(e),[]).reverse()[0]||null,type:VJ,drmInfos:a}},iL=function(){return{type:_.Be,drmInfos:[],keyId:null}},pL=function(a,b,c){a=aK(a,JJ)[0];if(!a||"AES-128"!==WJ(a,QJ))return null;
var d=_.J(a,"IV","");d?c={iv:_.Kl((d||"0x").slice(2)),generatedIv:!1}:(d=_.J(a,"KEYFORMAT"),c=null==d||"identity"===d?{iv:_.Nl(new Uint8Array(12),XK(c)),generatedIv:!0}:{iv:null,generatedIv:!1});const {iv:e,generatedIv:f}=c;return{method:"AES-128",url:gK(b,WJ(a,_.tb)),iv:e,generatedIv:f}},qL=function(a,b,c){return _.x(function*(){const d=b.f(),e=_.YC(b.Ya(),b.ya,b.ya+2048-1,a.a.attemptParameters);e.type=2;const f=_.YC(b.Ya(),b.ya,b.pa,a.a.attemptParameters);f.type=2;d&&(f.keyInfo=d);try{return yield a.f(c?
f:e)}catch(g){if(7001===g.code||c)throw g;a.g.warn("Unable to fetch a partial HLS segment! Falling back to a full segment request, which is expensive! Your server should support Range requests and CORS pre-flights.",e.uris[0]);try{return yield a.f(f)}catch(h){throw a.g.error("Failed to fetch media segment to parse its start timestamp.",f.uris[0],h),new _.I(_.G,4,4030,"Failed to fetch the media segment.");}}})},rL=function(a,b,c,d,e,f){return _.x(function*(){a.g.debug("Fetching segment to find start time");
if("audio/mpeg"===d||d===_.Ec||d===_.Dc)return 0;if(d===_.Ac){var g=yield qL(a,c,f);g=_.K(g.data);if(!YK(g))throw new _.I(_.G,4,4030,"AAC segment does not contain an ID3 tag.");return ZK(g)}if(d===_.pg||d===_.Fc)return g=[qL(a,c,f)],b&&g.push(qL(a,b,!0)),g=yield Promise.all(g),$K(g[0].data,(g[1]||g[0]).data);if(d===_.og)return g=yield qL(a,c,f),bL(g.data);if(!_.Ds(`${d.split("/")[0]||""}/mp4;codecs="${e}"`))return 0;throw new _.I(_.G,4,4030);})},sL=function(a,b){a=a.map(c=>c.streams[b]);return a.some(c=>
null==c)?null:a},tL=function(a,b){a=a.streams.find(c=>{c=c.U;return c[0].position<=b&&b<=c[c.length-1].position});return null==a?null:a.U.find(c=>c.position===b)||null},zK=function(a){return a.streams[0]},uL=function(a,b){a.streams.forEach(c=>{c.re=b})},vL=function(a,b){a.streams.forEach(c=>{c.width=b})},wL=function(a,b){a.streams.forEach(c=>{c.height=b})},xL=function(a,b){a.streams.forEach(c=>{c.frameRate=b})},yL=function(a,b){a.streams.forEach(c=>{c.bandwidth=b})},zL=function(a,b){a=a.map(c=>c.a[b]);
return a.some(c=>null==c)?null:a},AL=function(a,b){const c=new Set(a.map(d=>d.oa));return b.filter(d=>!c.has(d.oa))},CL=function(a,b){for(;a[0].oa<b[0].oa;)a.splice(0,1);var c=a[0];let d=b[0];c.startTime===d.startTime&&c.endTime===d.endTime||BL(c,d);const e=a.length-1;c=a[e];d=b[e];0<e&&(c.startTime!==d.startTime||c.endTime!==d.endTime)&&BL(c,d);for(c=e+1;c<b.length;)a.push(b[c]),c++},HL=function(a,b,c,d,e){var f=b[0].length();f=WK(f).map(g=>{var h=zL(b,g)||[];const k=sL(c,g)||[];g=sL(d,g)||[];{const l=
[...DL(h),...k,...g].filter(Boolean);EL(l);const {oa:m,duration:n}=l[0];h={configurationId:a,variants:h,textStreams:k,thumbStreams:g,startTime:0,id:`P${m}`,endTime:n,duration:n,oa:m}}return h});e&&FL(f[0]);GL(f);return f},DL=function(a){a=new Set(a.flatMap(b=>[b.video,b.audio]).filter(Boolean));return Array.from(a)},FL=function(a){const b=DL(a.variants)[0].U[0].Ca;a.startTime+=b;a.endTime+=b},GL=function(a){for(let b=0;b<a.length;b++){const c=a[b],d=a[b-1];c.startTime=d?d.endTime:c.startTime;c.endTime=
c.startTime+c.duration}},BL=function(a,b){a.startTime=b.startTime;a.endTime=b.endTime;a.duration=b.duration;IL(a.variants,b.variants);JL(hK(a),hK(b))},IL=function(a,b){const c=new Map(a.map(d=>[xK(d),d]));b.forEach(d=>{c.get(xK(d)).drmInfos=d.drmInfos})},JL=function(a,b){const c=new Map(a.map(d=>[d.Da,d]));b.forEach(d=>{const e=c.get(d.Da);e.U=d.U;d.U.forEach(f=>{f.initSegment=e.initSegmentReference});e.segmentIndex.replace(d.U);e.Uc=d.Uc;e.Ke=d.Ke;e.duration=d.duration;e.Sf=d.Sf;e.encrypted=d.encrypted;
e.drmInfos=d.drmInfos;e.keyId=d.keyId})},EL=function(a){const b=KL(a);a.forEach(c=>{_.UC(c.segmentIndex,b);c.duration=b;c.Ke=c.Uc+b})},KL=function(a){let b=Infinity;a.filter(kK).forEach(c=>{b=Math.min(b,c.duration)});return b},LL=function(a,b){iK(b,(c,d)=>{_.gD(a,c.U,d.startTime)});_.ZC(a.a,b[0].startTime,b[b.length-1].endTime)},ML=function(a){return null===a.o?[]:[a.o.audio,a.o.video].filter(b=>b).map(b=>b.Da)},NL=function(a,b){return _.x(function*(){var c=_.mj([b],a.a.attemptParameters);c.type=
1;c=yield a.H(c);let d="";try{d=_.Ui(c.data)}catch(e){throw new _.I(_.G,4,4042);}d=d.replace(/\r\n|\r(?=[^\n]|$)/gm,"\n");d=d.trim();return{text:d,response:c}})},YL=function(a,b){return _.x(function*(){var c=OL(a,b,a.w,"");if(1===c.type){var d=c.U[0].a;c=PL(d);if(!c)throw new _.I(_.G,4,4021,`Unknown file extension ${d}`);d="";c===_.w?d="avc1.42E01E":c===_.p&&(d="mp4a.40.2");c=UK(a.R,a.w,a.a.hlsDefaultCodecs||d)}d=sK(c.ha);c=QL(d.Bc.Ff);c.forEach(m=>{a.J.add(m.groupId)});var e=yield RL(a,d);var f=
e.Wh;const g=e.periods;var h=e.ki;const k=e.Hi;d=e.alternativeVariants;const l=e.alternativeTextStreams;e=e.alternativeImageStreams;if(!a.D)throw new _.I(_.G,7,7001);SL(a,g);h=TL(a,f.delay,g,h);UL(a)||(a.G=f.Ed,VL(a));WL(a,h,g);f=XL(a,k);c={presentationTimeline:h,periods:g,minBufferTime:0,cues:f,muxedAudioTracks:c};d&&(c.alternativeVariants=d);l&&(c.alternativeTextStreams=l);e&&(c.alternativeImageStreams=e);a.g.debug("HLS playlist parsed",c);return c})},$L=function(a,b){return Promise.all(b.map(c=>
ZL(a,c)))},bM=function(a,b){b.forEach(c=>{a:{var d=a.j.get(c.verbatimUri),e=!UL(a),f=eK(c.ha,"EXT-X-DISCONTINUITY-SEQUENCE");if(f)var g=Number(f.value);else{d?(f=d.streams[d.streams.length-1].U,f=f[f.length-1].oa):f=0;if(e&&0<f)try{{const k=eK(c.ha,MJ);if(!k)throw aM.error("Failed to infer discontinuity number, because EXT-X-MEDIA-SEQUENCE tag is missing."),Error(OJ);const l=Number(k.value),m=tL(d,l);if(!m)throw aM.error("Failed to infer discontinuity number, could not find the appropriate segment in the previous playlist"+
` (segment position = ${l})`),Error(OJ);var h=m.oa}g=h;break a}catch(k){throw new _.I(_.G,4,4024,"EXT-X-DISCONTINUITY-SEQUENCE tag is required for discontinuous HLS live streams.");}g=0}}c=c.U||[];for(const k of c)dK(k.ha,IJ)&&g++,k.oa=g});eL(b)},eM=function(a,b){return _.x(function*(){const {textStreams:c,thumbStreams:d,$g:e}=yield cM(a,b);var f=a.f.periods[0].variants;a.a.lowLatencyMode&&null!==a.o&&(f=f.filter(g=>g.id===a.o.id));f=f.map(g=>{const h=DK(g.audio,e),k=DK(g.video,e);g=dM(a,h,k,g.bandwidth);
if(!g)throw new _.I(_.G,4,4047,{message:"Video and audio are encrypted in an incompatible way.",oj:k?zK(k).Da:void 0,audio:h?zK(h).Da:void 0});return g});return HL(a.D.configurationId,f,c,d,!0)})},SL=function(a,b){UL(a)||2!==a.a.timeline.version||(a.I||(a.I=b[0].startTime),_.qE(b,-a.I))},fM=function(a,b){b=b.flatMap(d=>d.U[0].ha);b=eK(b,"EXT-X-PROGRAM-DATE-TIME");if(!b)return null;const c=(new Date(b.value)).getTime();return isNaN(c)?(a.g.warn("Failed to parse EXT-X-PROGRAM-DATE-TIME tag "+`value (value: ${b.value}).`),
null):c/1E3},gM=function(a,b,c){b=b.find(d=>null!==eK(d.ha,HJ));if(!b)return[];if(null===c)throw new _.I(_.G,4,4024,"EXT-X-PROGRAM-DATE-TIME tag is required when EXT-X-DATERANGE tags are present");return b.ha.filter(d=>d.name===HJ).map(d=>{a:{var e=a.C,f=!UL(a),g=_.J(d,"ID"),h=_.J(d,"START-DATE");if(null===g||null===h)_.ju.warn("Invalid  EXT-X-DATERANGE missing mandatory ID or START-DATE attribute, ignoring the EXT-X-DATERANGE tag.",d),d=null;else{e=f?e-c:-c;var k=new Date(h);f=k.getTime()/1E3+e;
g={id:g,startTime:f,startDate:k,oe:h};h=$J(_.J(d,GJ));void 0!==h&&0<=h&&(g.duration=h);var l=$J(_.J(d,"PLANNED-DURATION"));void 0!==l&&0<=l&&(g.plannedDuration=l);var m=_.J(d,"CLASS");null!==m&&(g.schemeIdUri=m);var n=_.J(d,"END-DATE");n=n?new Date(n):null;null!==n&&n.getTime()>=k.getTime()&&(g.endDate=n);{const v=d.attributes;if(null==v)var r=null;else{k={};for(r of v)r.name.trim().startsWith("X-")&&(k[r.name]=r.value);r=_.Zg(k)?k:null}}r=r||{};(k=_.J(d,"CUE"))&&(r.CUE=k.split(","));if(_.zi(m)){k=
d.attributes;if(null==k)var u=null;else{m={};for(u of k)switch(u.name){case _.Kb:m[_.Kb]=u.value;break;case _.Jb:m[_.Jb]=u.value;break;case _.Nb:m[_.Nb]=$J(u.value);break;case _.Lb:m[_.Lb]=$J(u.value);break;case "X-SNAP":m["X-SNAP"]=u.value.split(",");break;case _.Mb:m[_.Mb]=u.value.split(",")}m[_.Kb]&&m[_.Jb]||!m[_.Kb]&&!m[_.Jb]?(_.ju.warn("Invalid EXT-X-DATERANGE Interstitial attributes X-ASSET-URI, X-ASSET-LIST"),u=null):u=_.Zg(m)?m:null}if(null===u){_.ju.warn("Invalid interstitial attributes, ignoring the EXT-X-DATERANGE tag.",
d);d=null;break a}r=Object.assign(r,u)}_.Zg(r)&&(g.customAttributes=r);g.endTime=n?n.getTime()/1E3+e:h?f+h:l?f+l:f;g.type=_.Qh;d=g}}return d}).filter(Boolean)},XL=function(a,b){const c=new Set(b.map(d=>d.id));a.B.forEach((d,e)=>{c.has(e)||a.B.delete(e)});for(const d of b){if((b=a.B.get(d.id))&&b.oe!==d.oe)a.D.onError(new _.I(1,4,4044,"EXT-X-DATERANGE START-DATE has changed for"+` ID=${d.id}`));const e={configurationId:a.D.configurationId,schemeIdUri:d.schemeIdUri,customAttributes:d.customAttributes,
value:"",startTime:d.startTime,oe:d.oe,endTime:d.endTime,id:d.id,type:_.Qh,eventElement:null};b&&!ZJ(b,e)||a.B.set(d.id,e)}return Array.from(a.B.values())},hM=function(a,b,c){a.A=_.Cb;_.cD(b,!0);b.f=c[c.length-1].endTime},OL=function(a,b,c,d){a=QK(a.R,b,c);a.verbatimUri=d;return a},QL=function(a){return a.filter(b=>b.name===LJ&&_.J(b,_.rb)===_.rB&&!_.J(b,_.tb)).map(b=>{const c=EK(b),d=_.J(b,_.Ka)||_.dg;return{groupId:WJ(b,_.Ea),id:_.oJ++,label:WJ(b,_.Sa),language:d,channelsCount:c,primary:"YES"===
_.J(b,"DEFAULT")}})},RL=function(a,b){return _.x(function*(){var c=BK(b.Bc.closedCaptions),d=iM(a,b.Gd),e=yield jM(a,b),f=Object.values(e).flat().map(h=>h.playlist);bM(a,f);f=f[0];var g=lK(f.ha);a.A=g;a.K=qK(f.ha);f=yK(f.ha,g,a.a.lowLatencyMode||!1,a.a.suggestedPresentationDelay,a.a.liveRefreshPeriod);g=yield kM(a,e.Gf,d);c=yield lM(a,e.Gd,g,c);d=yield mM(a,e.Ei,d);g=yield nM(a,e.Fe);d=HL(a.D.configurationId,c,d,g,!UL(a));a.D.filterAllPeriods(d);c=[...e.Gd,...e.Gf].map(h=>h.playlist);e=fM(a,c);c=
gM(a,c,e);return{periods:d,ki:e,Hi:c,Wh:f}})},TL=function(a,b,c,d){let e=!0,f=null,g=0;UL(a)||(e=!1,f=0,g=b);b=a.a.timeline||{};b.type=void 0;a=new _.rJ(b,f,g,!0,void 0,!!a.a.lowLatencyMode);_.cD(a,e);LL(a,c);d&&_.bD(a,d);return a},VL=function(a){var b=0;for(var c of a.j.values())b=Math.max(b,c.streams[0].Uc);for(c=0;95443.7176888889<=b;)c+=95443.7176888889,b-=95443.7176888889;if(c){a.g.debug("Offsetting live streams by",c,"to compensate for rollover");for(const d of a.j.values())b=d.streams[0],95443.7176888889>
b.Uc?(a.g.debug("Offset applied to",b.type),b.segmentIndex.offset(c)):a.g.debug("Offset NOT applied to",b.type)}},WL=function(a,b,c){c=wK(c);"LIVE"===a.A||"EVENT"===a.A?(c=Math.max(c,b.J),isNaN(a.a.availabilityWindowOverride)||(c=a.a.availabilityWindowOverride),b.A=c):a.A===_.Cb&&(b.f=c)},cM=function(a,b){return _.x(function*(){const c=g=>zK(g.stream).type===_.w||zK(g.stream).type===_.p;var d=b.filter(c),e=b.filter(g=>!c(g)),f=g=>{g=g.map(h=>{var k=zK(h.stream);k={language:k.language,channelsCount:k.channelsCount,
spatialAudio:k.spatialAudio,closedCaptions:k.closedCaptions,primary:k.primary,kind:k.kind||null,groupId:k.groupId,type:k.type,codecs:k.codecs,name:k.originalId,uri:k.Da,Hd:{width:k.width,height:k.height,frameRate:k.frameRate}};h=Object.assign({},{playlist:h.playlist},k);return oM(a,h)});return Promise.all(g)};d=yield f(d);f=yield f(e);pM(a,d.concat(f));e=f.filter(g=>zK(g).type===_.XB);f=f.filter(g=>zK(g).type===_.be);return{textStreams:e,thumbStreams:f,$g:d}})},dM=function(a,b,c,d,e){const f=[],g=
(c||b).length();for(let n=0;n<g;n++){var h=b?b.streams[n]||null:null,k=c?c.streams[n]||null:null,l=h,m=k;l=l&&m?_.wC(l.drmInfos,m.drmInfos)?_.vC(l.drmInfos,m.drmInfos):null:l?l.drmInfos:m?m.drmInfos:null;if(!l)return null;m=d;h={id:e?e:a.h++,language:h?h.language:_.dg,primary:!!h&&h.primary||!!k&&k.primary,audio:h,video:k,bandwidth:m,drmInfos:l,allowedByApplication:!0,allowedByKeySystem:!0};f.push(h)}return new qM(f)},oM=function(a,b){return _.x(function*(){const c=b.playlist,d=b.codecs,e=b.type,
f=b.Sc,g=b.hc,h=b.groupId,k=b.muxedAudioId,l=b.primary;var m=b.kind;const n=b.name,r=b.channelsCount,u=b.spatialAudio,v=b.closedCaptions,y=b.Hd,A=_.Bi(f||_.dg);if(1!==c.type)throw new _.I(_.G,4,4017);const D=yield rM(a,c,e,d),E=a.a.lowLatencyMode?_.OB:_.NB;let X=m;e!==_.H||m||(X=_.XB);const cd=lK(c.ha);m=D.map(gc=>{const Ob=gc.U,Vd=gc.mh,Pb=gc.mimeType,hc=gc.oa,ic=Ob[0].startTime,Gb=Ob[Ob.length-1].endTime,hb=Gb-ic,ua=new _.sJ(Ob),zb=Ob[0].initSegment||null;return{id:null===g?_.oJ++:g,originalId:n,
createSegmentIndex:Promise.resolve.bind(Promise),findSegmentPosition:ua.f.bind(ua),getSegmentReference:ua.get.bind(ua),adjustSegmentDurations:ua.h.bind(ua),getDuration:ua.getDuration.bind(ua),segmentIndex:ua,segmentLookupStrategy:E,initSegmentReference:zb,mimeType:Pb,codecs:d,kind:X,Sf:Vd.type,encrypted:Vd.type===VJ,aesEncrypted:gc.aesEncrypted,keyId:Vd.keyId,language:A,originalLanguage:f||_.dg,label:n,type:e,primary:l,trickModeVideo:null,emsgSchemeIdUris:null,frameRate:y?y.frameRate:void 0,width:y?
y.width:void 0,height:y?y.height:void 0,bandwidth:void 0,roles:[],channelsCount:r,spatialAudio:u,closedCaptions:v,U:Ob,drmInfos:Vd.drmInfos,oa:hc,Da:c.verbatimUri,re:c.a,Uc:ic,Ke:Gb,duration:hb,groupId:h,hj:cd,muxedAudioId:k}});return new sM(m)})},pM=function(a,b){b.forEach(c=>{a.j.a.set(zK(c).Da,c)})},iM=function(a,b){const c=new Map;for(const f of b){var d=_.J(f,_.rB);b=_.J(f,_.Bb);var e=_.J(f,SJ);const g=tM(a,f);if(e){const h=_.Yj(_.H,g);c.set(`${_.H}:${e}`,h);e=g.indexOf(h);-1<e&&g.splice(e,1)}d&&
(e=uM(_.p,g),c.set(`${"audio"}:${d}`,e));b&&(d=uM(_.w,g),c.set(`${"video"}:${b}`,d))}return c},jM=function(a,b){return _.x(function*(){const c=yield Promise.all([vM(a,b.Bc.Ff),vM(a,b.Bc.Fi),vM(a,b.Gd),vM(a,b.Fe)]),[d,e,f,g]=c;return{Gf:d,Ei:e,Gd:f,Fe:g}})},kM=function(a,b,c){return _.x(function*(){if(0===b.length)return new Map;var d=[wM(a,b[0],c)];yield d[0];d=d.concat(b.slice(1).map(e=>wM(a,e,c)));d=yield Promise.all(d);return AK(d)})},lM=function(a,b,c,d){return _.x(function*(){const e=new Set;
var f=[...b];let g=0;var h=Infinity;for(let k=0;k<f.length;++k){const l=Number(WJ(f[k].tag,_.la));l<h&&(h=l,g=k)}h=f.splice(g,1).pop();h=yield xM(a,h,c,d,e);f=f.map(k=>xM(a,k,c,d,e));f=yield Promise.all(f);f.splice(g,0,h);return f.reduce(_.nC,[])})},mM=function(a,b,c){return Promise.all(b.map(d=>wM(a,d,c)))},nM=function(a,b){return Promise.all(b.map(c=>yM(a,c)))},zM=function(a,b){return _.x(function*(){const c=gK(a.w,b.verbatimUri),{response:d,text:e}=yield NL(a,c);return OL(a,e,d.uri,b.verbatimUri)})},
AM=function(a,b,c){return _.x(function*(){const d=yield oM(a,{playlist:c,codecs:b.codecs,type:b.type,Sc:b.originalLanguage,hc:b.id,groupId:b.groupId,primary:b.primary,kind:b.kind||null,name:b.label,channelsCount:b.channelsCount,spatialAudio:b.spatialAudio||!1,closedCaptions:b.closedCaptions,Hd:{width:b.width,height:b.height,frameRate:b.frameRate}});b.bandwidth&&yL(d,b.bandwidth);return d})},UL=function(a){return a.A===_.Cb},vM=function(a,b){return _.x(function*(){return(yield Promise.all(b.map(c=>
_.x(function*(){const d=yield BM(a,c);return d?{tag:c,playlist:d}:null})))).filter(Boolean)})},ZL=function(a,b){return _.x(function*(){var c=new _.mi(zK(b).re);if(a.a.lowLatencyMode&&a.K&&a.K.Kf){var d=b.streams[b.streams.length-1].segmentIndex;if(d=d.a[d.a.length-1]){var e=d.a,f=e.length-1;d={Xh:d.position,di:e&&0<e.length?f:null}}else d=null;if(e=d)d=e.Xh,e=e.di,f=_.Mj(c.a.toString()),f._HLS_msn=d.toString(),null===e&&f._HLS_part&&delete f._HLS_part,null!==e&&(f._HLS_part=e.toString()),d=_.Lj(f,
!0),d=new _.ti(d),_.pi(c,d)}const {response:g,text:h}=yield NL(a,c.toString());c=zK(b).Da;d=zK(b).re;e=g.uri;d!==e&&(d=e,uL(b,d));c=OL(a,h,d,c);return{stream:b,playlist:c}})},tM=function(a,b){var c=_.J(b,_.oa,a.a.hlsDefaultCodecs||"avc1.42E01E,mp4a.40.2").split(/\s*,\s*/);c=CK(c);b=new Set;const d=[];for(const e of c)c=_.CC(e),b.has(c)?a.g.debug("Ignoring duplicate codec"):(d.push(e),b.add(c));return d},uM=function(a,b){if(1===b.length)return b[0];a=_.Yj(a,b);if(null!=a)return a;throw new _.I(_.G,
4,4025,{codecList:b});},wM=function(a,b,c){return _.x(function*(){const d=b.tag,e=b.playlist;return CM(a,e.verbatimUri,()=>_.x(function*(){const f=WJ(d,_.Ea),g=mK(WJ(d,_.rb));var h=WJ(d,_.rb).toUpperCase();if(mK(h)!==_.H)h=null;else{var k=d.getAttribute("FORCED");k=!(!k||!k.value||"YES"!==k.value.toUpperCase());var l=_.XB;h===EJ&&(l=_.JB);k&&(l=_.Ud);h=l}k=c.get(`${g}:${f}`)||"";l=_.J(d,_.Ka);const m=_.J(d,_.Sa),n=_.J(d,"DEFAULT"),r=g===_.p?EK(d):null;var u=g===_.p?(u=_.J(d,"CHANNELS"))?u.includes("/JOC"):
!1:!1;return yield oM(a,{playlist:e,codecs:k,type:g,Sc:l,primary:"YES"===n,name:m,channelsCount:r,spatialAudio:u,groupId:f,kind:h,hc:null,closedCaptions:null,Hd:null})}))})},yM=function(a,b){return _.x(function*(){const c=b.tag,d=b.playlist;return CM(a,d.verbatimUri,()=>_.x(function*(){var e=_.J(c,_.oa)||"jpg",f=_.J(c,_.Ka);const g=_.J(c,_.Sa);e=yield oM(a,{playlist:d,codecs:e,type:_.be,Sc:f,name:g,primary:!1,kind:null,channelsCount:null,spatialAudio:!1,closedCaptions:null,hc:null,groupId:null,Hd:null});
(f=_.J(c,_.la))&&yL(e,Number(f));return e}))})},xM=function(a,b,c,d,e){return _.x(function*(){var f=b.tag,g=Number(WJ(f,_.la));if(f.hasAttribute("FRAME-RATE")||f.hasAttribute(_.kb)){var h=_.J(f,"FRAME-RATE");f=_.J(f,_.kb);var [k,l]=f?f.split("x"):[null,null];h={frameRate:$J(h),width:$J(k),height:$J(l)}}else h=null;if(f=yield DM(a,b,h,c,d)){h=f.video;f=f.audio;var m=0<f.length?f:[null];h=0<h.length?h:[null];f=[];for(const n of m)for(const r of h){m=(r?zK(r).Da:"")+" - "+(n?zK(n).Da:"");if(e.has(m)){a.g.debug("Skipping variant which only differs in text streams.");
continue}const u=dM(a,n,r,g);null==u?a.g.warn("Incompatible DRM info in HLS variant. Skipping."):(f.push(u),e.add(m))}g=f}else g=[];return g})},EM=function(a,b,c,d,e,f){let g=tM(a,b);a.g.debug("Guessing stream type for",b.toString());b=!1;const h=_.Yj(_.w,g),k=d+e;1!==g.length||c||h?!k&&1<g.length?(a.g.debug("Guessing multiplexed audio+video"),c=_.w,g=[g.join(",")]):d&&f?(a.g.debug(PJ),c=_.p,b=!0):e?(a.g.debug(PJ),c=_.p):(a.g.debug("Guessing video-only"),c=_.w):(c=_.p,a.g.debug(PJ));return{type:c,
Yg:g,Nh:b}},CM=function(a,b,c){if(a.j.has(b))return a=a.j.get(b),Promise.resolve(a);if(a.j.f.has(b))return a.j.f.get(b)||null;c=c();a.j.set(b,c);return c},DM=function(a,b,c,d,e){return _.x(function*(){var f=b.tag,g=b.playlist,h=_.J(f,_.rB),k=_.J(f,_.Bb);h=h?d.get(`${"audio"}:${h}`)||[]:[];k=k?d.get(`${"video"}:${k}`)||[]:[];k={audio:h,video:k};const l=g.verbatimUri;g=k.audio.find(u=>zK(u).Da===l);const {type:m,Yg:n,Nh:r}=EM(a,f,c,k.audio.length,k.video.length,g);f=null;r||(f=yield FM(a,b,n,m,e,c));
if(null==f)return null;k[m]=[f];m===_.p&&c&&k.video.forEach(u=>{vL(u,c.width);wL(u,c.height);xL(u,c.frameRate)});return k})},FM=function(a,b,c,d,e,f){return _.x(function*(){const g=b.tag,h=b.playlist;return CM(a,h.verbatimUri,()=>_.x(function*(){var k=_.J(g,EJ);let l=null;d===_.w&&k&&"NONE"!==k&&(l=e.get(k));k=(k=_.J(g,_.rB)||void 0)&&a.J.has(k)?k:void 0;var m=uM(d,c);if(k){const n=uM(_.p,c);m+=`,${n}`}return yield oM(a,{playlist:h,codecs:m,type:d,closedCaptions:l,primary:!1,kind:null,Sc:null,name:null,
channelsCount:null,spatialAudio:!1,hc:null,groupId:null,muxedAudioId:k,Hd:f})}))})},rM=function(a,b,c,d){return _.x(function*(){var e=b.verbatimUri,f=b.U;var g=void 0===g?0:g;var h=(h=eK(b.ha,MJ))?Number(h.value):g;g=[];e=yield GM(a,b.a,e,f,h,c,d);if(0===f.length)f=[];else{var k=[],l=[];for(var m of f)dK(m.ha,IJ)&&0<l.length&&(k.push(l),l=[]),l.push(m);k.push(l);f=k}for(m=0;m<f.length;m++)k=f[m],l=yield HM(a,b.a,k,h,e,c,d,g[g.length-1]||null),g.push(l),h+=k.length;IM(g);return g})},BM=function(a,
b){return _.x(function*(){var c=b.name!==LJ?!0:_.J(b,_.rb)===SJ;c=_.J(b,_.tb,void 0,{required:c});if(!c)return null;const d=gK(a.w,c),e=Date.now(),{response:f,text:g}=yield NL(a,d);a.D.onEvent(new _.F(UJ,{detail:{duration:Date.now()-e,type:"media"}}));return OL(a,g,f.uri,c)})},IM=function(a){if(1<(new Set(a.map(b=>b.mimeType))).size)throw new _.I(_.G,4,4045,"Media playlist contains discontinuities with different MIME types. This is valid, but not yet supported.");},JM=function(a){a=a.map(b=>b.a?b.a:
b.f.map(c=>_.J(c,_.tb))||null).map(b=>_.iu(b));if(1<(new Set(a)).size)throw new _.I(_.G,4,4044,"Unexpected change in file format.");},KM=function(a,b,c){a=aK(a.ha,KJ);if(1<a.length)throw new _.I(_.G,4,4020);a=a[0];if(!a)return null;const d=WJ(a,_.tb),e=gK(b,d);b=rK(a,null,!0);return new _.nJ(()=>[e],b.ya,b.pa,c)},LM=function(a,b,c,d,e,f,g){const h=[];for(const r of VK(b.f)){b=r.eg;const u=r.item;{var k=0===b,l=k?a:h[h.length-1],m=k?d:l.endTime,n=Number(_.J(u,GJ));n=m+n;k=rK(u,k?null:l.pa,k);l=_.J(u,
_.tb);const v=(l=gK(g,l))?[l]:[];m=new tK(c,m,n,()=>v,k.ya,k.pa,e,f,!1,null,null,null,null);if("YES"===_.J(u,"INDEPENDENT")||0===b)m.h=!0;h.push(m)}}return h},MM=function(a,b,c,d,e,f,g,h,k,l,m){const n=c.ha;var r=c.a;0<aK(n,KJ).length&&(m=KM(c,k,g));const u=null!=r,v=r?[r]:[];if(!u&&!a.a.lowLatencyMode)return null;a=0;r={ya:0,pa:null};let y=null;u?({duration:c}=pK(n),a=e+c,r=oK(n,b?b.pa:null)):(b=LM(b,c,d,e,f,g,k),a=b[b.length-1].endTime,y=b);h=h===_.be?fK(n):null;d=new tK(d,e,a,()=>v,r.ya,r.pa,f,
g,!1,null,h?h.ld:null,h?h.Fd:null,h?h.durationPerTile:null,y,m);d.oa=l;return d},GM=function(a,b,c,d,e,f,g){return _.x(function*(){var h=d[0];if(null!=a.C)return a.C;if(!UL(a)&&a.f)try{var k=a.j.get(c);var l=k?tL(k,e)||null:null;if(!l)throw new _.I(_.G,4,4030,"Segment not found in pervious playlist update.");var m=l.startTime+l.Ca;a.g.debug(`Setting playlist start time to ${m}.`);return a.C=m}catch(n){if(h=a.j.get(c))m=h.streams[h.streams.length-1].U,m=m[m.length-1],a.g.warn(`Last #EXT-X-MEDIA-SEQUENCE values ${h.streams[0].U[0].position} - ${m.position}`+
`, new values ${e} - ${e+d.length-1}.`,b,h);throw new _.I(_.G,4,4047,{message:"The updated playlist does not share any segments with the previous one.",uri:c});}m=yield NM(a,f,g,h);l=pL(h.ha,a.w,e);k=KM(h,b,l);h=yield OM(a,k,h,l,m,g);a.g.debug(`Setting playlist start time to ${h}.`);return a.C=h})},HM=function(a,b,c,d,e,f,g,h){return _.x(function*(){var k=c[0],l=null==h;JM(c);const m=yield NM(a,f,g,k);var n=h?h.Uh:null;if(dK(c[0].ha,JJ)||null===n)n=mL(c,m),n=0===n.length?[iL()]:n;else{var r=mL(c,
m);n=[n,...r]}r=n;n=r[r.length-1];r=jL(r);let u=h?h.Vh:null;var v=PM(u,k.ha,a.w,d);let y=KM(k,b,v)||(h?h.Oh:null);const A=k.oa;k=l?e:yield QM(a,A,y,k,d,v,m,g);l=[];v=!1;for(let E=0;E<c.length;E++){var D=c[E];const X=l[l.length-1]||null,cd=0===E?0:X.endTime,gc=d+E,Ob=PM(u,D.ha,a.w,gc);(u=Ob)&&(v=!0);if(D=MM(a,X,D,gc,cd,k,Ob,f,b,A,y))y=D.initSegment,l.push(D)}return{U:l,mh:r,Uh:n,aesEncrypted:v,mimeType:m,endTime:l[l.length-1].endTime,oa:A,Oh:y,Vh:u}})},NM=function(a,b,c,d){return _.x(function*(){const e=
d.a;var f=eK(d.ha,KJ);f=f?WJ(f,_.tb):null;return RM(a,b,c,e,f)})},OM=function(a,b,c,d,e,f){return _.x(function*(){if(null==c.a)return 0;const g=uK(c,d);return rL(a.S,b,g,e,f,null!=d)})},PM=function(a,b,c,d){return b.some(e=>e.name===JJ&&"NONE"===_.J(e,QJ))?null:(b=pL(b,c,d))?b:a&&a.generatedIv?Object.assign({},a,{iv:_.Nl(new Uint8Array(12),XK(d))}):a},QM=function(a,b,c,d,e,f,g,h){return _.x(function*(){if(a.L.has(b))return a.L.get(b);const k=yield OM(a,c,d,f,g,h);a.g.debug(`Segment #${e} has raw media timestamp `+
`${k} s.`);a.L.set(b,k);return k})},RM=function(a,b,c,d,e){return _.x(function*(){const f=[d,e].filter(Boolean);var g=_.bk(f,b,c);if(g)return g;g=_.mj([d],a.a.attemptParameters);g.method="HEAD";g.type=2;g=(yield a.H(g)).headers["content-type"];if(!g)throw new _.I(_.G,4,4021,"Unknown MIME type of: "+f.join(", "));return g.toLowerCase().split(";")[0]})},PL=a=>{a=_.iu(a)||"";return null!=_.hu.video[a]?_.w:null!=_.hu.audio[a]?_.p:null},KK=class{constructor(a,b,c,d){if(1===b){if(!d||0===d.length)throw new _.I(_.G,
4,4043,"Media playlist must have at least one segment!");if(null==d[0].a)throw new _.I(_.G,4,4043,"Media playlist must have at least one full segment!");}this.a=a;this.verbatimUri="";this.type=b;this.ha=c;this.U=1===b?d:null}},TK=class{constructor(a,b,c){c=void 0===c?[]:c;this.ha=b;this.a=a;this.f=c;this.oa=-1}},tK=class extends _.sD{constructor(a,b,c,d,e,f,g,h,k,l,m,n,r,u,v){u=void 0===u?[]:u;super(a,b,c,d,e,f,g,void 0===h?null:h,void 0===k?!1:k,void 0===l?null:l,void 0===m?null:m,void 0===n?null:
n,void 0===r?null:r,u,void 0===v?null:v);this.oa=0}},RK=/^#EXT-X-DEFINE/,SK=/^#(EXT-X-DISCONTINUITY-SEQUENCE|EXT-X-ENDLIST|EXT-X-I-FRAMES-ONLY|EXT-X-MEDIA-SEQUENCE|EXT-X-PART-INF|EXT-X-PLAYLIST-TYPE|EXT-X-SERVER-CONTROL|EXT-X-TARGETDURATION|EXT-X-DATERANGE|EXT-X-VERSION)/,SM=class{constructor(){this.h=0;this.a=new Map}},TM=class{constructor(){this.a=new Map;this.f=new Map}set(a,b){this.f.set(a,b);return b.then(c=>this.a.set(a,c)).catch(()=>{}).then(()=>this.f.delete(a))}has(a){return this.a.has(a)}get(a){return this.a.get(a)||
null}values(){return Array.from(this.a.values())}clear(){this.f.clear();this.a.clear()}},aM=new _.S("clpp.hls.DiscontinuityUtils");var oL={"com.apple.streamingkeydelivery":function(a,b){if(b===_.og)throw new _.I(_.G,4,4041);if(WJ(a,QJ)===RJ)throw new _.I(_.G,4,4044,"EXT-X-KEY:METHOD SAMPLE-AES-CTR is not supported in FairPlay.");return _.qC(_.pd,[{initDataType:_.Gf,initData:new Uint8Array(0)}],"")},"com.microsoft.playready":hL,"urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":hL,"urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":function(a){var b=WJ(a,QJ);if(!fL.includes(b))return gL.error("Widevine in HLS is only supported with [",
fL.join(", "),"], not",b),null;b=WJ(a,_.tb);b=_.vt(b);b=_.K(b.data);b=_.qC(_.td,[{initDataType:_.Tc,initData:b}],"");if(a=_.J(a,"KEYID"))b.keyIds=[a.substr(2).toLowerCase()];return b}},fL=["SAMPLE-AES",RJ],gL=new _.S("clpp.hls.DrmParser");var nL=new _.S("clpp.hls.EncryptionUtils");var UM=class{constructor(a){this.g=new _.S("clpp.hls.MediaReader");this.f=a;this.a={attemptParameters:_.ij()}}};var sM=class{constructor(a){this.streams=a}length(){return this.streams.length}};var qM=class{constructor(a){this.a=a}length(){return this.a.length}};var VM=class{constructor(){this.a=this.D=null;this.h=1;this.j=new TM;this.w="";this.R=new SM;this.G=0;this.o=null;this.l=new _.rk(()=>{this.Vb()});this.A=_.Cb;this.f=null;this.F=new _.lu;this.K=this.C=null;this.g=new _.S("clpp.hls.HlsParser");this.L=new Map;this.S=new UM(this.H.bind(this));this.P=!1;this.I=null;this.M=!1;this.B=new Map;this.J=new Set}configure(a){this.a=a;this.S.a=a}setCurrentVariant(a){this.o=a}start(a,b){const c=this;return _.x(function*(){if(c.P)throw Error("start() may be called only once!");
c.P=!0;c.D=b;var d=Date.now();const {response:e,text:f}=yield NL(c,a);c.D.onEvent(new _.F(UJ,{detail:{duration:Date.now()-d,type:"master"}}));c.w=e.uri;d=yield YL(c,f);c.f=d;const g=c.G;c.l&&0<g&&c.l.ka(g);return d})}requestStop(){this.M=!0}stop(){this.l&&(this.l.stop(),this.l=null);const a=[];this.F&&(a.push(this.F.destroy()),this.F=null);this.j.clear();this.f=this.a=this.D=this.o=null;this.B.clear();this.J.clear();return Promise.all(a)}update(){const a=this;return _.x(function*(){const b=a.f;if(!UL(a)&&
b){var c=b.presentationTimeline;"LIVE"===a.A&&(a.C=null);var d=Array.from(a.j.values());if(a.a.lowLatencyMode&&null!==a.o){const g=ML(a);d=d.filter(h=>g.includes(zK(h).Da))}var e=yield $L(a,d);d=e.map(g=>g.playlist);bM(a,d);e=yield eM(a,e);AL(b.periods,e).forEach(g=>{a.D.filterNewPeriod(g)});SL(a,e);var f=fM(a,d);f=gM(a,d,f);b.cues=XL(a,f);CL(b.periods,e);LL(c,e);if(d=jK(d))!0!==a.a.keepTimelineLive&&hM(a,c,e),a.l.stop(),a.l=null;if(a.D.onUpdate)a.D.onUpdate(b);if(d&&a.D.onTurnedStatic)a.D.onTurnedStatic();
a.M&&(yield a.stop());return b}})}loadVariant(a,b){const c=this;return _.x(function*(){const d=a.id;var e=c.f.periods.find(k=>k.id===b);if(e&&(e=e.variants.find(k=>k.id===d)))return e;e=c.f.alternativeVariants.find(k=>k.id===d);if(!e)throw new _.ji(`No alternative variant with id: ${d}`);var f=null,g=null;if(e.audio){const k=e.audio;f=CM(c,k.verbatimUri,()=>_.x(function*(){const l=yield zM(c,k);return AM(c,k,l)}))}if(e.video){const k=e.video;g=CM(c,k.verbatimUri,()=>_.x(function*(){const l=yield zM(c,
k);return AM(c,k,l)}))}f=yield f;g=yield g;e=dM(c,f,g,e.bandwidth,e.id);let h;e&&(e=HL(c.D.configurationId,[e],[],[],!UL(c)),c.D.filterAllPeriods(e),e.forEach((k,l)=>{c.f.periods[l].variants.push(k.variants[0]);b===c.f.periods[l].id&&(h=k.variants[0])}));if(!h)throw new _.ji(`Could load variant with id: ${d}`);return h})}loadTextStream(a,b){const c=this;return _.x(function*(){let d;var e=c.f.periods.find(f=>f.id===b);e&&(e=e.textStreams.find(f=>f.id===a)||null)&&(d=e);if(!d&&c.f.alternativeTextStreams){const f=
c.f.alternativeTextStreams.find(h=>h.id===a)||null;if(!f)throw new _.ji(`Could not load text stream with id: ${a}`);const g=yield CM(c,f.verbatimUri,()=>_.x(function*(){const h=yield zM(c,f);return AM(c,f,h)}));g&&c.f.periods.forEach((h,k)=>{h=g.streams[k];c.f.periods[k].textStreams.push(h);h.id===a&&(d=h)})}if(!d)throw new _.ji(`Could not load text stream with id: ${a}`);return d})}Vb(){const a=this;return _.x(function*(){a.g.debug(_.DB);if(a.D)try{yield a.update(),a.l&&0<a.G&&a.l.ka(a.G)}catch(b){if(!(b instanceof
_.I))throw b;a.D&&(a.D.onError(b),1===b.severity&&a.l&&a.l.ka(.1))}})}H(a){if(!this.F)throw new _.I(_.G,7,7001);a=this.D.networkingEngine.fetch(a);_.vj(this.F,a);return a.T}};_.z("clpp.hls.HlsComponent",class extends _.Av{f(){_.$s.m3u8=VM;_.Ys[_.kl]=VM;_.Ys[TJ]=VM}a(){_.RD("m3u8");_.SD(_.kl);_.SD(TJ)}id(){return"hls"}});};f.call(g, window);