UNPKG

@videojs/http-streaming

Version:

Play back HLS and DASH with Video.js, even where it's not natively supported

3 lines 320 kB
/*! @name @videojs/http-streaming @version 3.5.1 @license Apache-2.0 */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("video.js"),require("@xmldom/xmldom")):"function"==typeof define&&define.amd?define(["exports","video.js","@xmldom/xmldom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).httpStreaming={},e.videojs,e.window)}(this,(function(e,t,i){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=n(t),a={exports:{}};!function(e,t){!function(t){var i=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#[^]*)?$/,n=/^([^\/?#]*)([^]*)$/,s=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,r={buildAbsoluteURL:function(e,t,i){if(i=i||{},e=e.trim(),!(t=t.trim())){if(!i.alwaysNormalize)return e;var s=r.parseURL(e);if(!s)throw new Error("Error trying to parse base URL.");return s.path=r.normalizePath(s.path),r.buildURLFromParts(s)}var a=r.parseURL(t);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return i.alwaysNormalize?(a.path=r.normalizePath(a.path),r.buildURLFromParts(a)):t;var o=r.parseURL(e);if(!o)throw new Error("Error trying to parse base URL.");if(!o.netLoc&&o.path&&"/"!==o.path[0]){var d=n.exec(o.path);o.netLoc=d[1],o.path=d[2]}o.netLoc&&!o.path&&(o.path="/");var u={scheme:o.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(u.netLoc=o.netLoc,"/"!==a.path[0]))if(a.path){var l=o.path,h=l.substring(0,l.lastIndexOf("/")+1)+a.path;u.path=r.normalizePath(h)}else u.path=o.path,a.params||(u.params=o.params,a.query||(u.query=o.query));return null===u.path&&(u.path=i.alwaysNormalize?r.normalizePath(a.path):a.path),r.buildURLFromParts(u)},parseURL:function(e){var t=i.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(s,"");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=r}()}(a);var r=a.exports,o="http://example.com",d=function(e,t){if(/^[a-z]+:/i.test(t))return t;/^data:/.test(e)&&(e=window.location&&window.location.href||"");var i="function"==typeof window.URL,n=/^\/\//.test(e),s=!window.location&&!/\/\//i.test(e);if(i?e=new window.URL(e,window.location||o):/\/\//i.test(e)||(e=r.buildAbsoluteURL(window.location&&window.location.href||"",e)),i){var a=new URL(t,e);return s?a.href.slice(o.length):n?a.href.slice(a.protocol.length):a.href}return r.buildAbsoluteURL(e,t)};const u=d,l=(e,t)=>t&&t.responseURL&&e!==t.responseURL?t.responseURL:e,h=e=>s.default.log.debug?s.default.log.debug.bind(s.default,"VHS:",`${e} >`):function(){};function c(){return c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e},c.apply(this,arguments)}var p=function(){function e(){this.listeners={}}var t=e.prototype;return t.on=function(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)},t.off=function(e,t){if(!this.listeners[e])return!1;var i=this.listeners[e].indexOf(t);return this.listeners[e]=this.listeners[e].slice(0),this.listeners[e].splice(i,1),i>-1},t.trigger=function(e){var t=this.listeners[e];if(t)if(2===arguments.length)for(var i=t.length,n=0;n<i;++n)t[n].call(this,arguments[1]);else for(var s=Array.prototype.slice.call(arguments,1),a=t.length,r=0;r<a;++r)t[r].apply(this,s)},t.dispose=function(){this.listeners={}},t.pipe=function(e){this.on("data",(function(t){e.push(t)}))},e}();function m(e){for(var t,i=(t=e,window.atob?window.atob(t):Buffer.from(t,"base64").toString("binary")),n=new Uint8Array(i.length),s=0;s<i.length;s++)n[s]=i.charCodeAt(s);return n} /*! @name m3u8-parser @version 7.0.0 @license Apache-2.0 */class g extends p{constructor(){super(),this.buffer=""}push(e){let t;for(this.buffer+=e,t=this.buffer.indexOf("\n");t>-1;t=this.buffer.indexOf("\n"))this.trigger("data",this.buffer.substring(0,t)),this.buffer=this.buffer.substring(t+1)}}const f=String.fromCharCode(9),y=function(e){const t=/([0-9.]*)?@?([0-9.]*)?/.exec(e||""),i={};return t[1]&&(i.length=parseInt(t[1],10)),t[2]&&(i.offset=parseInt(t[2],10)),i},_=function(e){const t={};if(!e)return t;const i=e.split(new RegExp('(?:^|,)((?:[^=]*)=(?:"[^"]*"|[^,]*))'));let n,s=i.length;for(;s--;)""!==i[s]&&(n=/([^=]*)=(.*)/.exec(i[s]).slice(1),n[0]=n[0].replace(/^\s+|\s+$/g,""),n[1]=n[1].replace(/^\s+|\s+$/g,""),n[1]=n[1].replace(/^['"](.*)['"]$/g,"$1"),t[n[0]]=n[1]);return t};class T extends p{constructor(){super(),this.customParsers=[],this.tagMappers=[]}push(e){let t,i;0!==(e=e.trim()).length&&("#"===e[0]?this.tagMappers.reduce(((t,i)=>{const n=i(e);return n===e?t:t.concat([n])}),[e]).forEach((e=>{for(let t=0;t<this.customParsers.length;t++)if(this.customParsers[t].call(this,e))return;if(0===e.indexOf("#EXT"))if(e=e.replace("\r",""),t=/^#EXTM3U/.exec(e),t)this.trigger("data",{type:"tag",tagType:"m3u"});else{if(t=/^#EXTINF:([0-9\.]*)?,?(.*)?$/.exec(e),t)return i={type:"tag",tagType:"inf"},t[1]&&(i.duration=parseFloat(t[1])),t[2]&&(i.title=t[2]),void this.trigger("data",i);if(t=/^#EXT-X-TARGETDURATION:([0-9.]*)?/.exec(e),t)return i={type:"tag",tagType:"targetduration"},t[1]&&(i.duration=parseInt(t[1],10)),void this.trigger("data",i);if(t=/^#EXT-X-VERSION:([0-9.]*)?/.exec(e),t)return i={type:"tag",tagType:"version"},t[1]&&(i.version=parseInt(t[1],10)),void this.trigger("data",i);if(t=/^#EXT-X-MEDIA-SEQUENCE:(\-?[0-9.]*)?/.exec(e),t)return i={type:"tag",tagType:"media-sequence"},t[1]&&(i.number=parseInt(t[1],10)),void this.trigger("data",i);if(t=/^#EXT-X-DISCONTINUITY-SEQUENCE:(\-?[0-9.]*)?/.exec(e),t)return i={type:"tag",tagType:"discontinuity-sequence"},t[1]&&(i.number=parseInt(t[1],10)),void this.trigger("data",i);if(t=/^#EXT-X-PLAYLIST-TYPE:(.*)?$/.exec(e),t)return i={type:"tag",tagType:"playlist-type"},t[1]&&(i.playlistType=t[1]),void this.trigger("data",i);if(t=/^#EXT-X-BYTERANGE:(.*)?$/.exec(e),t)return i=c(y(t[1]),{type:"tag",tagType:"byterange"}),void this.trigger("data",i);if(t=/^#EXT-X-ALLOW-CACHE:(YES|NO)?/.exec(e),t)return i={type:"tag",tagType:"allow-cache"},t[1]&&(i.allowed=!/NO/.test(t[1])),void this.trigger("data",i);if(t=/^#EXT-X-MAP:(.*)$/.exec(e),t){if(i={type:"tag",tagType:"map"},t[1]){const e=_(t[1]);e.URI&&(i.uri=e.URI),e.BYTERANGE&&(i.byterange=y(e.BYTERANGE))}this.trigger("data",i)}else if(t=/^#EXT-X-STREAM-INF:(.*)$/.exec(e),t){if(i={type:"tag",tagType:"stream-inf"},t[1]){if(i.attributes=_(t[1]),i.attributes.RESOLUTION){const e=i.attributes.RESOLUTION.split("x"),t={};e[0]&&(t.width=parseInt(e[0],10)),e[1]&&(t.height=parseInt(e[1],10)),i.attributes.RESOLUTION=t}i.attributes.BANDWIDTH&&(i.attributes.BANDWIDTH=parseInt(i.attributes.BANDWIDTH,10)),i.attributes["FRAME-RATE"]&&(i.attributes["FRAME-RATE"]=parseFloat(i.attributes["FRAME-RATE"])),i.attributes["PROGRAM-ID"]&&(i.attributes["PROGRAM-ID"]=parseInt(i.attributes["PROGRAM-ID"],10))}this.trigger("data",i)}else{if(t=/^#EXT-X-MEDIA:(.*)$/.exec(e),t)return i={type:"tag",tagType:"media"},t[1]&&(i.attributes=_(t[1])),void this.trigger("data",i);if(t=/^#EXT-X-ENDLIST/.exec(e),t)this.trigger("data",{type:"tag",tagType:"endlist"});else if(t=/^#EXT-X-DISCONTINUITY/.exec(e),t)this.trigger("data",{type:"tag",tagType:"discontinuity"});else{if(t=/^#EXT-X-PROGRAM-DATE-TIME:(.*)$/.exec(e),t)return i={type:"tag",tagType:"program-date-time"},t[1]&&(i.dateTimeString=t[1]),void this.trigger("data",i);if(t=/^#EXT-X-KEY:(.*)$/.exec(e),t)return i={type:"tag",tagType:"key"},t[1]&&(i.attributes=_(t[1]),i.attributes.IV&&("0x"===i.attributes.IV.substring(0,2).toLowerCase()&&(i.attributes.IV=i.attributes.IV.substring(2)),i.attributes.IV=i.attributes.IV.match(/.{8}/g),i.attributes.IV[0]=parseInt(i.attributes.IV[0],16),i.attributes.IV[1]=parseInt(i.attributes.IV[1],16),i.attributes.IV[2]=parseInt(i.attributes.IV[2],16),i.attributes.IV[3]=parseInt(i.attributes.IV[3],16),i.attributes.IV=new Uint32Array(i.attributes.IV))),void this.trigger("data",i);if(t=/^#EXT-X-START:(.*)$/.exec(e),t)return i={type:"tag",tagType:"start"},t[1]&&(i.attributes=_(t[1]),i.attributes["TIME-OFFSET"]=parseFloat(i.attributes["TIME-OFFSET"]),i.attributes.PRECISE=/YES/.test(i.attributes.PRECISE)),void this.trigger("data",i);if(t=/^#EXT-X-CUE-OUT-CONT:(.*)?$/.exec(e),t)return i={type:"tag",tagType:"cue-out-cont"},t[1]?i.data=t[1]:i.data="",void this.trigger("data",i);if(t=/^#EXT-X-CUE-OUT:(.*)?$/.exec(e),t)return i={type:"tag",tagType:"cue-out"},t[1]?i.data=t[1]:i.data="",void this.trigger("data",i);if(t=/^#EXT-X-CUE-IN:(.*)?$/.exec(e),t)return i={type:"tag",tagType:"cue-in"},t[1]?i.data=t[1]:i.data="",void this.trigger("data",i);if(t=/^#EXT-X-SKIP:(.*)$/.exec(e),t&&t[1])return i={type:"tag",tagType:"skip"},i.attributes=_(t[1]),i.attributes.hasOwnProperty("SKIPPED-SEGMENTS")&&(i.attributes["SKIPPED-SEGMENTS"]=parseInt(i.attributes["SKIPPED-SEGMENTS"],10)),i.attributes.hasOwnProperty("RECENTLY-REMOVED-DATERANGES")&&(i.attributes["RECENTLY-REMOVED-DATERANGES"]=i.attributes["RECENTLY-REMOVED-DATERANGES"].split(f)),void this.trigger("data",i);if(t=/^#EXT-X-PART:(.*)$/.exec(e),t&&t[1])return i={type:"tag",tagType:"part"},i.attributes=_(t[1]),["DURATION"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=parseFloat(i.attributes[e]))})),["INDEPENDENT","GAP"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=/YES/.test(i.attributes[e]))})),i.attributes.hasOwnProperty("BYTERANGE")&&(i.attributes.byterange=y(i.attributes.BYTERANGE)),void this.trigger("data",i);if(t=/^#EXT-X-SERVER-CONTROL:(.*)$/.exec(e),t&&t[1])return i={type:"tag",tagType:"server-control"},i.attributes=_(t[1]),["CAN-SKIP-UNTIL","PART-HOLD-BACK","HOLD-BACK"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=parseFloat(i.attributes[e]))})),["CAN-SKIP-DATERANGES","CAN-BLOCK-RELOAD"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=/YES/.test(i.attributes[e]))})),void this.trigger("data",i);if(t=/^#EXT-X-PART-INF:(.*)$/.exec(e),t&&t[1])return i={type:"tag",tagType:"part-inf"},i.attributes=_(t[1]),["PART-TARGET"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=parseFloat(i.attributes[e]))})),void this.trigger("data",i);if(t=/^#EXT-X-PRELOAD-HINT:(.*)$/.exec(e),t&&t[1])return i={type:"tag",tagType:"preload-hint"},i.attributes=_(t[1]),["BYTERANGE-START","BYTERANGE-LENGTH"].forEach((function(e){if(i.attributes.hasOwnProperty(e)){i.attributes[e]=parseInt(i.attributes[e],10);const t="BYTERANGE-LENGTH"===e?"length":"offset";i.attributes.byterange=i.attributes.byterange||{},i.attributes.byterange[t]=i.attributes[e],delete i.attributes[e]}})),void this.trigger("data",i);if(t=/^#EXT-X-RENDITION-REPORT:(.*)$/.exec(e),t&&t[1])return i={type:"tag",tagType:"rendition-report"},i.attributes=_(t[1]),["LAST-MSN","LAST-PART"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=parseInt(i.attributes[e],10))})),void this.trigger("data",i);if(t=/^#EXT-X-DATERANGE:(.*)$/.exec(e),t&&t[1]){i={type:"tag",tagType:"daterange"},i.attributes=_(t[1]),["ID","CLASS"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=String(i.attributes[e]))})),["START-DATE","END-DATE"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=new Date(i.attributes[e]))})),["DURATION","PLANNED-DURATION"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=parseFloat(i.attributes[e]))})),["END-ON-NEXT"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=/YES/i.test(i.attributes[e]))})),["SCTE35-CMD"," SCTE35-OUT","SCTE35-IN"].forEach((function(e){i.attributes.hasOwnProperty(e)&&(i.attributes[e]=i.attributes[e].toString(16))}));const e=/^X-([A-Z]+-)+[A-Z]+$/;for(const t in i.attributes){if(!e.test(t))continue;const n=/[0-9A-Fa-f]{6}/g.test(i.attributes[t]),s=/^\d+(\.\d+)?$/.test(i.attributes[t]);i.attributes[t]=n?i.attributes[t].toString(16):s?parseFloat(i.attributes[t]):String(i.attributes[t])}this.trigger("data",i)}else t=/^#EXT-X-INDEPENDENT-SEGMENTS/.exec(e),t?this.trigger("data",{type:"tag",tagType:"independent-segments"}):this.trigger("data",{type:"tag",data:e.slice(4)})}}}else this.trigger("data",{type:"comment",text:e.slice(1)})})):this.trigger("data",{type:"uri",uri:e}))}addParser({expression:e,customType:t,dataParser:i,segment:n}){"function"!=typeof i&&(i=e=>e),this.customParsers.push((s=>{if(e.exec(s))return this.trigger("data",{type:"custom",data:i(s),customType:t,segment:n}),!0}))}addTagMapper({expression:e,map:t}){this.tagMappers.push((i=>e.test(i)?t(i):i))}}const b=function(e){const t={};return Object.keys(e).forEach((function(i){var n;t[(n=i,n.toLowerCase().replace(/-(\w)/g,(e=>e[1].toUpperCase())))]=e[i]})),t},S=function(e){const{serverControl:t,targetDuration:i,partTargetDuration:n}=e;if(!t)return;const s="#EXT-X-SERVER-CONTROL",a="holdBack",r="partHoldBack",o=i&&3*i,d=n&&2*n;i&&!t.hasOwnProperty(a)&&(t[a]=o,this.trigger("info",{message:`${s} defaulting HOLD-BACK to targetDuration * 3 (${o}).`})),o&&t[a]<o&&(this.trigger("warn",{message:`${s} clamping HOLD-BACK (${t[a]}) to targetDuration * 3 (${o})`}),t[a]=o),n&&!t.hasOwnProperty(r)&&(t[r]=3*n,this.trigger("info",{message:`${s} defaulting PART-HOLD-BACK to partTargetDuration * 3 (${t[r]}).`})),n&&t[r]<d&&(this.trigger("warn",{message:`${s} clamping PART-HOLD-BACK (${t[r]}) to partTargetDuration * 2 (${d}).`}),t[r]=d)};class v extends p{constructor(){super(),this.lineStream=new g,this.parseStream=new T,this.lineStream.pipe(this.parseStream),this.lastProgramDateTime=null;const e=this,t=[];let i,n,s={},a=!1;const r=function(){},o={AUDIO:{},VIDEO:{},"CLOSED-CAPTIONS":{},SUBTITLES:{}};let d=0;this.manifest={allowCache:!0,discontinuityStarts:[],dateRanges:[],segments:[]};let u=0,l=0;const h={};this.on("end",(()=>{s.uri||!s.parts&&!s.preloadHints||(!s.map&&i&&(s.map=i),!s.key&&n&&(s.key=n),s.timeline||"number"!=typeof d||(s.timeline=d),this.manifest.preloadSegment=s)})),this.parseStream.on("data",(function(p){let g,f;({tag(){({version(){p.version&&(this.manifest.version=p.version)},"allow-cache"(){this.manifest.allowCache=p.allowed,"allowed"in p||(this.trigger("info",{message:"defaulting allowCache to YES"}),this.manifest.allowCache=!0)},byterange(){const e={};"length"in p&&(s.byterange=e,e.length=p.length,"offset"in p||(p.offset=u)),"offset"in p&&(s.byterange=e,e.offset=p.offset),u=e.offset+e.length},endlist(){this.manifest.endList=!0},inf(){"mediaSequence"in this.manifest||(this.manifest.mediaSequence=0,this.trigger("info",{message:"defaulting media sequence to zero"})),"discontinuitySequence"in this.manifest||(this.manifest.discontinuitySequence=0,this.trigger("info",{message:"defaulting discontinuity sequence to zero"})),p.title&&(s.title=p.title),p.duration>0&&(s.duration=p.duration),0===p.duration&&(s.duration=.01,this.trigger("info",{message:"updating zero segment duration to a small value"})),this.manifest.segments=t},key(){if(p.attributes)if("NONE"!==p.attributes.METHOD)if(p.attributes.URI){if("com.apple.streamingkeydelivery"===p.attributes.KEYFORMAT)return this.manifest.contentProtection=this.manifest.contentProtection||{},void(this.manifest.contentProtection["com.apple.fps.1_0"]={attributes:p.attributes});if("com.microsoft.playready"===p.attributes.KEYFORMAT)return this.manifest.contentProtection=this.manifest.contentProtection||{},void(this.manifest.contentProtection["com.microsoft.playready"]={uri:p.attributes.URI});if("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"===p.attributes.KEYFORMAT)return-1===["SAMPLE-AES","SAMPLE-AES-CTR","SAMPLE-AES-CENC"].indexOf(p.attributes.METHOD)?void this.trigger("warn",{message:"invalid key method provided for Widevine"}):("SAMPLE-AES-CENC"===p.attributes.METHOD&&this.trigger("warn",{message:"SAMPLE-AES-CENC is deprecated, please use SAMPLE-AES-CTR instead"}),"data:text/plain;base64,"!==p.attributes.URI.substring(0,23)?void this.trigger("warn",{message:"invalid key URI provided for Widevine"}):p.attributes.KEYID&&"0x"===p.attributes.KEYID.substring(0,2)?(this.manifest.contentProtection=this.manifest.contentProtection||{},void(this.manifest.contentProtection["com.widevine.alpha"]={attributes:{schemeIdUri:p.attributes.KEYFORMAT,keyId:p.attributes.KEYID.substring(2)},pssh:m(p.attributes.URI.split(",")[1])})):void this.trigger("warn",{message:"invalid key ID provided for Widevine"}));p.attributes.METHOD||this.trigger("warn",{message:"defaulting key method to AES-128"}),n={method:p.attributes.METHOD||"AES-128",uri:p.attributes.URI},void 0!==p.attributes.IV&&(n.iv=p.attributes.IV)}else this.trigger("warn",{message:"ignoring key declaration without URI"});else n=null;else this.trigger("warn",{message:"ignoring key declaration without attribute list"})},"media-sequence"(){isFinite(p.number)?this.manifest.mediaSequence=p.number:this.trigger("warn",{message:"ignoring invalid media sequence: "+p.number})},"discontinuity-sequence"(){isFinite(p.number)?(this.manifest.discontinuitySequence=p.number,d=p.number):this.trigger("warn",{message:"ignoring invalid discontinuity sequence: "+p.number})},"playlist-type"(){/VOD|EVENT/.test(p.playlistType)?this.manifest.playlistType=p.playlistType:this.trigger("warn",{message:"ignoring unknown playlist type: "+p.playlist})},map(){i={},p.uri&&(i.uri=p.uri),p.byterange&&(i.byterange=p.byterange),n&&(i.key=n)},"stream-inf"(){this.manifest.playlists=t,this.manifest.mediaGroups=this.manifest.mediaGroups||o,p.attributes?(s.attributes||(s.attributes={}),c(s.attributes,p.attributes)):this.trigger("warn",{message:"ignoring empty stream-inf attributes"})},media(){if(this.manifest.mediaGroups=this.manifest.mediaGroups||o,!(p.attributes&&p.attributes.TYPE&&p.attributes["GROUP-ID"]&&p.attributes.NAME))return void this.trigger("warn",{message:"ignoring incomplete or missing media group"});const e=this.manifest.mediaGroups[p.attributes.TYPE];e[p.attributes["GROUP-ID"]]=e[p.attributes["GROUP-ID"]]||{},g=e[p.attributes["GROUP-ID"]],f={default:/yes/i.test(p.attributes.DEFAULT)},f.default?f.autoselect=!0:f.autoselect=/yes/i.test(p.attributes.AUTOSELECT),p.attributes.LANGUAGE&&(f.language=p.attributes.LANGUAGE),p.attributes.URI&&(f.uri=p.attributes.URI),p.attributes["INSTREAM-ID"]&&(f.instreamId=p.attributes["INSTREAM-ID"]),p.attributes.CHARACTERISTICS&&(f.characteristics=p.attributes.CHARACTERISTICS),p.attributes.FORCED&&(f.forced=/yes/i.test(p.attributes.FORCED)),g[p.attributes.NAME]=f},discontinuity(){d+=1,s.discontinuity=!0,this.manifest.discontinuityStarts.push(t.length)},"program-date-time"(){const{lastProgramDateTime:e}=this;this.lastProgramDateTime=new Date(p.dateTimeString).getTime(),null===e&&this.manifest.segments.reduceRight(((e,t)=>(t.programDateTime=e-1e3*t.duration,t.programDateTime)),this.lastProgramDateTime)},targetduration(){!isFinite(p.duration)||p.duration<0?this.trigger("warn",{message:"ignoring invalid target duration: "+p.duration}):(this.manifest.targetDuration=p.duration,S.call(this,this.manifest))},start(){p.attributes&&!isNaN(p.attributes["TIME-OFFSET"])?this.manifest.start={timeOffset:p.attributes["TIME-OFFSET"],precise:p.attributes.PRECISE}:this.trigger("warn",{message:"ignoring start declaration without appropriate attribute list"})},"cue-out"(){s.cueOut=p.data},"cue-out-cont"(){s.cueOutCont=p.data},"cue-in"(){s.cueIn=p.data},skip(){this.manifest.skip=b(p.attributes),this.warnOnMissingAttributes_("#EXT-X-SKIP",p.attributes,["SKIPPED-SEGMENTS"])},part(){a=!0;const e=this.manifest.segments.length,t=b(p.attributes);s.parts=s.parts||[],s.parts.push(t),t.byterange&&(t.byterange.hasOwnProperty("offset")||(t.byterange.offset=l),l=t.byterange.offset+t.byterange.length);const i=s.parts.length-1;this.warnOnMissingAttributes_(`#EXT-X-PART #${i} for segment #${e}`,p.attributes,["URI","DURATION"]),this.manifest.renditionReports&&this.manifest.renditionReports.forEach(((e,t)=>{e.hasOwnProperty("lastPart")||this.trigger("warn",{message:`#EXT-X-RENDITION-REPORT #${t} lacks required attribute(s): LAST-PART`})}))},"server-control"(){const e=this.manifest.serverControl=b(p.attributes);e.hasOwnProperty("canBlockReload")||(e.canBlockReload=!1,this.trigger("info",{message:"#EXT-X-SERVER-CONTROL defaulting CAN-BLOCK-RELOAD to false"})),S.call(this,this.manifest),e.canSkipDateranges&&!e.hasOwnProperty("canSkipUntil")&&this.trigger("warn",{message:"#EXT-X-SERVER-CONTROL lacks required attribute CAN-SKIP-UNTIL which is required when CAN-SKIP-DATERANGES is set"})},"preload-hint"(){const e=this.manifest.segments.length,t=b(p.attributes),i=t.type&&"PART"===t.type;s.preloadHints=s.preloadHints||[],s.preloadHints.push(t),t.byterange&&(t.byterange.hasOwnProperty("offset")||(t.byterange.offset=i?l:0,i&&(l=t.byterange.offset+t.byterange.length)));const n=s.preloadHints.length-1;if(this.warnOnMissingAttributes_(`#EXT-X-PRELOAD-HINT #${n} for segment #${e}`,p.attributes,["TYPE","URI"]),t.type)for(let i=0;i<s.preloadHints.length-1;i++){const a=s.preloadHints[i];a.type&&a.type===t.type&&this.trigger("warn",{message:`#EXT-X-PRELOAD-HINT #${n} for segment #${e} has the same TYPE ${t.type} as preload hint #${i}`})}},"rendition-report"(){const e=b(p.attributes);this.manifest.renditionReports=this.manifest.renditionReports||[],this.manifest.renditionReports.push(e);const t=this.manifest.renditionReports.length-1,i=["LAST-MSN","URI"];a&&i.push("LAST-PART"),this.warnOnMissingAttributes_(`#EXT-X-RENDITION-REPORT #${t}`,p.attributes,i)},"part-inf"(){this.manifest.partInf=b(p.attributes),this.warnOnMissingAttributes_("#EXT-X-PART-INF",p.attributes,["PART-TARGET"]),this.manifest.partInf.partTarget&&(this.manifest.partTargetDuration=this.manifest.partInf.partTarget),S.call(this,this.manifest)},daterange(){this.manifest.dateRanges.push(b(p.attributes));const e=this.manifest.dateRanges.length-1;this.warnOnMissingAttributes_(`#EXT-X-DATERANGE #${e}`,p.attributes,["ID","START-DATE"]);const t=this.manifest.dateRanges[e];t.endDate&&t.startDate&&new Date(t.endDate)<new Date(t.startDate)&&this.trigger("warn",{message:"EXT-X-DATERANGE END-DATE must be equal to or later than the value of the START-DATE"}),t.duration&&t.duration<0&&this.trigger("warn",{message:"EXT-X-DATERANGE DURATION must not be negative"}),t.plannedDuration&&t.plannedDuration<0&&this.trigger("warn",{message:"EXT-X-DATERANGE PLANNED-DURATION must not be negative"});const i=!!t.endOnNext;if(i&&!t.class&&this.trigger("warn",{message:"EXT-X-DATERANGE with an END-ON-NEXT=YES attribute must have a CLASS attribute"}),i&&(t.duration||t.endDate)&&this.trigger("warn",{message:"EXT-X-DATERANGE with an END-ON-NEXT=YES attribute must not contain DURATION or END-DATE attributes"}),t.duration&&t.endDate){const i=t.startDate,n=i.setSeconds(i.getSeconds()+t.duration);this.manifest.dateRanges[e].endDate=new Date(n)}if(h[t.id]){for(const e in h[t.id])if(h[t.id][e]!==t[e]){this.trigger("warn",{message:"EXT-X-DATERANGE tags with the same ID in a playlist must have the same attributes and same attribute values"});break}}else h[t.id]=t},"independent-segments"(){this.manifest.independentSegments=!0}}[p.tagType]||r).call(e)},uri(){s.uri=p.uri,t.push(s),this.manifest.targetDuration&&!("duration"in s)&&(this.trigger("warn",{message:"defaulting segment duration to the target duration"}),s.duration=this.manifest.targetDuration),n&&(s.key=n),s.timeline=d,i&&(s.map=i),l=0,null!==this.lastProgramDateTime&&(s.programDateTime=this.lastProgramDateTime,this.lastProgramDateTime+=1e3*s.duration),s={}},comment(){},custom(){p.segment?(s.custom=s.custom||{},s.custom[p.customType]=p.data):(this.manifest.custom=this.manifest.custom||{},this.manifest.custom[p.customType]=p.data)}})[p.type].call(e)}))}warnOnMissingAttributes_(e,t,i){const n=[];i.forEach((function(e){t.hasOwnProperty(e)||n.push(e)})),n.length&&this.trigger("warn",{message:`${e} lacks required attribute(s): ${n.join(", ")}`})}push(e){this.lineStream.push(e)}end(){this.lineStream.push("\n"),this.manifest.dateRanges.length&&null===this.lastProgramDateTime&&this.trigger("warn",{message:"A playlist with EXT-X-DATERANGE tag must contain atleast one EXT-X-PROGRAM-DATE-TIME tag"}),this.lastProgramDateTime=null,this.trigger("end")}addParser(e){this.parseStream.addParser(e)}addTagMapper(e){this.parseStream.addTagMapper(e)}}var w={mp4:/^(av0?1|avc0?[1234]|vp0?9|flac|opus|mp3|mp4a|mp4v|stpp.ttml.im1t)/,webm:/^(vp0?[89]|av0?1|opus|vorbis)/,ogg:/^(vp0?[89]|theora|flac|opus|vorbis)/,video:/^(av0?1|avc0?[1234]|vp0?[89]|hvc1|hev1|theora|mp4v)/,audio:/^(mp4a|flac|vorbis|opus|ac-[34]|ec-3|alac|mp3|speex|aac)/,text:/^(stpp.ttml.im1t)/,muxerVideo:/^(avc0?1)/,muxerAudio:/^(mp4a)/,muxerText:/a^/},I=["video","audio","text"],E=["Video","Audio","Text"],A=function(e){return e?e.replace(/avc1\.(\d+)\.(\d+)/i,(function(e,t,i){return"avc1."+("00"+Number(t).toString(16)).slice(-2)+"00"+("00"+Number(i).toString(16)).slice(-2)})):e},D=function(e){void 0===e&&(e="");var t=e.split(","),i=[];return t.forEach((function(e){var t;e=e.trim(),I.forEach((function(n){var s=w[n].exec(e.toLowerCase());if(s&&!(s.length<=1)){t=n;var a=e.substring(0,s[1].length),r=e.replace(a,"");i.push({type:a,details:r,mediaType:n})}})),t||i.push({type:e,details:"",mediaType:"unknown"})})),i},x=function(e){return void 0===e&&(e=""),w.audio.test(e.trim().toLowerCase())},L=function(e){if(e&&"string"==typeof e){var t,i=e.toLowerCase().split(",").map((function(e){return A(e.trim())})),n="video";1===i.length&&x(i[0])?n="audio":1===i.length&&(void 0===(t=i[0])&&(t=""),w.text.test(t.trim().toLowerCase()))&&(n="application");var s="mp4";return i.every((function(e){return w.mp4.test(e)}))?s="mp4":i.every((function(e){return w.webm.test(e)}))?s="webm":i.every((function(e){return w.ogg.test(e)}))&&(s="ogg"),n+"/"+s+';codecs="'+e+'"'}},k=function(e){return void 0===e&&(e=""),window.MediaSource&&window.MediaSource.isTypeSupported&&window.MediaSource.isTypeSupported(L(e))||!1},P=function(e){return void 0===e&&(e=""),e.toLowerCase().split(",").every((function(e){e=e.trim();for(var t=0;t<E.length;t++)if(w["muxer"+E[t]].test(e))return!0;return!1}))},O="mp4a.40.2";function C(...e){const t=s.default.obj||s.default;return(t.merge||t.mergeOptions).apply(t,e)}function U(...e){const t=s.default.time||s.default;return(t.createTimeRanges||t.createTimeRanges).apply(t,e)}const R=1/30,M=.1,N=function(e,t){const i=[];let n;if(e&&e.length)for(n=0;n<e.length;n++)t(e.start(n),e.end(n))&&i.push([e.start(n),e.end(n)]);return U(i)},B=function(e,t){return N(e,(function(e,i){return e-M<=t&&i+M>=t}))},F=function(e,t){return N(e,(function(e){return e-R>=t}))},$=e=>{const t=[];if(!e||!e.length)return"";for(let i=0;i<e.length;i++)t.push(e.start(i)+" => "+e.end(i));return t.join(", ")},q=e=>{const t=[];for(let i=0;i<e.length;i++)t.push({start:e.start(i),end:e.end(i)});return t},G=function(e){if(e&&e.length&&e.end)return e.end(e.length-1)},W=function(e,t){let i=0;if(!e||!e.length)return i;for(let n=0;n<e.length;n++){const s=e.start(n),a=e.end(n);t>a||(i+=t>s&&t<=a?a-t:a-s)}return i},V=(e,t)=>{if(!t.preload)return t.duration;let i=0;return(t.parts||[]).forEach((function(e){i+=e.duration})),(t.preloadHints||[]).forEach((function(t){"PART"===t.type&&(i+=e.partTargetDuration)})),i},H=e=>(e.segments||[]).reduce(((e,t,i)=>(t.parts?t.parts.forEach((function(n,s){e.push({duration:n.duration,segmentIndex:i,partIndex:s,part:n,segment:t})})):e.push({duration:t.duration,segmentIndex:i,partIndex:null,segment:t,part:null}),e)),[]),X=e=>{const t=e.segments&&e.segments.length&&e.segments[e.segments.length-1];return t&&t.parts||[]},j=({preloadSegment:e})=>{if(!e)return;const{parts:t,preloadHints:i}=e;let n=(i||[]).reduce(((e,t)=>e+("PART"===t.type?1:0)),0);return n+=t&&t.length?t.length:0,n},z=(e,t)=>{if(t.endList)return 0;if(e&&e.suggestedPresentationDelay)return e.suggestedPresentationDelay;const i=X(t).length>0;return i&&t.serverControl&&t.serverControl.partHoldBack?t.serverControl.partHoldBack:i&&t.partTargetDuration?3*t.partTargetDuration:t.serverControl&&t.serverControl.holdBack?t.serverControl.holdBack:t.targetDuration?3*t.targetDuration:0},Y=function(e,t,i){if(void 0===t&&(t=e.mediaSequence+e.segments.length),t<e.mediaSequence)return 0;const n=function(e,t){let i=0,n=t-e.mediaSequence,s=e.segments[n];if(s){if(void 0!==s.start)return{result:s.start,precise:!0};if(void 0!==s.end)return{result:s.end-s.duration,precise:!0}}for(;n--;){if(s=e.segments[n],void 0!==s.end)return{result:i+s.end,precise:!0};if(i+=V(e,s),void 0!==s.start)return{result:i+s.start,precise:!0}}return{result:i,precise:!1}}(e,t);if(n.precise)return n.result;const s=function(e,t){let i,n=0,s=t-e.mediaSequence;for(;s<e.segments.length;s++){if(i=e.segments[s],void 0!==i.start)return{result:i.start-n,precise:!0};if(n+=V(e,i),void 0!==i.end)return{result:i.end-n,precise:!0}}return{result:-1,precise:!1}}(e,t);return s.precise?s.result:n.result+i},Q=function(e,t,i){if(!e)return 0;if("number"!=typeof i&&(i=0),void 0===t){if(e.totalDuration)return e.totalDuration;if(!e.endList)return window.Infinity}return Y(e,t,i)},K=function({defaultDuration:e,durationList:t,startIndex:i,endIndex:n}){let s=0;if(i>n&&([i,n]=[n,i]),i<0){for(let t=i;t<Math.min(0,n);t++)s+=e;i=0}for(let e=i;e<n;e++)s+=t[e].duration;return s},J=function(e,t,i,n){if(!e||!e.segments)return null;if(e.endList)return Q(e);if(null===t)return null;t=t||0;let s=Y(e,e.mediaSequence+e.segments.length,t);return i&&(s-=n="number"==typeof n?n:z(null,e)),Math.max(0,s)},Z=function(e){return e.excludeUntil&&e.excludeUntil>Date.now()},ee=function(e){return e.excludeUntil&&e.excludeUntil===1/0},te=function(e){const t=Z(e);return!e.disabled&&!t},ie=function(e,t){return t.attributes&&t.attributes[e]},ne=(e,t)=>{if(1===e.playlists.length)return!0;const i=t.attributes.BANDWIDTH||Number.MAX_VALUE;return 0===e.playlists.filter((e=>!!te(e)&&(e.attributes.BANDWIDTH||0)<i)).length},se=(e,t)=>!(!e&&!t||!e&&t||e&&!t||e!==t&&(!e.id||!t.id||e.id!==t.id)&&(!e.resolvedUri||!t.resolvedUri||e.resolvedUri!==t.resolvedUri)&&(!e.uri||!t.uri||e.uri!==t.uri)),ae=function(e,t){const i=e&&e.mediaGroups&&e.mediaGroups.AUDIO||{};let n=!1;for(const e in i){for(const s in i[e])if(n=t(i[e][s]),n)break;if(n)break}return!!n},re=e=>{if(!e||!e.playlists||!e.playlists.length)return ae(e,(e=>e.playlists&&e.playlists.length||e.uri));for(let t=0;t<e.playlists.length;t++){const i=e.playlists[t],n=i.attributes&&i.attributes.CODECS;if((!n||!n.split(",").every((e=>x(e))))&&!ae(e,(e=>se(i,e))))return!1}return!0};var oe={liveEdgeDelay:z,duration:Q,seekable:function(e,t,i){const n=t||0,s=J(e,t,!0,i);return null===s?U():U(n,s)},getMediaInfoForTime:function({playlist:e,currentTime:t,startingSegmentIndex:i,startingPartIndex:n,startTime:s,exactManifestTimings:a}){let r=t-s;const o=H(e);let d=0;for(let e=0;e<o.length;e++){const t=o[e];if(i===t.segmentIndex&&("number"!=typeof n||"number"!=typeof t.partIndex||n===t.partIndex)){d=e;break}}if(r<0){if(d>0)for(let t=d-1;t>=0;t--){const i=o[t];if(r+=i.duration,a){if(r<0)continue}else if(r+R<=0)continue;return{partIndex:i.partIndex,segmentIndex:i.segmentIndex,startTime:s-K({defaultDuration:e.targetDuration,durationList:o,startIndex:d,endIndex:t})}}return{partIndex:o[0]&&o[0].partIndex||null,segmentIndex:o[0]&&o[0].segmentIndex||0,startTime:t}}if(d<0){for(let i=d;i<0;i++)if(r-=e.targetDuration,r<0)return{partIndex:o[0]&&o[0].partIndex||null,segmentIndex:o[0]&&o[0].segmentIndex||0,startTime:t};d=0}for(let t=d;t<o.length;t++){const i=o[t];if(r-=i.duration,a){if(r>0)continue}else if(r-R>=0)continue;return{partIndex:i.partIndex,segmentIndex:i.segmentIndex,startTime:s+K({defaultDuration:e.targetDuration,durationList:o,startIndex:d,endIndex:t})}}return{segmentIndex:o[o.length-1].segmentIndex,partIndex:o[o.length-1].partIndex,startTime:t}},isEnabled:te,isDisabled:function(e){return e.disabled},isExcluded:Z,isIncompatible:ee,playlistEnd:J,isAes:function(e){for(let t=0;t<e.segments.length;t++)if(e.segments[t].key)return!0;return!1},hasAttribute:ie,estimateSegmentRequestTime:function(e,t,i,n=0){return ie("BANDWIDTH",i)?(e*i.attributes.BANDWIDTH-8*n)/t:NaN},isLowestEnabledRendition:ne,isAudioOnly:re,playlistMatch:se,segmentDurationWithParts:V};const{log:de}=s.default,ue=(e,t)=>`${e}-${t}`,le=(e,t,i)=>`placeholder-uri-${e}-${t}-${i}`,he=(e,t)=>{e.mediaGroups&&["AUDIO","SUBTITLES"].forEach((i=>{if(e.mediaGroups[i])for(const n in e.mediaGroups[i])for(const s in e.mediaGroups[i][n]){const a=e.mediaGroups[i][n][s];t(a,i,n,s)}}))},ce=({playlist:e,uri:t,id:i})=>{e.id=i,e.playlistErrors_=0,t&&(e.uri=t),e.attributes=e.attributes||{}},pe=(e,t,i=le)=>{e.uri=t;for(let t=0;t<e.playlists.length;t++)if(!e.playlists[t].uri){const i=`placeholder-uri-${t}`;e.playlists[t].uri=i}const n=re(e);he(e,((t,s,a,r)=>{if(!t.playlists||!t.playlists.length){if(n&&"AUDIO"===s&&!t.uri)for(let t=0;t<e.playlists.length;t++){const i=e.playlists[t];if(i.attributes&&i.attributes.AUDIO&&i.attributes.AUDIO===a)return}t.playlists=[c({},t)]}t.playlists.forEach((function(t,n){const o=i(s,a,r,t),d=ue(n,o);t.uri?t.resolvedUri=t.resolvedUri||u(e.uri,t.uri):(t.uri=0===n?o:d,t.resolvedUri=t.uri),t.id=t.id||d,t.attributes=t.attributes||{},e.playlists[t.id]=t,e.playlists[t.uri]=t}))})),(e=>{let t=e.playlists.length;for(;t--;){const i=e.playlists[t];ce({playlist:i,id:ue(t,i.uri)}),i.resolvedUri=u(e.uri,i.uri),e.playlists[i.id]=i,e.playlists[i.uri]=i,i.attributes.BANDWIDTH||de.warn("Invalid playlist STREAM-INF detected. Missing BANDWIDTH attribute.")}})(e),(e=>{he(e,(t=>{t.uri&&(t.resolvedUri=u(e.uri,t.uri))}))})(e)};class me{constructor(){this.offset_=null,this.pendingDateRanges_=new Map,this.processedDateRanges_=new Map}setOffset(e=[]){if(null!==this.offset_)return;if(!e.length)return;const[t]=e;void 0!==t.programDateTime&&(this.offset_=t.programDateTime/1e3)}setPendingDateRanges(e=[]){if(!e.length)return;const[t]=e,i=t.startDate.getTime();this.trimProcessedDateRanges_(i),this.pendingDateRanges_=e.reduce(((e,t)=>(e.set(t.id,t),e)),new Map)}processDateRange(e){this.pendingDateRanges_.delete(e.id),this.processedDateRanges_.set(e.id,e)}getDateRangesToProcess(){if(null===this.offset_)return[];const e={},t=[];this.pendingDateRanges_.forEach(((i,n)=>{if(!this.processedDateRanges_.has(n)&&(i.startTime=i.startDate.getTime()/1e3-this.offset_,i.processDateRange=()=>this.processDateRange(i),t.push(i),i.class))if(e[i.class]){const t=e[i.class].push(i);i.classListIndex=t-1}else e[i.class]=[i],i.classListIndex=0}));for(const i of t){const t=e[i.class]||[];i.endDate?i.endTime=i.endDate.getTime()/1e3-this.offset_:i.endOnNext&&t[i.classListIndex+1]?i.endTime=t[i.classListIndex+1].startTime:i.duration?i.endTime=i.startTime+i.duration:i.plannedDuration?i.endTime=i.startTime+i.plannedDuration:i.endTime=i.startTime}return t}trimProcessedDateRanges_(e){new Map(this.processedDateRanges_).forEach(((t,i)=>{t.startDate.getTime()<e&&this.processedDateRanges_.delete(i)}))}}const{EventTarget:ge}=s.default,fe=(e,t)=>{if(!e)return t;const i=C(e,t);if(e.preloadHints&&!t.preloadHints&&delete i.preloadHints,e.parts&&!t.parts)delete i.parts;else if(e.parts&&t.parts)for(let n=0;n<t.parts.length;n++)e.parts&&e.parts[n]&&(i.parts[n]=C(e.parts[n],t.parts[n]));return!e.skipped&&t.skipped&&(i.skipped=!1),e.preload&&!t.preload&&(i.preload=!1),i},ye=(e,t)=>{!e.resolvedUri&&e.uri&&(e.resolvedUri=u(t,e.uri)),e.key&&!e.key.resolvedUri&&(e.key.resolvedUri=u(t,e.key.uri)),e.map&&!e.map.resolvedUri&&(e.map.resolvedUri=u(t,e.map.uri)),e.map&&e.map.key&&!e.map.key.resolvedUri&&(e.map.key.resolvedUri=u(t,e.map.key.uri)),e.parts&&e.parts.length&&e.parts.forEach((e=>{e.resolvedUri||(e.resolvedUri=u(t,e.uri))})),e.preloadHints&&e.preloadHints.length&&e.preloadHints.forEach((e=>{e.resolvedUri||(e.resolvedUri=u(t,e.uri))}))},_e=function(e){const t=e.segments||[],i=e.preloadSegment;if(i&&i.parts&&i.parts.length){if(i.preloadHints)for(let e=0;e<i.preloadHints.length;e++)if("MAP"===i.preloadHints[e].type)return t;i.duration=e.targetDuration,i.preload=!0,t.push(i)}return t},Te=(e,t)=>e===t||e.segments&&t.segments&&e.segments.length===t.segments.length&&e.endList===t.endList&&e.mediaSequence===t.mediaSequence&&e.preloadSegment===t.preloadSegment,be=(e,t,i=Te)=>{const n=C(e,{}),s=n.playlists[t.id];if(!s)return null;if(i(s,t))return null;t.segments=_e(t);const a=C(s,t);if(a.preloadSegment&&!t.preloadSegment&&delete a.preloadSegment,s.segments){if(t.skip){t.segments=t.segments||[];for(let e=0;e<t.skip.skippedSegments;e++)t.segments.unshift({skipped:!0})}a.segments=((e,t,i)=>{const n=e.slice(),s=t.slice();i=i||0;const a=[];let r;for(let e=0;e<s.length;e++){const t=n[e+i],o=s[e];t?(r=t.map||r,a.push(fe(t,o))):(r&&!o.map&&(o.map=r),a.push(o))}return a})(s.segments,t.segments,t.mediaSequence-s.mediaSequence)}a.segments.forEach((e=>{ye(e,a.resolvedUri)}));for(let e=0;e<n.playlists.length;e++)n.playlists[e].id===t.id&&(n.playlists[e]=a);return n.playlists[t.id]=a,n.playlists[t.uri]=a,he(e,((e,i,n,s)=>{if(e.playlists)for(let i=0;i<e.playlists.length;i++)t.id===e.playlists[i].id&&(e.playlists[i]=a)})),n},Se=(e,t)=>{const i=e.segments||[],n=i[i.length-1],s=n&&n.parts&&n.parts[n.parts.length-1],a=s&&s.duration||n&&n.duration;return t&&a?1e3*a:500*(e.partTargetDuration||e.targetDuration||10)};class ve extends ge{constructor(e,t,i={}){if(super(),!e)throw new Error("A non-empty playlist URL or object is required");this.logger_=h("PlaylistLoader");const{withCredentials:n=!1}=i;this.src=e,this.vhs_=t,this.withCredentials=n,this.addDateRangesToTextTrack_=i.addDateRangesToTextTrack;const s=t.options_;this.customTagParsers=s&&s.customTagParsers||[],this.customTagMappers=s&&s.customTagMappers||[],this.llhls=s&&s.llhls,this.dateRangesStorage_=new me,this.state="HAVE_NOTHING",this.handleMediaupdatetimeout_=this.handleMediaupdatetimeout_.bind(this),this.on("mediaupdatetimeout",this.handleMediaupdatetimeout_),this.on("loadedplaylist",this.handleLoadedPlaylist_.bind(this))}handleLoadedPlaylist_(){const e=this.media();if(!e)return;this.dateRangesStorage_.setOffset(e.segments),this.dateRangesStorage_.setPendingDateRanges(e.dateRanges);const t=this.dateRangesStorage_.getDateRangesToProcess();t.length&&this.addDateRangesToTextTrack_(t)}handleMediaupdatetimeout_(){if("HAVE_METADATA"!==this.state)return;const e=this.media();let t=u(this.main.uri,e.uri);this.llhls&&(t=((e,t)=>{if(t.endList||!t.serverControl)return e;const i={};if(t.serverControl.canBlockReload){const{preloadSegment:e}=t;let n=t.mediaSequence+t.segments.length;if(e){const s=e.parts||[],a=j(t)-1;a>-1&&a!==s.length-1&&(i._HLS_part=a),(a>-1||s.length)&&n--}i._HLS_msn=n}if(t.serverControl&&t.serverControl.canSkipUntil&&(i._HLS_skip=t.serverControl.canSkipDateranges?"v2":"YES"),Object.keys(i).length){const t=new window.URL(e);["_HLS_skip","_HLS_msn","_HLS_part"].forEach((function(e){i.hasOwnProperty(e)&&t.searchParams.set(e,i[e])})),e=t.toString()}return e})(t,e)),this.state="HAVE_CURRENT_METADATA",this.request=this.vhs_.xhr({uri:t,withCredentials:this.withCredentials},((e,t)=>{if(this.request)return e?this.playlistRequestError(this.request,this.media(),"HAVE_METADATA"):void this.haveMetadata({playlistString:this.request.responseText,url:this.media().uri,id:this.media().id})}))}playlistRequestError(e,t,i){const{uri:n,id:s}=t;this.request=null,i&&(this.state=i),this.error={playlist:this.main.playlists[s],status:e.status,message:`HLS playlist request error at URL: ${n}.`,responseText:e.responseText,code:e.status>=500?4:2},this.trigger("error")}parseManifest_({url:e,manifestString:t}){return(({onwarn:e,oninfo:t,manifestString:i,customTagParsers:n=[],customTagMappers:s=[],llhls:a})=>{const r=new v;e&&r.on("warn",e),t&&r.on("info",t),n.forEach((e=>r.addParser(e))),s.forEach((e=>r.addTagMapper(e))),r.push(i),r.end();const o=r.manifest;if(a||(["preloadSegment","skip","serverControl","renditionReports","partInf","partTargetDuration"].forEach((function(e){o.hasOwnProperty(e)&&delete o[e]})),o.segments&&o.segments.forEach((function(e){["parts","preloadHints"].forEach((function(t){e.hasOwnProperty(t)&&delete e[t]}))}))),!o.targetDuration){let t=10;o.segments&&o.segments.length&&(t=o.segments.reduce(((e,t)=>Math.max(e,t.duration)),0)),e&&e(`manifest has no targetDuration defaulting to ${t}`),o.targetDuration=t}const d=X(o);if(d.length&&!o.partTargetDuration){const t=d.reduce(((e,t)=>Math.max(e,t.duration)),0);e&&(e(`manifest has no partTargetDuration defaulting to ${t}`),de.error("LL-HLS manifest has parts but lacks required #EXT-X-PART-INF:PART-TARGET value. See https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-09#section-4.4.3.7. Playback is not guaranteed.")),o.partTargetDuration=t}return o})({onwarn:({message:t})=>this.logger_(`m3u8-parser warn for ${e}: ${t}`),oninfo:({message:t})=>this.logger_(`m3u8-parser info for ${e}: ${t}`),manifestString:t,customTagParsers:this.customTagParsers,customTagMappers:this.customTagMappers,llhls:this.llhls})}haveMetadata({playlistString:e,playlistObject:t,url:i,id:n}){this.request=null,this.state="HAVE_METADATA";const s=t||this.parseManifest_({url:i,manifestString:e});s.lastRequest=Date.now(),ce({playlist:s,uri:i,id:n});const a=be(this.main,s);this.targetDuration=s.partTargetDuration||s.targetDuration,this.pendingMedia_=null,a?(this.main=a,this.media_=this.main.playlists[n]):this.trigger("playlistunchanged"),this.updateMediaUpdateTimeout_(Se(this.media(),!!a)),this.trigger("loadedplaylist")}dispose(){this.trigger("dispose"),this.stopRequest(),window.clearTimeout(this.mediaUpdateTimeout),window.clearTimeout(this.finalRenditionTimeout),this.dateRangesStorage_=new me,this.off()}stopRequest(){if(this.request){const e=this.request;this.request=null,e.onreadystatechange=null,e.abort()}}media(e,t){if(!e)return this.media_;if("HAVE_NOTHING"===this.state)throw new Error("Cannot switch media playlist from "+this.state);if("string"==typeof e){if(!this.main.playlists[e])throw new Error("Unknown playlist URI: "+e);e=this.main.playlists[e]}if(window.clearTimeout(this.finalRenditionTimeout),t){const t=(e.partTargetDuration||e.targetDuration)/2*1e3||5e3;return void(this.finalRenditionTimeout=window.setTimeout(this.media.bind(this,e,!1),t))}const i=this.state,n=!this.media_||e.id!==this.media_.id,s=this.main.playlists[e.id];if(s&&s.endList||e.endList&&e.segments.length)return this.request&&(this.request.onreadystatechange=null,this.request.abort(),this.request=null),this.state="HAVE_METADATA",this.media_=e,void(n&&(this.trigger("mediachanging"),"HAVE_MAIN_MANIFEST"===i?this.trigger("loadedmetadata"):this.trigger("mediachange")));if(this.updateMediaUpdateTimeout_(Se(e,!0)),n){if(this.state="SWITCHING_MEDIA",this.request){if(e.resolvedUri===this.request.url)return;this.request.onreadystatechange=null,this.request.abort(),this.request=null}this.media_&&this.trigger("mediachanging"),this.pendingMedia_=e,this.request=this.vhs_.xhr({uri:e.resolvedUri,withCredentials:this.withCredentials},((t,n)=>{if(this.request){if(e.lastRequest=Date.now(),e.resolvedUri=l(e.resolvedUri,n),t)return this.playlistRequestError(this.request,e,i);this.haveMetadata({playlistString:n.responseText,url:e.uri,id:e.id}),"HAVE_MAIN_MANIFEST"===i?this.trigger("loadedmetadata"):this.trigger("mediachange")}}))}}pause(){this.mediaUpdateTimeout&&(window.clearTimeout(this.mediaUpdateTimeout),this.mediaUpdateTimeout=null),this.stopRequest(),"HAVE_NOTHING"===this.state&&(this.started=!1),"SWITCHING_MEDIA"===this.state?this.media_?this.state="HAVE_METADATA":this.state="HAVE_MAIN_MANIFEST":"HAVE_CURRENT_METADATA"===this.state&&(this.state="HAVE_METADATA")}load(e){this.mediaUpdateTimeout&&(window.clearTimeout(this.mediaUpdateTimeout),this.mediaUpdateTimeout=null);const t=this.media();if(e){const e=t?(t.partTargetDuration||t.targetDuration)/2*1e3:5e3;this.mediaUpdateTimeout=window.setTimeout((()=>{this.mediaUpdateTimeout=null,this.load()}),e)}else this.started?t&&!t.endList?this.trigger("mediaupdatetimeout"):this.trigger("loadedplaylist"):this.start()}updateMediaUpdateTimeout_(e){this.mediaUpdateTimeout&&(window.clearTimeout(this.mediaUpdateTimeout),this.mediaUpdateTimeout=null),this.media()&&!this.media().endList&&(this.mediaUpdateTimeout=window.setTimeout((()=>{this.mediaUpdateTimeout=null,this.trigger("mediaupdatetimeout"),this.updateMediaUpdateTimeout_(e)}),e))}start(){if(this.started=!0,"object"==typeof this.src)return this.src.uri||(this.src.uri=window.location.href),this.src.resolvedUri=this.src.uri,void setTimeout((()=>{this.setupInitialPlaylist(this.src)}),0);this.request=this.vhs_.xhr({uri:this.src,withCredentials:this.withCredentials},((e,t)=>{if(!this.request)return;if(this.request=null,e)return this.error={status:t.status,message:`HLS playlist request error at URL: ${this.src}.`,responseText:t.responseText,code:2},"HAVE_NOTHING"===this.state&&(this.started=!1),this.trigger("error");this.src=l(this.src,t);const i=this.parseManifest_({manifestString:t.responseText,url:this.src});this.setupInitialPlaylist(i)}))}srcUri(){return"string"==typeof this.src?this.src:this.src.uri}setupInitialPlaylist(e){if(this.state="HAVE_MAIN_MANIFEST",e.playlists)return this.main=e,pe(this.main,this.srcUri()),e.playlists.forEach((e=>{e.segments=_e(e),e.segments.forEach((t=>{ye(t,e.resolvedUri)}))})),this.trigger("loadedplaylist"),void(this.request||this.media(this.main.playlists[0]));const t=this.srcUri()||window.location.href;this.main=((e,t)=>{const i=ue(0,t),n={mediaGroups:{AUDIO:{},VIDEO:{},"CLOSED-CAPTIONS":{},SUBTITLES:{}},uri:window.location.href,resolvedUri:window.location.href,playlists:[{uri:t,id:i,resolvedUri:t,attributes:{}}]};return n.playlists[i]=n.playlists[0],n.playlists[t]=n.playlists[0],n})(0,t),this.haveMetadata({playlistObject:e,url:t,id:this.main.playlists[0].id}),this.trigger("loadedmetadata")}}const{xhr:we}=s.default,Ie=function(e,t,i,n){const s="arraybuffer"===e.responseType?e.response:e.responseText;!t&&s&&(e.responseTime=Date.now(),e.roundTripTime=e.responseTime-e.requestTime,e.bytesReceived=s.byteLength||s.length,e.bandwidth||(e.bandwidth=Math.floor(e.bytesReceived/e.roundTripTime*8*1e3))),i.headers&&(e.responseHeaders=i.headers),t&&"ETIMEDOUT"===t.code&&(e.timedout=!0),t||e.aborted||200===i.statusCode||206===i.statusCode||0===i.statusCode||(t=new Error("XHR Failed with a response of: "+(e&&(s||e.responseText)))),n(t,e)},Ee=function(){const e=function e(t,i){t=C({timeout:45e3},t);const n=e.beforeRequest||s.default.Vhs.xhr.beforeRequest,a=e._requestCallbackSet||s.default.Vhs.xhr._requestCallbackSet||new Set,r=e._responseCallbackSet||s.default.Vhs.xhr._responseCallbackSet;n&&"function"==typeof n&&(s.default.log.warn("beforeRequest is deprecated, use onRequest instead."),a.add(n));const o=!0===s.default.Vhs.xhr.original?we:s.default.Vhs.xhr,d=((e,t)=>{if(!e||!e.size)return;let i=t;return e.forEach((e=>{i=e(i)})),i})(a,t);a.delete(n);const u=o(d||t,(function(e,t){return((e,t,i,n)=>{e&&e.size&&e.forEach((e=>{e(t,i,n)}))})(r,u,e,t),Ie(u,e,t,i)})),l=u.abort;return u.abort=function(){return u.aborted=!0,l.apply(u,arguments)},u.uri=t.uri,u.requestTime=Date.now(),u};return e.original=!0,e},Ae=function(e){const t={};return e.byterange&&(t.Range=function(e){let t;const i=e.offset;return t="bigint"==typeof e.offset||"bigint"==typeof e.length?window.BigInt(e.offset)+window.BigInt(e.length)-window.BigInt(1):e.offset+e.length-1,"bytes="+i+"-"+t}(e.byterange)),t};var De,xe,Le=/^(audio|video|application)\/(x-|vnd\.apple\.)?mpegurl/i,ke=/^application\/dash\+xml/i,Pe=function(e){return Le.test(e)?"hls":ke.test(e)?"dash":"application/vnd.videojs.vhs+json"===e?"vhs-json":null},Oe=function(e){return"function"===ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer},Ce=function(e){return e instanceof Uint8Array?e:(Array.isArray(e)||Oe(e)||e instanceof ArrayBuffer||(e="number"!=typeof e||"number"==typeof e&&e!=e?0:[e]),new Uint8Array(e&&e.buffer||e,e&&e.byteOffset||0,e&&e.byteLength||0))},Ue=window.BigInt||Number,Re=[Ue("0x1"),Ue("0x100"),Ue("0x10000"),Ue("0x1000000"),Ue("0x100000000"),Ue("0x10000000000"),Ue("0x1000000000000"),Ue("0x100000000000000"),Ue("0x10000000000000000")];De=new Uint16Array([65484]),255===(xe=new Uint8Array(De.buffer,De.byteOffset,De.byteLength))[0]||xe[0];var Me=function(e,t){var i=void 0===t?{}:t,n=i.signed,s=void 0!==n&&n,a=i.le,r=void 0!==a&&a;e=Ce(e);var o=r?"reduce":"reduceRight",d=(e[o]?e[o]:Array.prototype[o]).call(e,(function(t,i,n){var s=r?n:Math.abs(n+1-e.length);return t+Ue(i)*Re[s]}),Ue(0));if(s){var u=Re[e.length]/Ue(2)-Ue(1);(d=Ue(d))>u&&(d-=u,d-=u,d-=Ue(2))}return Number(d)},Ne=function(e,t){if("string"!=typeof e&&e&&"function"==typeof e.toString&&(e=e.toString()),"string"!=typeof e)return new Uint8Array;t||(e=unescape(encodeURIComponent(e)));for(var i=new Uint8Array(e.length),n=0;n<e.length;n++)i[n]=e.charCodeAt(n);return i},Be=function(e,t,i){var n=void 0===i?{}:i,s=n.offset,a=void 0===s?0:s,r=n.mask,o=void 0===r?[]:r;e=Ce(e);var d=(t=Ce(t)).every?t.every:Array.prototype.every;return t.length&&e.length-a>=t.length&&d.call(t,(function(t,i){return t===(o[i]?o[i]&e[a+i]:e[a+i])}))};const Fe=function(e,t){return e.start(t)+"-"+e.end(t)},$e=function(e,t){const i=e.toString(16);return"00".substring(0,2-i.length)+i+(t%2?" ":"")},qe=function(e){return e>=32&&e<126?String.fromCharCode(e):"."},Ge=function(e){const t={};return Object.keys(e).forEach((i=>{const n=e[i];Oe(n)?t[i]={bytes:n.buffer,byteOffset:n.byteOffset,byteLength:n.byteLength}:t[i]=n})),t},We=function(e){const t=e.byterange||{length:1/0,offset:0};return[t.length,t.offset,e.resolvedUri].join(",")},Ve=function(e){return e.resolvedUri},He=e=>{const t=Array.prototype.slice.call(e),i=16;let n,s,a="";for(let e=0;e<t.length/i;e++)n=t.slice(e*i,e*i+i).map($e).join(""),s=t.slice(e*i,e*i+i).map(qe).join(""),a+=n+" "+s+"\n";return a};var Xe=Object.freeze({__proto__:null,createTransferableMessage:Ge,initSegmentId:We,segmentKeyId:Ve,hexDump:He,tagDump:({bytes:e})=>He(e),textRanges:e=>{let t,i="";for(t=0;t<e.length;t++)i+=Fe(e,t)+" ";return i}});const je