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=r?.useDelay||i>8e3,c=[],l={};for(let e=0;e<i;e+=100)l[`${n}?offset=${e}`]=[],c.push(`${n}?offset=${e}`);for(let n=0;n<c.length;n+=15){let s=c.slice(n,n+15).map(t=>e(t,{limit:100,...r.queryParams},a,o).then(e=>{if(l[t]=e?.data?.data,r.verbose&&console.log(`worker: v3Turbo`,`debug`,`Downloaded chunk.`,{href:t}),i>0){let e=Math.round(Object.values(l).flat().length/i*100);self.postMessage({type:`progress`,progress:e})}}).catch(e=>{console.log(`worker: v3Turbo`,`error`,`Failed to download chunk.`,{href:t,error:e})}));await Promise.all(s),t&&await new Promise(e=>setTimeout(e,300))}let u=Object.values(l).flat()??[];r.verbose&&console.log(`worker: v3Turbo`,`info`,`Turbo continuous call completed.`,{durationInMs:Math.round(performance.now()-s),href:n,songCount:r.total}),self.postMessage({type:`result`,result:u})}catch(e){self.postMessage({type:`error`,error:e})}};