async function e(e,t,n,r){let i=new Headers;n&&i.append(`Authorization`,`Bearer ${n}`),r&&i.append(`Media-User-Token`,r);let a=e.startsWith(`/`)?e.slice(1):e,o=Object.keys(t).length===0?void 0:t,s=e.includes(`?`),c=``;if(o){let e=structuredClone(t);for(let t in e)Array.isArray(e[t])&&(e[t]=e[t].join(`,`));c=new URLSearchParams(e).toString(),c=s?`&${c}`:`?${c}`}let l=`https://amp-api.music.apple.com/${a}${c}`,u=await fetch(l,{headers:i,method:`GET`,body:void 0});if(!u.ok)throw Error(`HTTP Error: ${u.status} ${u.statusText} for ${l}`);let d=u.status;if(d===204||d===202)return{data:{}};let f={};try{f=await u.json()}catch(e){console.log(`worker: v3Turbo`,`error`,`Failed to parse JSON response.`,e)}return{data:f}}self.onmessage=async t=>{let{href:n,args:r,total:i,developerToken:a,musicUserToken:o}=t.data,s=performance.now();try{let t=Number(i)||0,c=r?.useDelay||t>8e3,l=[],u={},d={};for(let e=0;e<t;e+=100){let t=`${n}?offset=${e}`;u[t]=[],d[t]=e,l.push(t)}let f=e=>u[e].length===0&&t-(d[e]??0)>0,p=n=>e(n,{limit:100,...r.queryParams},a,o).then(e=>{let i=e?.data?.data;if(u[n]=Array.isArray(i)?i:[],r.verbose&&console.log(`worker: v3Turbo`,`debug`,`Downloaded chunk.`,{href:n}),t>0){let e=Math.round(Object.values(u).flat().length/t*100);self.postMessage({type:`progress`,progress:e})}}).catch(e=>{console.log(`worker: v3Turbo`,`error`,`Failed to download chunk.`,{href:n,error:e})});for(let e=0;e<l.length;e+=15){let t=l.slice(e,e+15);await Promise.all(t.map(p)),c&&await new Promise(e=>setTimeout(e,300))}let m=l.filter(f);if(m.length){await new Promise(e=>setTimeout(e,500));for(let e=0;e<m.length;e+=15)await Promise.all(m.slice(e,e+15).map(p))}let h=Object.values(u).flat(),g=l.filter(f).length;g?console.log(`worker: v3Turbo`,`error`,`Turbo call returned a partial result.`,{href:n,expected:t,received:h.length,missingPages:g}):r.verbose&&console.log(`worker: v3Turbo`,`info`,`Turbo continuous call completed.`,{durationInMs:Math.round(performance.now()-s),href:n,songCount:h.length}),self.postMessage({type:`result`,result:h,partial:g>0})}catch(e){self.postMessage({type:`error`,error:e})}};