PageSourceSearch

https://energy.ch/ech-new/lib/icecast-metadata-player-1.2.2.min.js

js energy.ch collected 2026-09-24 09:35:58 UTC 54,176 bytes, 21 lines download raw bytes

1/*! 
2 * Copyright 2021 Ethan Halsall
3 * https://github.com/eshaz/icecast-metadata-js
4 *
5 * This file is part of icecast-metadata-player.
6 *
7 * icecast-metadata-player free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * icecast-metadata-player distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program.  If not, see <https://www.gnu.org/licenses/>
19 */
20var IcecastMetadataPlayer;(()=>{var t={764:t=>{const e=()=>{};t.exports=class{constructor({icyBr:t,onMetadataUpdate:s=e,onMetadataEnqueue:i=e}){this.t=t,this.i=s,this.h=i,this.l=!0,this.u=[]}get metadataQueue(){return this.u.map((({m:t,...e})=>e))}addMetadata({metadata:t,stats:e},s,i=0){this.p(t,s,i+this.getTimeByBytes(e.currentStreamPosition))}getTimeByBytes(t){return this.t?t/(125*this.t):0}purgeMetadataQueue(){this.u.forEach((t=>clearTimeout(t.m))),this.u=[]}p(t,e,s){const i={metadata:t,timestampOffset:e,timestamp:s};this.u.push(i),this.h(t,e,s),this.l?(this.g(),this.l=!1):i.m=setTimeout((()=>{this.g()}),1e3*(e-s))}g(){const{metadata:t,timestampOffset:e,timestamp:s}=this.u.shift();this.i(t,e,s)}}},420:(t,e,s)=>{const i=s(395),n=s(103),r=s(361),a=s(399);t.exports=class{constructor({metadataTypes:t=["icy"],...e}={}){const s=t.includes("icy"),o=t.includes("ogg");this.S=s&&o?new a(e):o?new r(e):s?new n(e):new i(e)}static parseIcyMetadata(t){return n.parseIcyMetadata(t)}get icyMetaInt(){return this.S.icyMetaInt}*iterator(t){yield*this.S.iterator(t)}readAll(t){this.S.readAll(t)}async*asyncIterator(t){return yield*this.S.asyncIterator(t)}async asyncReadAll(t){return this.S.asyncReadAll(t)}}},399:(t,e,s)=>{const i=s(103),n=s(361);t.exports=class{constructor(t){const{onStream:e,...s}=t;this.M=new n(t),this.v=new i(s)}get icyMetaInt(){return this.v.icyMetaInt}*iterator(t){for(const e of this.v.iterator(t))e.stream?yield*this.M.iterator(e.stream):yield e}readAll(t){for(const e of this.v.iterator(t))e.stream&&this.M.readAll(e.stream)}async*asyncIterator(t){for await(const e of this.v.asyncIterator(t))if(e.stream)for await(const t of this.M.asyncIterator(e.stream))yield t;else yield e}async asyncReadAll(t){for await(const e of this.v.iterator(t))e.stream&&await this.M.asyncReadAll(e.stream)}}},103:(t,e,s)=>{const i=s(395);class n extends i{constructor({icyMetaInt:t,icyDetectionTimeout:e=2e3,...s}){super(s),this.I=t,this.B=e,this.C=this.A(),this.C.next()}*A(){if(yield*this.L())for(;;)this.T=this.I,yield*this._(),yield*this.D(),this.T&&(yield*this.R());this.T=1/0,yield*this._()}static parseIcyMetadata(t){const e=/(?<key>[^\0]+?)='(?<val>[^\0]*?)(;$|';|'$|$)/,s={};for(const i of t.match(new RegExp(e,"g"))||[]){const t=i.match(e);t&&(s[t.groups.key]=t.groups.val)}return s}get icyMetaInt(){return this.I}*L(){if(this.I>0)return!0;if(!this.B)return!1;this.P("Passed in Icy-MetaInt is invalid. Attempting to detect ICY Metadata.","See https://github.com/eshaz/icecast-metadata-js for information on how to properly request ICY Metadata.");const t=[null,83,116,114,101,97,109,84,105,116,108,101,61],e=Date.now();let s=0;for(;e+this.B>Date.now();){this.k=i.U(this.k,yield*this.F());t:for(;s<this.k.length-t.length;){for(let e=1;e<t.length;e++)if(this.k[e+s]!==t[e]){s++;continue t}return this.P(`Found ICY Metadata! Setting Icy-MetaInt to ${s}.`),this.I=s,!0}}return this.P("ICY Metadata not detected, but continuing anyway. Audio errors will occur if there is ICY metadata.",`Searched ${this.k.length} bytes for ${(Date.now()-e)/1e3} seconds.`,"Try increasing the `icyDetectionTimeout` value if ICY metadata is present in the stream."),this.O("icy"),!1}*_(){for(this.V.currentStreamBytesRemaining=this.T;this.T;)yield*this.W(yield*super.H())}*D(){this.T=1;do{this.T=16*(yield*this.H())[0]}while(1===this.T);this.V.addMetadataLengthBytes(1)}*R(){this.V.currentMetadataBytesRemaining=this.T;const t=yield*this.H(this.T);this.V.addMetadataBytes(t.length),yield*this.N(n.parseIcyMetadata(this.$.decode(t)))}}t.exports=n},395:(t,e,s)=>{const i=s(758).TextDecoder||TextDecoder,n=s(4),r=()=>{};class a{constructor(t){this.T=0,this.j=0,this.k=new Uint8Array(0),this.V=new n,this.$=new i("utf-8"),this.G=t.onStream||r,this.K=t.onMetadata||r,this.O=t.onMetadataFailed||r,this.q=t.onError||r,this.Y=t.enableLogging||!1,this.J=Promise.resolve(),this.Z=Promise.resolve(),this.C=this.X(),this.C.next()}*X(){for(this.T=1/0;;)yield*this.W(yield*this.H())}static U(t,e){const s=new Uint8Array(t.length+e.length);return s.set(t),s.set(e,t.length),s}*iterator(t){for(let e=this.C.next(t);e.value;e=this.C.next())yield e.value}readAll(t){for(let e=this.C.next(t);e.value;e=this.C.next());}async*asyncIterator(t){for(let e=this.C.next(t);e.value;e=this.C.next())await this.J,await this.Z,yield e.value}async asyncReadAll(t){for(let e=this.C.next(t);e.value;e=this.C.next())await this.J,await this.Z}P(...t){this.Y&&console.warn("icecast-metadata-js",t.reduce(((t,e)=>t+"\n  "+e),"")),this.q(...t)}*W(t){this.V.addStreamBytes(t.length);
20const e={stream:t,stats:this.V.stats};this.J=this.G(e),yield e}*N(t){const e={metadata:t,stats:this.V.stats};this.Z=this.K(e),yield e}*H(t=0){for(this.j===this.k.length&&(this.k=yield*this.F(),this.j=0);this.k.length-this.j<t;)this.k=a.U(this.k,yield*this.F());const e=this.k.subarray(this.j,(t||this.T)+this.j);return this.V.addBytes(e.length),this.T=e.length<this.T?this.T-e.length:0,this.j+=e.length,e}*F(){let t;do{t=yield}while(!t||0===t.length);return this.V.addCurrentBytesRemaining(t.length),t}}t.exports=a},361:(t,e,s)=>{const i=s(395);t.exports=class extends i{constructor(t){super(t),this.C=this.tt(),this.C.next()}*tt(){if(yield*this.et()){const t=yield*this.st();if(t)for(;yield*this.et();)yield*this.R(t),yield*this._()}this.T=1/0,yield*this._()}it(t,e=0){return new DataView(Uint8Array.from([...t.subarray(e,e+4)]).buffer).getUint32(0,!0)}nt(t,e){return String.fromCharCode(...e).match(t)}*et(){let t=[];for(;t.length<=65307;){const e=yield*super.H(5);if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3]&&!(248&e[5])){this.j-=5,this.T+=5,this.V.rt-=5,this.V.at+=5;break}t.push(e[0]),this.j-=4,this.V.rt-=4,this.V.at+=4}if(t.length&&(yield*this.W(Uint8Array.from(t))),t.length>65307)return this.P("This stream is not an OGG stream. No OGG metadata will be returned.","See https://github.com/eshaz/icecast-metadata-js for information on OGG metadata."),this.O("ogg"),!1;const e=yield*this.H(27),s=yield*this.H(e[26]);return this.T=s.reduce(((t,e)=>t+e),0),!0}*st(){const t=yield*this.H(8);return yield*this._(),this.nt(/\x7fFLAC/,t.subarray(0,5))?{regex:/^[\x84|\x04]/,length:4}:this.nt(/OpusHead/,t.subarray(0,8))?{regex:/OpusTags/,length:8}:this.nt(/\x01vorbis/,t.subarray(0,7))?{regex:/\x03vorbis/,length:7}:void 0}*R({regex:t,length:e}){this.nt(t,yield*this.H(e))&&(yield*this.N(yield*this.ot()))}*_(){for(;this.T;)yield*this.H()}*H(t){const e=yield*super.H(t);return yield*this.W(e),e}*F(){const t=yield*super.F();return this.V.currentStreamBytesRemaining=t.length,t}*ot(){const t=this.it(yield*this.H(4));this.V.addMetadataBytes(4);const e=this.$.decode(yield*this.H(t));this.V.addMetadataBytes(t);const s=this.it(yield*this.H(4));this.V.addMetadataBytes(4);const i=[];for(let t=0;t<s;t++){const t=yield*this.H(4);this.V.addMetadataBytes(4),i.push(yield*this.H(this.it(t))),this.V.addMetadataBytes(i[i.length-1].length)}return this.V.currentMetadataBytesRemaining=0,i.reduce(((t,e)=>{const s=e.indexOf(61),i=String.fromCharCode(...e.subarray(0,s)).toUpperCase(),n=this.$.decode(e.subarray(s+1));return t[i]=t[i]?`${t[i]}; ${n}`:n,t}),{VENDOR_STRING:e})}}},4:t=>{t.exports=class{constructor(){this.rt=0,this.ht=0,this.ct=0,this.dt=0,this.at=0,this.lt=0,this.ut=0}get stats(){return{totalBytesRead:this.rt,streamBytesRead:this.ht,metadataLengthBytesRead:this.ct,metadataBytesRead:this.dt,currentBytesRemaining:this.at,currentStreamBytesRemaining:this.lt,currentMetadataBytesRemaining:this.ut}}set currentStreamBytesRemaining(t){this.lt+=t}set currentMetadataBytesRemaining(t){this.ut=t}addBytes(t){this.rt+=t,this.at-=t}addStreamBytes(t){this.ht+=t,this.lt-=t}addMetadataLengthBytes(t){this.ct+=t}addMetadataBytes(t){this.dt+=t,this.ut-=t}addCurrentBytesRemaining(t){this.at+=t}}},758:()=>{}},e={};function s(i){if(e[i])return e[i].exports;var n=e[i]={exports:{}};return t[i](n,n.exports,s),n.exports}s.n=t=>{var e=t&&t.ft?()=>t.default:()=>t;return s.d(e,{a:e}),e},s.d=(t,e)=>{for(var i in e)s.o(e,i)&&!s.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var i={};(()=>{"use strict";s.d(i,{default:()=>Ge});const t=()=>{},e=new WeakMap,n="loading",r="playing",a="stopping",o="stopped",h="retrying",c="play",d="load",l="streamstart",u="stream",f="streamend",m="metadata",y="metadataenqueue",w="codecupdate",p="stop",g="retry",b="retrytimeout",S="warn",M="error",v=Symbol(),E=Symbol(),I=Symbol(),B=Symbol(),C=Symbol(),A=Symbol(),L=Symbol(),T=Symbol(),x=Symbol(),_=Symbol(),D=Symbol(),R=Symbol(),z=Symbol(),P=Symbol(),k=Symbol(),U=Symbol(),F=Symbol();var O=s(764),V=s.n(O),W=s(420),H=s.n(W);const N=()=>{};class ${constructor(t,{icyMetaInt:e,onStream:s=N,...i}){let n;this.yt=new ReadableStream({async start(r){n=new(H())({...i,icyMetaInt:parseInt(t.headers.get("Icy-MetaInt"))||e,onStream:async t=>(r.enqueue(t.stream),s(t))});for await(const e of $.asyncIterator(t.body))await n.asyncReadAll(e);r.close()}}),this.wt=n}get icyMetaInt(){return this.wt.icyMetaInt}get readableStream(){return this.yt}async startReading(){try{for await(const t of $.asyncIterator(this.yt));}catch(t){if("AbortError"!==t.name)throw t}}static asyncIterator(t){const e=t.getReader();return{[Symbol.asyncIterator]:()=>({next:()=>e.read()})}}}class j{constructor(){this.gt=[]}hasEventListener(t,e){return this.gt.some((s=>s.type===t&&s.listener===e))}addEventListener(t,e,s={}){return this.hasEventListener(t,e)||this.gt.push({type:t,listener:e,options:s}),this}removeEventListener(t,e){const s=this.gt.findIndex((s=>s.type===t&&s.listener===e));return s>=0&&this.gt.splice(s,1),this}removeEventListeners(){return this.gt=[],this}
20dispatchEvent(t){return this.gt.filter((e=>e.type===t.type)).forEach((e=>{const{type:s,listener:i,options:{once:n}}=e;i.call(this,t),!0===n&&this.removeEventListener(s,i)})),this}}class G{constructor(t){const s=e.get(t);this.wt=t,this.bt=s[I],this.St=s[v],this.Mt=s[E],this.I=s[B],this.B=s[C],this.vt=s[k],this.Et=s[U]}get icyMetaInt(){return this.It&&this.It.icyMetaInt}async play(){return this.fetchStream().then((async t=>(this.wt[D](l),this.playResponse(t).finally((()=>{this.wt[D](f)})))))}async fetchStream(){const t=await fetch(this.St,{method:"GET",headers:this.vt?{"Icy-MetaData":1}:{},signal:e.get(this.wt)[F].signal});if(!t.ok){const e=new Error(`${t.status} received from ${t.url}`);throw e.name="HTTP Response Error",e}return t}async playResponse(t){this.It=new $(t,{onMetadata:this.getOnMetadata(),onStream:this.getOnStream(t),onError:(...t)=>this.wt[D](S,...t),metadataTypes:this.Mt,icyMetaInt:this.I,icyDetectionTimeout:this.B}),await this.It.startReading()}getOnMetadata(){return t=>{this.Et.addMetadata(t,this.metadataTimestamp,this.bt.currentTime)}}}const K=(...t)=>{console.error("codec-parser",t.reduce(((t,e)=>t+"\n  "+e),""))},q=new Int32Array([0,7,14,9,28,27,18,21,56,63,54,49,36,35,42,45,112,119,126,12
201,108,107,98,101,72,79,70,65,84,83,90,93,224,231,238,233,252,251,242,245,216,223,214,209,196,195,202,205,144,151,158,153,140,139,130,133,168,175,166,161,180,179,186,189,199,192,201,206,219,220,213,210,255,248,241,246,227,228,237,234,183,176,185,190,171,172,165,162,143,136,129,134,147,148,157,154,39,32,41,46,59,60,53,50,31,24,17,22,3,4,13,10,87,80,89,94,75,76,69,66,111,104,97,102,115,116,125,122,137,142,135,128,149,146,155,156,177,182,191,184,173,170,163,164,249,254,247,240,229,226,235,236,193,198,207,200,221,218,211,212,105,110,103,96,117,114,123,124,81,86,95,88,77,74,67,68,25,30,23,16,5,2,11,12,33,38,47,40,61,58,51,52,78,73,64,71,82,85,92,91,118,113,120,127,106,109,100,99,62,57,48,55,34,37,44,43,6,1,8,15,26,29,20,19,174,169,160,167,178,181,188,187,150,145,152,159,138,141,132,131,222,217,208,215,194,197,204,203,230,225,232,239,250,253,244,243]),Y=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],Q=t=>Y[15&t]<<4|Y[t>>4];class J{constructor(t){this.Bt=t,this.Ct=8*t.length}set position(t){this.Ct=t}get position(){return this.Ct}read(t){const e=Math.floor(this.Ct/8),s=this.Ct%8;this.Ct-=t;return(Q(this.Bt[e-1])<<8)+Q(this.Bt[e])>>7-s&255}}const Z=new WeakMap,X=new WeakMap,tt=new WeakMap;class et{constructor(t){this.At=t,this.reset()}static getKey(t){return String.fromCharCode(...t)}enable(){this.Lt=!0}reset(){this.Tt=new Map,this.xt=new WeakMap,this.Lt=!1}getHeader(t){const e=this.Tt.get(t);return e&&t!==this._t&&(this._t=t,this.At({...this.xt.get(e)})),e}setHeader(t,e,s){this.Lt&&(t!==this._t&&(this._t=t,this.At({...s})),this.Tt.set(t,e),this.xt.set(e,s))}}class st{constructor(t){this.Tt=new et(t)}syncFrame(t,e=0){let s=new this.Frame(t.subarray(e),this.Tt);for(;!s.header&&e+this.Dt<t.length;)e+=tt.get(s).length||1,s=new this.Frame(t.subarray(e),this.Tt);return{frame:s,remainingData:e}}fixedLengthFrame(t){return this.fixedLengthFrameSync(t,!1)}fixedLengthFrameSync(t,e=!0){let{frame:s,remainingData:i}=this.syncFrame(t),n=[];for(;Z.get(s.header)&&tt.get(s).length+i+this.Dt<t.length;){const r=new this.Frame(t.subarray(tt.get(s).length+i),this.Tt);
20if(r.header||!e){if(this.Tt.enable(),n.push(s),i+=tt.get(s).length,s=r,!Z.get(s.header))break}else{this.Tt.reset(),i++;const e=this.syncFrame(t,i);i+=e.remainingData,s=e.frame}}return{frames:n,remainingData:i}}}class it{constructor(t,e,s){this.data=e||[],this.header=t,this.samples=s,this.duration=t&&s&&this.samples/this.header.sampleRate*1e3,this.frameNumber=void 0,this.totalBytesOut=void 0,this.totalSamples=void 0,this.totalDuration=void 0,tt.set(this,{length:this.data.length})}}class nt{constructor(t,e){X.set(this,t),Z.set(this,e),this.bitDepth=t.bitDepth,this.channels=t.channels,this.sampleRate=t.sampleRate}}const rt={0:["free","free","free","free","free"],16:[32,32,32,32,8],32:[64,48,40,48,16],48:[96,56,48,56,24],64:[128,64,56,64,32],80:[160,80,64,80,40],96:[192,96,80,96,48],112:[224,112,96,112,56],128:[256,128,112,128,64],144:[288,160,128,144,80],160:[320,192,160,160,96],176:[352,224,192,176,112],192:[384,256,224,192,128],208:[416,320,256,224,144],224:[448,384,320,256,160],240:["bad","bad","bad","bad","bad"]},at={0:"bands 4 to 31",16:"bands 8 to 31",32:"bands 12 to 31",48:"bands 16 to 31"},ot={0:{description:"reserved"},2:{description:"Layer III",framePadding:1,modeExtensions:{0:"Intensity stereo off, MS stereo off",16:"Intensity stereo on, MS stereo off",32:"Intensity stereo off, MS stereo on",48:"Intensity stereo on, MS stereo on"},v1:{bitrateIndex:2,samples:1152},v2:{bitrateIndex:4,samples:576}},4:{description:"Layer II",framePadding:1,modeExtensions:at,samples:1152,v1:{bitrateIndex:1},v2:{bitrateIndex:4}},6:{description:"Layer I",framePadding:4,modeExtensions:at,samples:384,v1:{bitrateIndex:0},v2:{bitrateIndex:3}}},ht={0:{description:"MPEG Version 2.5 (later extension of MPEG 2)",layers:"v2",sampleRates:{0:11025,4:12e3,8:8e3,12:"reserved"}},8:{description:"reserved"},16:{description:"MPEG Version 2 (ISO/IEC 13818-3)",layers:"v2",sampleRates:{0:22050,4:24e3,8:16e3,12:"reserved"}},24:{description:"MPEG Version 1 (ISO/IEC 11172-3)",layers:"v1",sampleRates:{0:44100,4:48e3,8:32e3,12:"reserved"}}},ct={0:"16bit CRC",1:"none"},dt={0:"none",1:"50/15 ms",2:"reserved",3:"CCIT J.17"},lt={0:{channels:2,description:"Stereo"},64:{channels:2,description:"Joint stereo"},128:{channels:2,description:"Dual channel"},192:{channels:1,description:"Single channel (Mono)"}};class ut extends nt{static getHeader(t,e){const s={};if(t.length<4)return new ut(s,!1);const i=et.getKey(t.subarray(0,4)),n=e.getHeader(i);if(n)return new ut(n,!0);if(255!==t[0]||t[1]<224)return null;const r=24&t[1],a=6&t[1],o=1&t[1];s.length=4;const h=ht[r];if("reserved"===h.description)return null;if("reserved"===ot[a].description)return null;const c={...ot[a],...ot[a][h.layers]};s.mpegVersion=h.description,s.layer=c.description,s.samples=c.samples,s.protection=ct[o];const d=240&t[2],l=12&t[2],u=2&t[2],f=1&t[2];if(s.bitrate=rt[d][c.bitrateIndex],"bad"===s.bitrate)return null;if(s.sampleRate=h.sampleRates[l],"reserved"===s.sampleRate)return null;if(s.framePadding=u>>1&&c.framePadding,s.isPrivate=!!f,s.frameLength=Math.floor(125*s.bitrate*s.samples/s.sampleRate+s.framePadding),!s.frameLength)return null;const m=192&t[3],y=48&t[3],w=8&t[3],p=4&t[3],g=3&t[3];if(s.channelMode=lt[m].description,s.channels=lt[m].channels,s.modeExtension=c.modeExtensions[y],s.isCopyrighted=!!(w>>3),s.isOriginal=!!(p>>2),s.emphasis=dt[g],"reserved"===s.emphasis)return null;s.bitDepth=16;const{length:b,frameLength:S,samples:M,...v}=s;return e.setHeader(i,s,v),new ut(s,!0)}constructor(t,e){super(t,e),this.bitrate=t.bitrate,this.channelMode=t.channelMode,this.emphasis=t.emphasis,this.framePadding=t.framePadding,this.isCopyrighted=t.isCopyrighted,this.isOriginal=t.isOriginal,this.isPrivate=t.isPrivate,this.layer=t.layer,this.modeExtension=t.modeExtension,this.mpegVersion=t.mpegVersion,this.protection=t.protection}}class ft extends it{constructor(t,e){const s=ut.getHeader(t,e);super(s,s&&t.subarray(0,X.get(s).frameLength),s&&X.get(s).samples)}}class mt extends st{constructor(t,e){super(t),this.Frame=ft,this.Dt=4,e(this.codec)}get codec(){return"mpeg"}parseFrames(t){return this.fixedLengthFrameSync(t)}}const yt={0:"MPEG-4",8:"MPEG-2"}
20,wt={0:"valid",2:"bad",4:"bad",6:"bad"},pt={0:"16bit CRC",1:"none"},gt={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},bt={0:96e3,4:88200,8:64e3,12:48e3,16:44100,20:32e3,24:24e3,28:22050,32:16e3,36:12e3,40:11025,44:8e3,48:7350,52:"reserved",56:"reserved",60:"frequency is written explicitly"},St={0:{channels:0,description:"Defined in AOT Specific Config"},64:{channels:1,description:"front-center"},128:{channels:2,description:"front-left, front-right"},192:{channels:3,description:"front-center, front-left, front-right"},256:{channels:4,description:"front-center, front-left, front-right, back-center"},320:{channels:5,description:"front-center, front-left, front-right, back-left, back-right"},384:{channels:6,description:"front-center, front-left, front-right, back-left, back-right, LFE-channel"},448:{channels:8,description:"front-center, front-left, front-right, side-left, side-right, back-left, back-right, LFE-channel"}};class Mt extends nt{static getHeader(t,e){const s={};if(t.length<7)return new Mt(s,!1);const i=et.getKey([t[0],t[1],t[2],111111100&t[3]]),n=e.getHeader(i);if(n)Object.assign(s,n);else{if(255!==t[0]||t[1]<240)return null;const e=8&t[1],i=6&t[1],n=1&t[1];if(s.mpegVersion=yt[e],s.layer=wt[i],"bad"===s.layer)return null;s.protection=pt[n],s.length=n?7:9,s.profileBits=192&t[2],s.sampleRateBits=60&t[2];const r=2&t[2];if(s.profile=gt[s.profileBits],s.sampleRate=bt[s.sampleRateBits],"reserved"===s.sampleRate)return null;s.isPrivate=!!(r>>1),s.channelModeBits=448&new DataView(Uint8Array.of(t[2],t[3]).buffer).getUint16(),s.channelMode=St[s.channelModeBits].description,s.channels=St[s.channelModeBits].channels;const a=32&t[3],o=8&t[3],h=8&t[3],c=4&t[3];s.isOriginal=!!(a>>5),s.isHome=!!(o>>4),s.copyrightId=!!(h>>3),s.copyrightIdStart=!!(c>>2),s.bitDepth=16}const r=262112&new DataView(Uint8Array.of(0,t[3],t[4],t[5]).buffer).getUint32();if(s.frameLength=r>>5,!s.frameLength)return null;const a=8188&new DataView(Uint8Array.of(t[5],t[6]).buffer).getUint16();if(s.bufferFullness=8188===a?"VBR":a>>2,s.numberAACFrames=3&t[6],s.samples=1024,!n){const{length:t,channelModeBits:n,profileBits:r,sampleRateBits:a,frameLength:o,bufferFullness:h,numberAACFrames:c,samples:d,...l}=s;e.setHeader(i,s,l)}return new Mt(s,!0)}constructor(t,e){super(t,e),this.copyrightId=t.copyrightId,this.copyrightIdStart=t.copyrightIdStart,this.channelMode=t.channelMode,this.bufferFullness=t.bufferFullness,this.isHome=t.isHome,this.isOriginal=t.isOriginal,this.isPrivate=t.isPrivate,this.layer=t.layer,this.mpegVersion=t.mpegVersion,this.numberAACFrames=t.numberAACFrames,this.profile=t.profile,this.protection=t.protection}get audioSpecificConfig(){const t=X.get(this),e=t.profileBits+64<<5|t.sampleRateBits<<5|t.channelModeBits>>3,s=new Uint8Array(2);return new DataView(s.buffer).setUint16(0,e,!1),s}}class vt extends it{constructor(t,e){const s=Mt.getHeader(t,e);super(s,s&&t.subarray(X.get(s).length,X.get(s).frameLength),s&&X.get(s).samples),tt.get(this).length=s&&X.get(s).frameLength}}class Et extends st{constructor(t,e){super(t),this.Frame=vt,this.Dt=9,e(this.codec)}get codec(){return"aac"}parseFrames(t){return this.fixedLengthFrameSync(t)}}class It{static getHeader(t){const e={};if(t.length<28)return new It(e,!1);const s=new DataView(Uint8Array.of(...t.subarray(0,28)).buffer);if(1332176723!==s.getUint32(0))return null;e.streamStructureVersion=t[4];const i=248&t[5],n=4&t[5],r=2&t[5],a=1&t[5];if(i)return null;e.isContinuedPacket=!!(n>>2),e.isFirstPage=!!(r>>1),e.isLastPage=!!a;try{e.absoluteGranulePosition=s.getBigInt64(6,!0)}catch{}e.streamSerialNumber=s.getInt32(14,!0),e.pageSequenceNumber=s.getInt32(18,!0),e.pageChecksum=s.getInt32(22,!0);const o=t[26];if(e.length=o+27,e.length>t.length)return new It(e,!1);e.frameLength=0,e.pageSegmentTable=[],e.pageSegmentBytes=t.subarray(27,e.length);let h=0;for(const t of e.pageSegmentBytes)e.frameLength+=t,h+=t,255!==t&&(e.pageSegmentTable.push(h),h=0);return new It(e,!0)}constructor(t,e){X.set(this,t),Z.set(this,e),this.absoluteGranulePosition=t.absoluteGranulePosition,this.isContinuedPacket=t.isContinuedPacket,this.isFirstPage=t.is
20FirstPage,this.isLastPage=t.isLastPage,this.pageSegmentTable=t.pageSegmentTable,this.pageSequenceNumber=t.pageSequenceNumber,this.pageChecksum=t.pageChecksum,this.streamSerialNumber=t.streamSerialNumber}}class Bt extends it{constructor(t){const e=It.getHeader(t),s=X.get(e);if(super(e,e?t.subarray(s.length,s.length+s.frameLength):[]),Z.get(e)){let i=s.length;this.segments=e.pageSegmentTable.map((e=>{const s=t.subarray(i,i+e);return i+=e,s})),this.length=s.length+s.frameLength}}}const Ct={0:"Fixed",1:"Variable"},At={0:"reserved",16:192,32:576,48:1152,64:2304,80:4608,96:"8-bit (blocksize-1) end of header",112:"16-bit (blocksize-1) end of header",128:256,144:512,160:1024,176:2048,192:4096,208:8192,224:16384,240:32768},Lt={0:"invalid",1:88200,2:176400,3:192e3,4:8e3,5:16e3,6:22050,7:24e3,8:32e3,9:44100,10:48e3,11:96e3,12:"get 8 bit sample rate (in kHz) from end of header",13:"get 16 bit sample rate (in Hz) from end of header",14:"get 16 bit sample rate (in tens of Hz) from end of header",15:"invalid"},Tt={0:{channels:1,description:"mono"},16:{channels:2,description:"left, right"},32:{channels:3,description:"left, right, center"},48:{channels:4,description:"front left, front right, back left, back right"},64:{channels:5,description:"front left, front right, front center, back/surround left, back/surround right"},80:{channels:6,description:"front left, front right, front center, LFE, back/surround left, back/surround right"},96:{channels:7,description:"front left, front right, front center, LFE, back center, side left, side right"},112:{channels:8,description:"front left, front right, front center, LFE, back left, back right, side left, side right"},128:{channels:2,description:"left/side stereo: channel 0 is the left channel, channel 1 is the side(difference) channel"},144:{channels:2,description:"right/side stereo: channel 0 is the side(difference) channel, channel 1 is the right channel"},160:{channels:2,description:"mid/side stereo: channel 0 is the mid(average) channel, channel 1 is the side(difference) channel"},176:"reserved",192:"reserved",208:"reserved",224:"reserved",240:"reserved"},xt={0:"get from STREAMINFO metadata block",2:8,4:12,6:"reserved",8:16,10:20,12:24,14:"reserved"};class _t extends nt{static decodeUTF8Int(t){if(t[0]<128)return{value:t[0],next:1};if(255===t)return null;let e,s=2,i=224;for(;(t[0]&i)!=(i<<1&255)&&s<7;)s++,i|=i>>1;if(7===s)return null;const n=6*(s-1);e=t[0]&(255^i)<<n;for(let i=1;i<s;i++)e|=(63&t[i])<<n-6*i;return{value:e,next:s}}static getHeader(t,e){const s={};if(t.length<6)return new _t(s,!1);const i=et.getKey(t.subarray(0,4)),n=e.getHeader(i);if(n)Object.assign(s,n);else{if(255!==t[0]||248!==t[1]&&249!==t[1])return null;s.length=2,s.blockingStrategyBits=1&t[1],s.blockingStrategy=Ct[s.blockingStrategyBits],s.length++;const e=240&t[2],i=15&t[2];if(s.blockSize=At[e],"reserved"===s.blockSize)return null;if(s.sampleRate=Lt[i],"invalid"===s.sampleRate)return null;if(s.length++,1&t[3])return null;const n=240&t[3],r=14&t[3],a=Tt[n];if("reserved"===a)return null;if(s.channels=a.channels,s.channelMode=a.description,s.bitDepth=xt[r],"reserved"===s.bitDepth)return null}if(s.length=5,t.length<s.length+8)return new _t(s,!1);const r=_t.decodeUTF8Int(t.subarray(4));if(!r)return null;if(s.blockingStrategyBits?s.sampleNumber=r.value:s.frameNumber=r.value,s.length+=r.next,"string"==typeof s.blockSize)if(96===blockSizeBits){if(t.length<s.length)return new _t(s,!1);s.blockSize=t[s.length-1]-1,s.length+=1}else if(112===blockSizeBits){if(t.length<=s.length)return new _t(s,!1);s.blockSize=(t[s.length-1]<<8)+t[s.length]-1,s.length+=2}if(s.samples=s.blockSize,"string"==typeof s.sampleRate)if(12===sampleRateBits){if(t.length<s.length)return new _t(s,!1);s.sampleRate=t[s.length-1]-1,s.length+=1}else if(13===sampleRateBits){if(t.length<=s.length)return new _t(s,!1);s.sampleRate=(t[s.length-1]<<8)+t[s.length]-1,s.length+=2}else if(14===sampleRateBits){if(t.length<=s.length)return new _t(s,!1);s.sampleRate=(t[s.length-1]<<8)+t[s.length]-1,s.length+=2}if(t.length<s.length)return new _t(s,!1);if(s.crc=t[s.length-1],s.crc!==(t=>{let e;for(const s of t)e=255&q[255&(e^s)];return e})(t.subarray(0,s.length-1)))return null;if(!n){const{blockingStrategyBits:t,frameNumber:n,sampleNumber:r,samples:a,crc:o,length:h,...c}=s;e.setHeader(i,s,c)}return s}constructor(t,e){super(t,e),this.channelMode=t.channelMode,this.blockingStrategy=t.blockingStrategy,this.blockSize=t.blockSize,this.frameNumber=t.frameNumber,this.sampleNumber=t.sampleNumber,this.streamInfo=void 0}}class Dt extends it{constructor(t,e,s){const i=new _t(e,!0);i&&(i.streamInfo=s),super(i,t,i&&X.get(i).samples)}}class Rt extends st{constructor(t,e){super(t),this.Frame=Dt,e(this.codec)}get codec(){return"flac"}parseFrames(t){return 0===t.header.pageSequenceNumber?(this.Tt.enable(),this.Rt=t.data.subarray(13),{frames:[],remainingData:0}):1===t.header.pageSequenceNumber?{frames:[],remainingData:0}:{frames:t.segments.filter((t=>255===t[0])).map((t=>new Dt(t,_t.getHeader(t,this.Tt),this.Rt))),remainingData:0}}}const zt={0:["monophonic (mono)","stereo (left, right)"],1:["monophonic (mono)","stereo (left, right)","linear surround (left, center, right)","quadraphonic (front left, front right, rear left, rear right)","5.0 surround (front left, front center, front right, rear left, rear right)","5.1 surround (front left, front center, front right, rear left, rear right, LFE)","6.1 surround (front left, front center, front right, side left, side right, rear center, LFE)","7.1 surround (front left, front center, front right, side left, side right, rear left, rear right, LFE)"]};class Pt extends nt{static getHeader(t,e){const s={};if(t.length<19)return new Pt(s,!1);const i=et.getKey(t.subarray(0,19)),n=e.getHeader(i);if(n)Object.assign(s,n);else{if(79!==t[0]||112!==t[1]||117!==t[2]||115!==t[3]||72!==t[4]||101!==t[5]||97!==t[6]||100!==t[7])return null;if(1!==t[8])return null;const e=new DataView(Uint8Array.of(...t.subarray(0,19)).buffer);if(s.bitDepth=16,s.length=19,s.channels=t[9],s.preSkip=e.getUint16(10,!0),s.inputSampleRate=e.getUint32(12,!0),s.sampleRate=48e3,s.outputGain=e.getInt16(16,!0),s.channelMappingFamily=t[18],!s.channelMappingFamily in zt)return null;if(s.channelMode=zt[s.channelMappingFamily][s.channels-1],!s.channelMode)return null}if(0!==s.channelMappingFamily){if(s.length+=2+s.channels,t.length<s.length)return new Pt(s,!1);s.streamCount=t[19],s.coupledStreamCount=t[20],s.channelMappingTable=t.subarray(21,s.channels+21)}if(s.data=Uint8Array.of(...t.subarray(0,s.length)),!n){const{length:t,data:n,channelMappingFamily:r,...a}=s;e.setHeader(i,s,a)}return new Pt(s,!0)}constructor(t,e){super(t,e),this.data=t.data,this.channelMappingFamily=t.channelMappingFamily,this.channelMode=t.channelMode,this.coupledStreamCount=t.coupledStreamCount,this.preSkip=t.preSkip,this.outputGain=t.outputGain,this.inputSampleRate=t.inputSampleRate,this.streamCount=t.streamCount,this.channelMappingTable=t.channelMappingTable}}const kt={0:{mode:"SILK-only",bandwidth:"NB",frameSize:10},8:{mode:"SILK-only",bandwidth:"NB",frameSize:20},16:{mode:"SILK-only",bandwidth:"NB",frameSize:40},24:{mode:"SILK-only",bandwidth:"NB",frameSize:60},32:{mode:"SILK-only",bandwidth:"MB",frameSize:10},40:{mode:"SILK-only",bandwidth:"MB",frameSize:20},48:{mode:"SILK-only",bandwidth:"MB",frameSize:40},56:{mode:"SILK-only",bandwidth:"MB",frameSize:60},64:{mode:"SILK-only",bandwidth:"WB",frameSize:10},72:{mode:"SILK-only",bandwidth:"WB",frameSize:20},80:{mode:"SILK-only",bandwidth:"WB",frameSize:40},88:{mode:"SILK-only",bandwidth:"WB",frameSize:60},96:{mode:"Hybrid",bandwidth:"SWB",frameSize:10},104:{mode:"Hybrid",bandwidth:"SWB",frameSize:20},112:{mode:"Hybrid",bandwidth:"FB",frameSize:10},120:{mode:"Hybrid",bandwidth:"FB",frameSize:20},128:{mode:"CELT-only",bandwidth:"NB",frameSize:2.5},136:{mode:"CELT-only",bandwidth:"NB",frameSize:5},144:{mode:"CELT-only",bandwidth:"NB",frameSize:10},152:{mode:"CELT-only",bandwidth:"NB",frameSize:20},160:{mode:"CELT-only",bandwidth:"WB",frameSize:2.5},168:{mode:"CELT-only",bandwidth:"WB",frameSize:5},176:{mode:"CELT-only",bandwidth:"WB",frameSize:10},184:{mode:"CELT-only",bandwidth:"WB",frameSize:20},192:{mode:"CELT-only",bandwidth:"SWB",frameSize:2.5},200:{mode:"CELT-only",bandwidth:"SWB",frameSize:5},208:{mode:"CELT-only",bandwidth:"SWB",frameSize:10},216:{mode:"CELT-only",bandwidth:"SWB",frameSize:20},224:{mode:"CELT-only",bandwidth:"FB",frameSize:2.5},232:{mode:"CELT-only",bandwidth:"FB",frameSize:5},240:{mode:"CELT-only",bandwidth:"FB",frameSize:10},248:{mode:"CELT-only",bandwidth:"FB",frameSize:20}};class Ut extends it{static getPacket(t){const e={config:kt[248&t[0]],channels:4&t[0]?2:1,code:3&t[0]};switch(e.code){case 0:return e.frameCount=1,e;case 1:case 2:return e.frameCount=2,e;
20case 3:return e.isVbr=Boolean(128&t[1]),e.hasOpusPadding=Boolean(64&t[1]),e.frameCount=63&t[1],e}}constructor(t,e){let s=new Pt(e,!0);const i=Ut.getPacket(t);super(s,t,s&&i.config.frameSize*i.frameCount/1e3*s.sampleRate)}}class Ft extends st{constructor(t,e){super(t),this.Frame=Ut,this.zt=null,this.Dt=26,e(this.codec)}get codec(){return"opus"}parseFrames(t){return 0===t.header.pageSequenceNumber?(this.Tt.enable(),this.zt=Pt.getHeader(t.data,this.Tt),{frames:[],remainingData:0}):1===t.header.pageSequenceNumber?{frames:[],remainingData:0}:{frames:t.segments.map((t=>new Ut(t,this.zt))),remainingData:0}}}class Ot extends it{constructor(t,e,s){super(e,t,s)}}const Vt={6:64,7:128,8:256,9:512,10:1024,11:2048,12:4096,13:8192};class Wt extends nt{static getHeader(t,e){const s={length:30};if(t.length<30)return new Wt(s,!1);const i=et.getKey(t.subarray(0,30)),n=e.getHeader(i);if(n)return new Wt(n,!0);if(1!==t[0]||118!==t[1]||111!==t[2]||114!==t[3]||98!==t[4]||105!==t[5]||115!==t[6])return null;s.data=Uint8Array.of(...t.subarray(0,30));const r=new DataView(s.data.buffer);if(s.version=r.getUint32(7,!0),0!==s.version)return null;if(s.channels=t[11],s.sampleRate=r.getUint32(12,!0),s.bitrateMaximum=r.getInt32(16,!0),s.bitrateNominal=r.getInt32(20,!0),s.bitrateMinimum=r.getInt32(24,!0),s.blocksize1=Vt[(240&t[28])>>4],s.blocksize0=Vt[15&t[28]],t[!0])return null;s.bitDepth=32;{const{length:t,data:n,version:r,...a}=s;e.setHeader(i,s,a)}return new Wt(s,!0)}constructor(t,e){super(t,e),this.bitrateMaximum=t.bitrateMaximum,this.bitrateMinimum=t.bitrateMinimum,this.bitrateNominal=t.bitrateNominal,this.blocksize0=t.blocksize0,this.blocksize1=t.blocksize1,this.data=t.data,this.vorbisComments=void 0,this.vorbisSetup=void 0}}class Ht extends st{constructor(t,e){super(t),this.Frame=Ot,this.Dt=29,e(this.codec),this.zt=null,this.Pt={count:0},this.kt=0,this.Ut=0}get codec(){return"vorbis"}parseFrames(t){return 0===t.header.pageSequenceNumber?(this.Tt.enable(),this.zt=Wt.getHeader(t.data,this.Tt),{frames:[],remainingData:0}):1===t.header.pageSequenceNumber?(this.zt.vorbisComments=t.segments[0],this.zt.vorbisSetup=t.segments[1],this.Pt=this.Ft(t.segments[1]),{frames:[],remainingData:0}):{frames:t.segments.map((t=>new Ot(t,this.zt,this.Ot(t)))),remainingData:0}}Ot(t){const e=t[0]>>1,s=this.Pt[e&this.Pt.mask];s&&(this.kt=e&this.Pt.prevMask?this.zt.blocksize1:this.zt.blocksize0),this.Ut=s?this.zt.blocksize1:this.zt.blocksize0;const i=this.kt+this.Ut>>2;return this.kt=this.Ut,i}Ft(t){const e=new J(t);let s,i={count:0};for(;1!=(1&e.read(1)););for(;i.count<64&&e.position>0;){const t=Q(e.read(8));if(t in i)throw K("received duplicate mode mapping, failed to parse vorbis modes"),new Error("Failed to read Vorbis stream");let n=0;for(;0===e.read(8)&&n++<3;);if(4!==n){if(1+((126&Q(s))>>1)!==i.count)throw K("mode count did not match actual modes, failed to parse vorbis modes"),new Error("Failed to read Vorbis stream");break}s=e.read(7),i[t]=1&s,e.position+=6,i.count++}return i.mask=(1<<Math.log2(i.count))-1,i.prevMask=1+(1|i.mask),i}}class Nt extends st{constructor(t,e){super(),this.At=t,this.Vt=e,this.Frame=Bt,this.Dt=283,this.Wt=null}get codec(){return this.Wt||""}nt(t,e){return String.fromCharCode(...e).match(t)}getCodec({data:t}){return this.nt(/\x7fFLAC/,t.subarray(0,5))?(this.Ht=new Rt(this.At,this.Vt),"flac"):this.nt(/OpusHead/,t.subarray(0,8))?(this.Ht=new Ft(this.At,this.Vt),"opus"):this.nt(/\x01vorbis/,t.subarray(0,7))?(this.Ht=new Ht(this.At,this.Vt),"vorbis"):void 0}parseFrames(t){const e=this.fixedLengthFrame(t);return e.frames.length&&(this.Wt||(this.Wt=this.getCodec(e.frames[0]),this.Wt))?{frames:e.frames.flatMap((t=>this.Ht.parseFrames(t).frames)),remainingData:e.remainingData}:{frames:[],remainingData:e.remainingData}}}const $t=()=>{};const jt=class{constructor(t,{onCodecUpdate:e,onCodec:s}={}){if(this.Nt=t,this.At=e||$t,this.Vt=s||$t,this.Nt.match(/aac/))this.$t=new Et(this.At,this.Vt);else if(this.Nt.match(/mpeg/))this.$t=new mt(this.At,this.Vt);else{if(!this.Nt.match(/ogg/))throw new Error(`Unsupported Codec ${t}`);this.$t=new Nt(this.At,this.Vt)}this.jt=0,this.Gt=0,this.Kt=0,this.qt=[],this.Yt=new Uint8Array(0),this.C=this.C(),this.C.next()}get codec(){return this.$t.codec}*iterator(t){for(let e=this.C.next(t);e.value;e=this.C.next())yield e.value}*C(){let t=[];for(;;)yield*this.Qt(t),t=this.Jt()}*Qt(t){for(const e of t)yield e;let e;do{e=yield}while(!e);this.Yt=((...t)=>{const e=new Uint8Array(t.reduce(((t,e)=>t+e.length),0));return t.reduce(((t,s)=>(e.set(s,t),t+s.length)),0),e})(this.Yt,e)}Jt(){const{frames:t,remainingData:e}=this.$t.parseFrames(this.Yt);return this.Yt=this.Yt.subarray(e),t.map((t=>(t.frameNumber=this.jt++,t.totalBytesOut=this.Gt,t.totalSamples=this.Kt,t.totalDuration=this.Kt/t.header.sampleRate*1e3,this.Gt+=t.data.length,this.Kt+=t.samples,t)))}};class Gt{constructor({name:t,contents:e=[],children:s=[]}){this.Zt=t,this.Xt=e,this.te=s}static stringToByteArray(t){return[...t].map((t=>t.charCodeAt(0)))}static getFloat64(t){const e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t),e}static getUint64(t){const e=new Uint8Array(8);return new DataView(e.buffer).setBigUint64(0,BigInt(t)),e}static getUint32(t){const e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t),e}static getUint16(t){const e=new Uint8Array(2);return new DataView(e.buffer).setUint16(0,t),e}static getInt16(t){const e=new Uint8Array(2);return new DataView(e.buffer).setInt16(0,t),e}static*flatten(t){for(const e of t)Array.isArray(e)?yield*Gt.flatten(e):yield e}
20get contents(){const t=new Uint8Array(this.length),e=this.ee();let s=0;for(const i of Gt.flatten(e))"object"!=typeof i?(t[s]=i,s++):(t.set(i,s),s+=i.length);return t}get length(){return this.se()}ee(){return[this.Xt,...this.te.map((t=>t.ee()))]}se(){let t;return t=Array.isArray(this.Xt)?this.Xt.reduce(((t,e)=>t+(void 0===e.length?1:e.length)),0):void 0===this.Xt.length?1:this.Xt.length,t+this.te.reduce(((t,e)=>t+e.length),0)}addChild(t){this.te.push(t)}}class Kt extends Gt{constructor(t,{contents:e,children:s}={}){super({name:t,contents:e,children:s})}ee(){return[...this.ie,...Gt.stringToByteArray(this.Zt),...super.ee()]}se(){return this.ne||(this.ne=4+this.Zt.length+super.se(),this.ie=Gt.getUint32(this.ne)),this.ne}}class qt extends Gt{constructor(t,{contents:e,tags:s}={}){super({name:t,contents:e,children:s})}static getLength(t){const e=Gt.getUint32(t);return e.every(((t,e,s)=>0===t&&(s[e]=128,!0))),e}ee(){return[this.Zt,...this.ie,...super.ee()]}se(){if(!this.ne){const t=super.se();this.ie=qt.getLength(t),this.ne=1+t+this.ie.length}return this.ne}addTag(t){this.addChild(t)}}class Yt{constructor(t){this.Wt=t}getCodecBox(t){switch(this.Wt){case"mp3":return this.getMp4a(t,107);case"mp4a.40.2":return this.getMp4a(t,64);case"opus":return this.getOpus(t);case"flac":return this.getFlaC(t)}}getOpus(t){return new Kt("Opus",{contents:[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channels,0,t.bitDepth,0,0,0,0,Kt.getUint16(t.sampleRate),0,0],children:[new Kt("dOps",{contents:[0,t.channels,Kt.getUint16(t.preSkip),Kt.getUint32(t.inputSampleRate),Kt.getInt16(t.outputGain),t.channelMappingFamily,0!==t.channelMappingFamily?[t.streamCount,t.coupledStreamCount,t.channelMappingTable]:[]]})]})}getFlaC(t){return new Kt("fLaC",{contents:[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channels,0,t.bitDepth,0,0,0,0,Kt.getUint16(t.sampleRate),0,0],children:[new Kt("dfLa",{contents:[0,0,0,0,...t.streamInfo||[128,0,0,34,Kt.getUint16(t.blockSize),Kt.getUint16(t.blockSize),0,0,0,0,0,0,Kt.getUint32(t.sampleRate<<12|t.channels<<8|t.bitDepth-1<<4),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]})]})}getMp4a(t,e){const s=new qt(4,{contents:[e,21,0,0,0,0,0,0,0,0,0,0,0]});return 64===e&&s.addTag(new qt(5,{contents:t.audioSpecificConfig})),new Kt("mp4a",{contents:[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channels,0,16,0,0,0,0,Kt.getUint16(t.sampleRate),0,0],children:[new Kt("esds",{contents:[0,0,0,0],children:[new qt(3,{contents:[0,1,0],tags:[s,new qt(6,{contents:2})]})]})]})}getInitializationSegment({header:t,samples:e}){return new Gt({children:[new Kt("ftyp",{contents:[Kt.stringToByteArray("iso5"),0,0,2,0,Kt.stringToByteArray("iso6mp41")]}),new Kt("moov",{children:[new Kt("mvhd",{contents:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,232,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2]}),new Kt("trak",{children:[new Kt("tkhd",{contents:[0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0]}),new Kt("mdia",{children:[new Kt("mdhd",{contents:[0,0,0,0,0,0,0,0,0,0,0,0,Kt.getUint32(t.sampleRate),0,0,0,0,85,196,0,0]}),new Kt("hdlr",{contents:[0,0,0,0,Kt.stringToByteArray("mhlr"),Kt.stringToByteArray("soun"),0,0,0,0,0,0,0,0,0,0,0,0,0]}),new Kt("minf",{children:[new Kt("stbl",{children:[new Kt("stsd",{contents:[0,0,0,0,0,0,0,1],children:[this.getCodecBox(t)]}),new Kt("stts",{contents:[0,0,0,0,0,0,0,0]}),new Kt("stsc",{contents:[0,0,0,0,0,0,0,0]}),new Kt("stsz",{contents:[0,0,0,0,0,0,0,0,0,0,0,0]}),new Kt("stco",{contents:[0,0,0,0,0,0,0,0]})]})]})]})]}),new Kt("mvex",{children:[new Kt("trex",{contents:[0,0,0,0,0,0,0,1,0,0,0,1,Kt.getUint32(e),0,0,0,0,0,0,0,0]})]})]})]}).contents}getMediaSegment(t){return new Gt({children:[new Kt("moof",{children:[new Kt("mfhd",{contents:[0,0,0,0,0,0,0,0]}),new Kt("traf",{children:[new Kt("tfhd",{contents:[0,2,0,0,0,0,0,1]}),new Kt("tfdt",{contents:[0,0,0,0,0,0,0,0]}),new Kt("trun",{contents:[0,0,2,1,Kt.getUint32(t.length),Kt.getUint32(92+4*t.length),...t.map((({data:t})=>Kt.getUint32(t.length)))]})]})]}),new Kt("mdat",{contents:t.map((({data:t})=>t))})]}).contents}}const Qt=(...t)=>t.flatMap((t=>{const e=[];for(let s=t.length;s>=0;s-=255)e.push(s>=255?255:s);return e}));class Jt extends Gt{constructor(t,{contents:e,children:s,isUnknownLength:i=!1}={}){super({name:t,contents:e,children:s}),this.re=i}static getUintVariable(t){let e;if(t<127)e=[128|t];else if(t<16383)e=Gt.getUint16(t),e[0]|=64;else if(t<2097151)e=Gt.getUint32(t).subarray(1),e[0]|=32;else if(t<268435455)e=Gt.getUint32(t),e[0]|=16;else if(t<34359738367)e=Gt.getUint64(t).subarray(3),e[0]|=8;
20else if(t<4398046511103)e=Gt.getUint64(t).subarray(2),e[0]|=4;else if(t<562949953421311)e=Gt.getUint64(t).subarray(1),e[0]|=2;else if(t<72057594037927940)e=Gt.getUint64(t),e[0]|=1;else if("number"!=typeof t||isNaN(t))throw((...t)=>{console.error("mse-audio-wrapper",t.reduce(((t,e)=>t+"\n  "+e),""))})(`EBML Variable integer must be a number, instead received ${t}`),new Error("mse-audio-wrapper: Unable to encode WEBM");return e}ee(){return[...this.Zt,...this.ie,...super.ee()]}se(){return this.ne||(this.ae=super.se(),this.ie=this.re?[1,255,255,255,255,255,255,255]:Jt.getUintVariable(this.ae),this.ne=this.Zt.length+this.ie.length+this.ae),this.ne}}const Zt=[225],Xt=[98,100],te=[159],ee=[31,67,182,117],se=[86,170],ie=[134],ne=[99,162],re=[66,130],ae=[66,133],oe=[66,135],he=[26,69,223,163],ce=[66,242],de=[66,243],le=[66,247],ue=[66,134],fe=[156],me=[21,73,169,102],ye=[77,128],we=[181],pe=[86,187],ge=[24,83,128,103],be=[163],Se=[231],Me=[42,215,177],ve=[174],Ee=[215],Ie=[22,84,174,107],Be=[131],Ce=[115,197],Ae=[87,65];class Le{constructor(t){switch(t){case"opus":this.oe="A_OPUS",this.he=t=>[new Jt(se,{contents:Jt.getUint32(Math.round(t.preSkip*this.ce))}),new Jt(pe,{contents:Jt.getUint32(Math.round(3840*this.ce))}),new Jt(ne,{contents:t.data})];break;case"vorbis":this.oe="A_VORBIS",this.he=t=>[new Jt(ne,{contents:[2,Qt(t.data,t.vorbisComments),t.data,t.vorbisComments,t.vorbisSetup]})]}}getInitializationSegment({header:t}){return this.ce=1e9/t.sampleRate,new Gt({children:[new Jt(he,{children:[new Jt(ue,{contents:1}),new Jt(le,{contents:1}),new Jt(ce,{contents:4}),new Jt(de,{contents:8}),new Jt(re,{contents:Jt.stringToByteArray("webm")}),new Jt(oe,{contents:4}),new Jt(ae,{contents:2})]}),new Jt(ge,{isUnknownLength:!0,children:[new Jt(me,{children:[new Jt(Me,{contents:Jt.getUint32(Math.floor(this.ce))}),new Jt(ye,{contents:Jt.stringToByteArray("mse-audio-wrapper")}),new Jt(Ae,{contents:Jt.stringToByteArray("mse-audio-wrapper")})]}),new Jt(Ie,{children:[new Jt(ve,{children:[new Jt(Ee,{contents:1}),new Jt(Ce,{contents:1}),new Jt(fe,{contents:0}),new Jt(ie,{contents:Jt.stringToByteArray(this.oe)}),new Jt(Be,{contents:2}),new Jt(Zt,{children:[new Jt(te,{contents:t.channels}),new Jt(we,{contents:Jt.getFloat64(t.sampleRate)}),new Jt(Xt,{contents:t.bitDepth})]}),...this.he(t)]})]})]})]}).contents}getMediaSegment(t){const e=t[0].totalSamples;return new Jt(ee,{children:[new Jt(Se,{contents:Jt.getUintVariable(e)}),...t.map((({data:t,totalSamples:s})=>new Jt(be,{contents:[129,Jt.getInt16(s-e),128,t]})))]}).contents}}const Te=()=>{};const xe=class{constructor(t,e={}){this.Nt=t,this.PREFERRED_CONTAINER=e.preferredContainer||"webm",this.MIN_FRAMES=e.minFramesPerSegment||4,this.MAX_FRAMES=e.maxFramesPerSegment||50,this.MIN_FRAMES_LENGTH=e.minBytesPerSegment||1022,this.MAX_SAMPLES_PER_SEGMENT=1/0,this.de=e.onMimeType||Te,this.qt=[],this.$t=new jt(t,{onCodec:t=>{this.le=this.ue(t),this.de(this.fe)},onCodecUpdate:e.onCodecUpdate})}get mimeType(){return this.fe}get inputMimeType(){return this.Nt}*iterator(t){if(this.qt.push(...this.$t.iterator(t)),this.qt.length){const t=this.me();if(t.length){this.ye||(this.ye=!0,yield this.le.getInitializationSegment(t[0][0]));for(const e of t)yield this.le.getMediaSegment(e)}}}me(){const t=[[]];let e=t[0],s=0;for(const i of this.qt)(e.length===this.MAX_FRAMES||s>=this.MAX_SAMPLES_PER_SEGMENT)&&(s=0,t.push(e=[])),e.push(i),s+=i.samples;return this.qt=e.length<this.MIN_FRAMES||e.reduce(((t,e)=>t+e.data.length),0)<this.MIN_FRAMES_LENGTH?t.pop():[],t}ue(t){switch(t){case"mpeg":return this.fe='audio/mp4;codecs="mp3"',new Yt("mp3");case"aac":return this.fe='audio/mp4;codecs="mp4a.40.2"',new Yt("mp4a.40.2");case"flac":return this.fe='audio/mp4;codecs="flac"',new Yt("flac");case"vorbis":return this.fe='audio/webm;codecs="vorbis"',this.MAX_SAMPLES_PER_SEGMENT=32767,new Le("vorbis");case"opus":return"webm"===this.PREFERRED_CONTAINER?(this.fe='audio/webm;codecs="opus"',this.MAX_SAMPLES_PER_SEGMENT=32767,new Le("opus")):(this.fe='audio/mp4;codecs="opus"',new Yt("opus"))}}};class _e extends G{constructor(t){super(t),this.we()}static isSupported(){try{new MediaSource}catch{return!1}return!0}static canPlayType(t){const e={mpeg:['audio/mp4;codecs="mp3"'],aac:['audio/mp4;codecs="mp4a.40.2"'],aacp:['audio/mp4;codecs="mp4a.40.2"'],ogg:{flac:['audio/mp4;codecs="flac"'],opus:['audio/mp4;codecs="opus"','audio/webm;codecs="opus"'],vorbis:['audio/webm;codecs="vorbis"']}};if(!_e.isSupported())return"";
20if(MediaSource.isTypeSupported(t))return"probably";const s=t.match(/^(?:application\/|audio\/|)(?<mime>[a-zA-Z]+)(?:$|;[ ]*codecs=(?:\'|\")(?<codecs>[a-zA-Z,]+)(?:\'|\"))/);if(s){const{mime:t,codecs:i}=s.groups;if(e[t])return(Array.isArray(e[t])?e[t]:i?i.split(",").flatMap((s=>e[t][s])):Object.values(e[t]).flat()).reduce(((t,e)=>MediaSource.isTypeSupported(e)?""===t?"maybe":"probably":t?"maybe":""),null)}return""}async reset(){await this.we()}get metadataTimestamp(){return this.pe&&this.pe.sourceBuffers.length&&Math.max(this.pe.sourceBuffers[0].timestampOffset,this.pe.sourceBuffers[0].buffered.length?this.pe.sourceBuffers[0].buffered.end(0):0)||0}getOnStream(t){const e=this.ge(t.headers.get("content-type")).then((t=>this.be(t))),s=async({stream:t})=>{this.wt[D](u,t),await e,await this.Se(t)};return this.Me?async({stream:t})=>{for await(const e of this.Me.iterator(t))await s({stream:e})}:s}async ge(t){if(MediaSource.isTypeSupported(t))return t;{const e=await new Promise((e=>{this.Me=new xe(t,{onCodecUpdate:(...t)=>this.wt[D](w,...t),onMimeType:e})}));if(!MediaSource.isTypeSupported(e)){this.wt[D](M,`Media Source Extensions API in your browser does not support ${t} or ${e}`,"See: https://caniuse.com/mediasource and https://developer.mozilla.org/en-US/docs/Web/API/Media_Source_Extensions_API");const s=new Error(`Unsupported Media Source Codec ${e}`);throw s.name="CodecError",s}return e}}async be(t){await this.ve,this.Ee=0,this.pe.addSourceBuffer(t).mode="sequence"}async we(){return this.pe=new MediaSource,this.bt.src=URL.createObjectURL(this.pe),this.ve=new Promise((t=>{this.pe.addEventListener("sourceopen",t,{once:!0})})),this.ve}async Ie(){return new Promise((t=>{this.pe.sourceBuffers[0].addEventListener("updateend",t,{once:!0})}))}async Se(t){this.wt.state!==a&&(this.pe.sourceBuffers[0].appendBuffer(t),await this.Ie(),this.bt.currentTime>10&&this.Ee+1e4<Date.now()&&(this.Ee=Date.now(),this.pe.sourceBuffers[0].remove(0,this.bt.currentTime-10),await this.Ie()))}}class De extends G{constructor(t){super(t),this.Be=null,this.Ce=0,this.Ae=0,this.bt.crossOrigin="anonymous",this.bt.preload="none",this.bt.src=this.St}static canPlayType(t){return(new Audio).canPlayType(t)}async reset(){this.wt.state!==r&&(this.Be=null,this.Ce=0,this.Ae=0,this.bt.removeAttribute("src"),this.bt.load(),this.bt.src=this.St)}async play(){const t=new Promise(((t,e)=>{this.wt.addEventListener(a,t,{once:!0}),this.bt.addEventListener("playing",t,{once:!0}),this.bt.addEventListener("error",e,{once:!0})}));return this.bt.src=this.St,this.bt.load(),this.Mt.length?t.then((async()=>{const t=performance.now(),e=await super.play();return this.Ae=performance.now()-t,e})):new Promise(((t,s)=>{const i=()=>s(new DOMException("Aborted","AbortError")),n=e.get(this.wt)[F];n.aborted?i():n.signal.addEventListener("abort",i,{once:!0})}))}get metadataTimestamp(){return this.Be?(this.Be.totalDuration+this.Ae)/1e3:0}getOnStream(t){return this.$t=new jt(t.headers.get("content-type"),{onCodecUpdate:(...t)=>this.wt[D](w,...t)}),({stream:t})=>{this.wt[D](u,t);for(const e of this.$t.iterator(t))this.Be=e}}}let Re;try{new EventTarget,Re=EventTarget}catch{Re=j}const ze=Symbol(),Pe=Symbol(),ke=Symbol(),Ue=Symbol(),Fe=Symbol(),Oe=Symbol(),Ve=Symbol(),We=Symbol(),He=Symbol(),Ne=Symbol(),$e=Symbol(),je=Symbol();class Ge extends Re{constructor(s,i={}){super(),e.set(this,{[v]:s,[I]:i.audioElement||new Audio,[B]:i.icyMetaInt,[C]:i.icyDetectionTimeout,[E]:i.metadataTypes||["icy"],[k]:(i.metadataTypes||["icy"]).includes("icy"),[A]:i.enableLogging||!1,[L]:(i.retryDelayRate||.1)+1,[T]:1e3*(i.retryDelayMin||.5),[x]:1e3*(i.retryDelayMax||2),[_]:1e3*(i.retryTimeout||30),[ke]:{[c]:i.onPlay||t,[d]:i.onLoad||t,[l]:i.onStreamStart||t,[u]:i.onStream||t,[f]:i.onStreamEnd||t,[m]:i.onMetadata||t,[y]:i.onMetadataEnqueue||t,[w]:i.onCodecUpdate||t,[p]:i.onStop||t,[g]:i.onRetry||t,[b]:i.onRetryTimeout||t,[S]:(...t)=>{e.get(this)[A]&&console.warn("icecast-metadata-js",t.reduce(((t,e)=>t+"\n  "+e),"")),i.onWarn&&i.onWarn(...t)},[M]:(...t)=>{e.get(this)[A]&&console.error("icecast-metadata-js",t.reduce(((t,e)=>t+"\n  "+e),"")),i.onError&&i.onError(...t)}},[U]:new(V())({onMetadataUpdate:(...t)=>this[D](m,...t),onMetadataEnqueue:(...t)=>this[D](y,...t)}),[Ne]:()=>{clearTimeout(e.get(this)[je]),this.removeEventListener(l,e.get(this)[Ne]),e.get(this)[I].removeEventListener("waiting",e.get(this)[He]),e.get(this)[I].pause(),e.get(this)[U].purgeMetadataQueue(),e.get(this)[Pe]=e.get(this)[ze].reset()},[Oe]:()=>{this.play()},[Fe]:()=>{this.stop()},[Ve]:()=>{this.state!==n&&this.state!==h||(e.get(this)[I].play(),this[Ue]=r,this[D](c))},[We]:t=>{this[D](M,"The audio element encountered an error",{1:"MEDIA_ERR_ABORTED The fetching of the associated resource was aborted by the user's request.",2:"MEDIA_ERR_NETWORK Some kind of network error occurred which prevented the media from being successfully fetched, despite having previously been available.",3:"MEDIA_ERR_DECODE Despite having previously been determined to be usable, an error occurred while trying to decode the media resource, resulting in an error.",4:"MEDIA_ERR_SRC_NOT_SUPPORTED The associated resource or media provider object (such as a MediaStream) has been found to be unsuitable.",5:"MEDIA_ERR_ENCRYPTED"}[t.target.error.code]||`Code: ${t.target.error.code}`,`Message: ${t.target.error.message}`),this.state!==h?this.stop():e.get(this)[Ne]()}}),this[z](),this[Ue]=o,_e.isSupported()?e.get(this)[ze]=new _e(this):(e.get(this)[ze]=new De(this),this[D](S,"Media Source Extensions API in your browser is not supported. Using two requests, one for audio, and another for metadata.","See: https://caniuse.com/mediasource and https://developer.mozilla.org/en-US/docs/Web/API/Media_Source_Extensions_API"))}static canPlayType(t){return{mediasource:_e.canPlayType(t),html5:De.canPlayType(t)}}get audioElement(){return e.get(this)[I]}get icyMetaInt(){return e.get(this)[ze].icyMetaInt}get metadataQueue(){return e.get(this)[U].metadataQueue}get state(){return e.get(this)[Ue]}set[Ue](t){this.dispatchEvent(new CustomEvent(t)),e.get(this)[Ue]=t}[z](){const t=e.get(this)[I];t.addEventListener("pause",e.get(this)[Fe]),t.addEventListener("play",e.get(this)[Oe]),t.addEventListener("canplay",e.get(this)[Ve]),t.addEventListener("error",e.get(this)[We])}detachAudioElement(){const t=e.get(this)[I];t.removeEventListener("pause",e.get(this)[Fe]),t.removeEventListener("play",e.get(this)[Oe]),t.removeEventListener("canplay",e.get(this)[Ve]),t.removeEventListener("error",e.get(this)[We])}async play(){if(this.state===o){let t;e.get(this)[F]=new AbortController,this[Ue]=n,this[D](d);const s=()=>e.get(this)[ze].play().catch((async i=>{if("AbortError"!==i.name){if(await this[P](i))return this[D](g),s();e.get(this)[F].abort(),e.get(this)[Ue]!==a&&e.get(this)[Ue]!==o&&(this[D](M,i),t=i)}}));s().finally((()=>{e.get(this)[Ne](),t&&!t.message.match(/network|fetch|offline/)&&this[R](),this[D](p),this[Ue]=o})),await new Promise((t=>{this.addEventListener(c,t,{once:!0})}))}}async stop(){this.state!==o&&this.state!==a&&(this[Ue]=a,e.get(this)[F].abort(),await new Promise((t=>{this.addEventListener(p,t,{once:!0})})))}async[P](t){if(0===e.get(this)[_])return!1;if(e.get(this)[Ue]===h)return await new Promise((t=>{this.addEventListener(a,t,{once:!0});const s=Math.min(e.get(this)[T]*e.get(this)[L]**e.get(this)[$e]++,e.get(this)[x]);setTimeout((()=>{this.removeEventListener(a,t),t()}),s+.3*s*Math.random())})),e.get(this)[Ue]===h;if(e.get(this)[Ue]!==a&&e.get(this)[Ue]!==o&&(t.message.match(/network|fetch|offline|Error in body stream/i)||"HTTP Response Error"===t.name)){this[D](M,t),this[Ue]=h,this.addEventListener(l,e.get(this)[Ne],{once:!0}),e.get(this)[k]&&this[D](S,"This stream was requested with ICY metadata.",'If there is a CORS preflight failure, try removing "icy" from the metadataTypes option.',"See https://github.com/eshaz/icecast-metadata-js#cors for more details.");const s=new Promise((t=>{e.get(this)[He]=t,e.get(this)[I].addEventListener("waiting",e.get(this)[He],{once:!0})}));return e.get(this)[je]=setTimeout((()=>{s.then((()=>{e.get(this)[Ue]===h&&(this[D](b),this.stop())}))}),e.get(this)[_]),e.get(this)[$e]=0,!0}return!1}[D](t,...s){this.dispatchEvent(new CustomEvent(t,{detail:s})),e.get(this)[ke][t](...s)}[R](){this[D](M,"Falling back to HTML5 audio by using two requests: one for audio, and another for metadata.","See the console for details on the error."),e.get(this)[ze]=new De(this),e.get(this)[Pe].then((()=>this.play()))}}})(),IcecastMetadataPlayer=i.default})();
21//# sourceMappingURL=icecast-metadata-player-1.2.2.min.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.