From 80c9ddf1bb2eaf295d425294d7832810cfdbe36c Mon Sep 17 00:00:00 2001 From: uh wot Date: Tue, 29 Mar 2022 23:08:47 +0200 Subject: [PATCH] fixed mime type on aac_96, updated dependencies, updated compat date --- dist/worker.js | 2 +- index.js | 2 +- package.json | 4 ++-- wrangler.toml | 2 +- yarn.lock | 16 ++++++++-------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dist/worker.js b/dist/worker.js index da55073..f865413 100644 --- a/dist/worker.js +++ b/dist/worker.js @@ -1,4 +1,4 @@ -!function(t){self.webpackChunk=function(e,n){for(var i in n)t[i]=n[i];for(;e.length;)r[e.pop()]=1};var e={},r={0:1},n={};var i={11:function(){return{"./index_bg.js":{__wbindgen_throw:function(t,r){return e[10].exports.b(t,r)}}}}};function a(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.e=function(t){var e=[];return e.push(Promise.resolve().then((function(){r[t]||importScripts(a.p+""+t+".worker.js")}))),({1:[11]}[t]||[]).forEach((function(t){var r=n[t];if(r)e.push(r);else{var o,s=i[t](),u=fetch(a.p+""+{11:"d80733de3401ff78c096"}[t]+".module.wasm");if(s instanceof Promise&&"function"==typeof WebAssembly.compileStreaming)o=Promise.all([WebAssembly.compileStreaming(u),s]).then((function(t){return WebAssembly.instantiate(t[0],t[1])}));else if("function"==typeof WebAssembly.instantiateStreaming)o=WebAssembly.instantiateStreaming(u,s);else{o=u.then((function(t){return t.arrayBuffer()})).then((function(t){return WebAssembly.instantiate(t,s)}))}e.push(n[t]=o.then((function(e){return a.w[t]=(e.instance||e).exports})))}})),Promise.all(e)},a.m=t,a.c=e,a.d=function(t,e,r){a.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},a.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},a.t=function(t,e){if(1&e&&(t=a(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)a.d(r,n,function(e){return t[e]}.bind(null,n));return r},a.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return a.d(e,"a",e),e},a.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},a.p="",a.w={},a(a.s=1)}([function(t,e){t.exports={Router:function({base:t="",routes:e=[]}={}){return{__proto__:new Proxy({},{get:(r,n,i)=>(r,...a)=>e.push([n.toUpperCase(),RegExp(`^${(t+r).replace(/(\/?)\*/g,"($1.*)?").replace(/\/$/,"").replace(/:(\w+)(\?)?(\.)?/g,"$2(?<$1>[^/]+)$2$3").replace(/\.(?=[\w(])/,"\\.").replace(/\)\.\?\(([^\[]+)\[\^/g,"?)\\.?($1(?<=\\.)[^\\.")}/*$`),a])&&i}),routes:e,async handle(t,...r){let n,i,a=new URL(t.url);for(var[o,s,u]of(t.query=Object.fromEntries(a.searchParams),e))if((o===t.method||"ALL"===o)&&(i=a.pathname.match(s)))for(var f of(t.params=i.groups,u))if(void 0!==(n=await f(t.proxy||t,...r)))return n}}}}},function(t,e,r){"use strict";r.r(e),function(t){var e=r(0);const n=r(7),i=Object(e.Router)(),a={aac_96:{num:"8",gw:"AAC_96",mime:"audio/aac",ext:"3gp"},64:{num:"10",gw:"MP3_64",mime:"audio/mpeg",ext:"mp3"},128:{num:"1",gw:"MP3_128",mime:"audio/mpeg",ext:"mp3"},320:{num:"3",gw:"MP3_320",mime:"audio/mpeg",ext:"mp3"},flac:{num:"9",gw:"FLAC",mime:"audio/flac",ext:"flac"},mp4_ra1:{num:"13",gw:"MP4_RA1",mime:"audio/mp4",ext:"mp4"},mp4_ra2:{num:"14",gw:"MP4_RA2",mime:"audio/mp4",ext:"mp4"},mp4_ra3:{num:"15",gw:"MP4_RA3",mime:"audio/mp4",ext:"mp4"},mhm1_ra1:{num:"16",gw:"MHM1_RA1",mime:"audio/mp4",ext:"mp4"},mhm1_ra2:{num:"17",gw:"MHM1_RA2",mime:"audio/mp4",ext:"mp4"},mhm1_ra3:{num:"18",gw:"MHM1_RA3",mime:"audio/mp4",ext:"mp4"},sbc_256:{num:"12",gw:"SBC_256",mime:"",ext:"sbc"},misc:{num:"0",gw:"MP3_MISC",mime:"audio/mpeg",ext:"mp3"}};async function o(t,e){"deezer.getUserData"===t&&(u=""),e||(e={});let r="arl="+ARL;f&&(r+="; sid="+f);const n={method:"POST",headers:new Headers({cookie:r}),body:JSON.stringify(e)},i=await fetch(`https://www.deezer.com/ajax/gw-light.php?method=${t}&input=3&api_version=1.0&api_token=${encodeURIComponent(u)}&cid=${Math.floor(1e9*Math.random())}`,n),a=await i.json();return 0!==a.error.length?new Response(JSON.stringify(a.error),{status:500,headers:{"content-type":"application/json"}}):("deezer.getUserData"===t&&(u=a.results.checkForm,await KV.put("checkForm",u),f=i.headers.get("set-cookie").split(",").map(t=>t.trimStart())[0],f=f.match(/^sid=(fr[\da-f]+)/)[1],await KV.put("sid",f)),a.results)}let s,u,f,c;i.get("/:type/:id",async e=>{const{query:i}=e;let{type:h,id:l}=e.params;if(!["track","album","playlist"].includes(h))return new Response("not found",{status:404,headers:{"content-type":"text/plain"}});if(l=parseInt(l),NaN===l||"track"!==h&&l<0)return new Response("Invalid ID",{status:400,headers:{"content-type":"text/plain"}});let p=i.f;if(void 0===p)p="320";else if(p=p.toLowerCase(),void 0===a[p]){let t=[];Object.values(a).forEach(e=>t.push(e.num));let e=t.indexOf(p);if(-1===e)return new Response("Invalid format",{status:400,headers:{"content-type":"text/plain"}});p=Object.keys(a)[e]}let g=i.t;switch(g=("true"===g||"1"===g)&&(["misc","128","320"].includes(p)||"track"!==h),h){case"track":return await async function(e,i,h,l){let p;if(e>=0){let t=await async function(){if(s=await KV.get("license_token"),u=await KV.get("checkForm"),f=await KV.get("sid"),null===s){const t=await o("deezer.getUserData");if("Response"===t.constructor.name)return t;if(0===t.USER.USER_ID)return new Response("Invalid arl",{status:500,headers:{"content-type":"text/plain"}});s=t.USER.OPTIONS.license_token,await KV.put("license_token",s,{expirationTtl:3600})}}();if(t)return t;if(p=await o("song.getData",{SNG_ID:e}),"Response"===p.constructor.name)return p}else{let t=await async function(){if(c=await KV.get("access_token"),null===c){const t=await fetch("https://connect.deezer.com/oauth/access_token.php?grant_type=client_credentials&client_id=447462&client_secret=a83bf7f38ad2f137e444727cfc3775cf&output=json"),e=await t.json();if(void 0!==e.error)return new Response("Couldn't get access token from Deezer",{status:500,headers:{"content-type":"text/plain"}});c=e.access_token,await KV.put("access_token",c,{expirationTtl:parseInt(e.expires)})}}();if(t)return t;const r=await fetch(`https://api.deezer.com/track/${e}?access_token=${c}`);if(p=await r.json(),void 0!==p.error)return new Response(JSON.stringify(p.error),{status:403,headers:{"content-type":"application/json"}});p={SNG_ID:p.id,FILESIZE_MP3_MISC:p.filesize_misc,SNG_TITLE:p.title,ALB_TITLE:p.album.title,ART_NAME:p.artist.name,ARTISTS:[{ART_NAME:p.artist.name}],ISRC:"",ALB_PICTURE:p.md5_image,MD5_ORIGIN:p.md5_origin,MEDIA_VERSION:p.media_version},i="misc"}if(0==p["FILESIZE_"+a[i].gw])return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});let g=null,d=null;if(null!==l){const t=l.match(/^bytes=(\d+)-(\d*)/);null!==t&&(g=parseInt(t[1]),d=parseInt(t[2]))}const m=await r.e(1).then(r.bind(null,9));let y;if(["320","flac"].includes(i)){let t;t=void 0!==p.FALLBACK?p.FALLBACK.TRACK_TOKEN:p.TRACK_TOKEN;const e={license_token:s,media:[{type:"FULL",formats:[{cipher:"BF_CBC_STRIPE",format:a[i].gw}]}],track_tokens:[t]},r={method:"POST",body:JSON.stringify(e)},n=await fetch("https://media.deezer.com/v1/get_url",r);if(200!==n.status)return new Response("Couldn't get stream URL",{status:403,headers:{"content-type":"text/plain"}});const o=await n.json();if(void 0===o.data[0].media)return new Response("Couldn't get stream URL",{status:403,headers:{"content-type":"text/plain"}});y=o.data[0].media[0].sources[0].url}else y=await function(t,e,r){t.FALLBACK&&(t=t.FALLBACK);const n=t.SNG_ID.toString(),i=t.MD5_ORIGIN,o=t.MEDIA_VERSION;return e=a[e].num,r(i,e,n,o)}(p,i,m.legacy_stream_url);let w=p.SNG_TITLE;p.VERSION&&(w+=" "+p.VERSION);let b,v={},A={status:200,headers:{"content-type":a[i].mime,"content-disposition":`inline; filename="${w.replaceAll('"','\\"')} [${e}].${a[i].ext}"`,"accept-ranges":"bytes"}},_=await fetch(y,{method:"HEAD"});if(200!==_.status)return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});b=parseInt(_.headers.get("content-length"));let E,T=b;if(h){let e=new n(t.alloc(0));if(e.padding=0,e.setFrame("TIT2",w).setFrame("TALB",p.ALB_TITLE).setFrame("TPE2",p.ART_NAME),void 0!==p.ARTISTS){let t=[];for(const e of p.ARTISTS)t.push(e.ART_NAME);e.setFrame("TPE1",t)}if(void 0!==p.TRACK_NUMBER&&e.setFrame("TRCK",p.TRACK_NUMBER),void 0!==p.DISK_NUMBER&&e.setFrame("TPOS",p.DISK_NUMBER),""!==p.ISRC&&e.setFrame("TSRC",p.ISRC),void 0!==p.PHYSICAL_RELEASE_DATE){const t=p.PHYSICAL_RELEASE_DATE.split("-");e.setFrame("TYER",t[0]),e.setFrame("TDAT",t[2]+t[1])}if(""!==p.ALB_PICTURE){const t=`https://cdns-images.dzcdn.net/images/cover/${p.ALB_PICTURE}/1000x1000-000000-80-0-0.jpg`,r=await fetch(t),n=await r.arrayBuffer();e.setFrame("APIC",{type:3,data:n,description:"cover"})}e.addTag(),E=e.arrayBuffer,T+=E.byteLength}let R,S=!1,P=!1,I=0,U=b,B=0,L=0;if(null!==g){if(isNaN(d)?d=T:d++,g<0||g>T||dT)return new Response("Range invalid",{status:416,headers:{"content-type":"text/plain"}});let t=g,e=d;if(h){let t=E.byteLength;if(g=b&&(U=b,L=0),v={headers:new Headers({range:`bytes=${I}-${U-1}`})}),A.status=206,A.headers["content-range"]=`bytes ${t}-${e-1}/${T}`,T=e-t}if(!P&&(R=await fetch(y,v),![200,206].includes(R.status)))return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});let{readable:C,writable:O}=new FixedLengthStream(T);const M=O.getWriter();h&&!S&&M.write(E);if(P)M.close();else{p.FALLBACK&&(e=p.FALLBACK.SNG_ID);const t=new m.Cipher(String(e));!async function(t,e,r,n,i,a,o){const s=e.getReader({mode:"byob"});let u=i,f=!1;for(;!f;){f=u+2048>=r;let e=(await s.readAtLeast(2048,new Uint8Array(2048))).value;u%6144==0&&2048==e.byteLength&&n.decrypt_chunk(e),0!==a&&(e=e.slice(a),a=0),f&&0!==o&&(e=e.slice(0,e.byteLength-o)),t.write(e),u+=2048}t.close()}(M,R.body,U,t,I,B,L)}return new Response(C,A)}(l,p,g,e.headers.get("range"));case"album":case"playlist":return await async function(t,e,r,n,i){const a=await fetch(`https://api.deezer.com/${t}/${e}?limit=-1`),o=await a.json();if(void 0!==o.error)return new Response(JSON.stringify(o.error),{status:403,headers:{"content-type":"application/json"}});let s="#EXTM3U\n";for(const t of o.tracks.data){let e=r;t.id<0&&(e="misc");let a=`https://${i}/track/${t.id}?f=${e}&t=${+n}`;s+=`#EXTINF:${t.duration},${t.title}\n${a}\n`}return new Response(s,{status:200,headers:{"content-type":"audio/mpegurl"}})}(h,l,p,g,e.headers.get("host"))}}),i.get("/",()=>new Response(r(8),{status:200,headers:{"content-type":"text/html"}})),i.all("*",()=>new Response("not found",{status:404,headers:{"content-type":"text/plain"}})),addEventListener("fetch",t=>t.respondWith(i.handle(t.request)))}.call(this,r(2).Buffer)},function(t,e,r){"use strict";(function(t){ +!function(t){self.webpackChunk=function(e,n){for(var i in n)t[i]=n[i];for(;e.length;)r[e.pop()]=1};var e={},r={0:1},n={};var i={11:function(){return{"./index_bg.js":{__wbindgen_throw:function(t,r){return e[10].exports.b(t,r)}}}}};function a(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.e=function(t){var e=[];return e.push(Promise.resolve().then((function(){r[t]||importScripts(a.p+""+t+".worker.js")}))),({1:[11]}[t]||[]).forEach((function(t){var r=n[t];if(r)e.push(r);else{var o,s=i[t](),u=fetch(a.p+""+{11:"d80733de3401ff78c096"}[t]+".module.wasm");if(s instanceof Promise&&"function"==typeof WebAssembly.compileStreaming)o=Promise.all([WebAssembly.compileStreaming(u),s]).then((function(t){return WebAssembly.instantiate(t[0],t[1])}));else if("function"==typeof WebAssembly.instantiateStreaming)o=WebAssembly.instantiateStreaming(u,s);else{o=u.then((function(t){return t.arrayBuffer()})).then((function(t){return WebAssembly.instantiate(t,s)}))}e.push(n[t]=o.then((function(e){return a.w[t]=(e.instance||e).exports})))}})),Promise.all(e)},a.m=t,a.c=e,a.d=function(t,e,r){a.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},a.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},a.t=function(t,e){if(1&e&&(t=a(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)a.d(r,n,function(e){return t[e]}.bind(null,n));return r},a.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return a.d(e,"a",e),e},a.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},a.p="",a.w={},a(a.s=1)}([function(t,e){t.exports={Router:function({base:t="",routes:e=[]}={}){return{__proto__:new Proxy({},{get:(r,n,i)=>(r,...a)=>e.push([n.toUpperCase(),RegExp(`^${(t+r).replace(/(\/?)\*/g,"($1.*)?").replace(/\/$/,"").replace(/:(\w+)(\?)?(\.)?/g,"$2(?<$1>[^/]+)$2$3").replace(/\.(?=[\w(])/,"\\.").replace(/\)\.\?\(([^\[]+)\[\^/g,"?)\\.?($1(?<=\\.)[^\\.")}/*$`),a])&&i}),routes:e,async handle(t,...r){let n,i,a=new URL(t.url);for(var[o,s,u]of(t.query=Object.fromEntries(a.searchParams),e))if((o===t.method||"ALL"===o)&&(i=a.pathname.match(s)))for(var f of(t.params=i.groups,u))if(void 0!==(n=await f(t.proxy||t,...r)))return n}}}}},function(t,e,r){"use strict";r.r(e),function(t){var e=r(0);const n=r(7),i=Object(e.Router)(),a={aac_96:{num:"8",gw:"AAC_96",mime:"audio/3gpp",ext:"3gp"},64:{num:"10",gw:"MP3_64",mime:"audio/mpeg",ext:"mp3"},128:{num:"1",gw:"MP3_128",mime:"audio/mpeg",ext:"mp3"},320:{num:"3",gw:"MP3_320",mime:"audio/mpeg",ext:"mp3"},flac:{num:"9",gw:"FLAC",mime:"audio/flac",ext:"flac"},mp4_ra1:{num:"13",gw:"MP4_RA1",mime:"audio/mp4",ext:"mp4"},mp4_ra2:{num:"14",gw:"MP4_RA2",mime:"audio/mp4",ext:"mp4"},mp4_ra3:{num:"15",gw:"MP4_RA3",mime:"audio/mp4",ext:"mp4"},mhm1_ra1:{num:"16",gw:"MHM1_RA1",mime:"audio/mp4",ext:"mp4"},mhm1_ra2:{num:"17",gw:"MHM1_RA2",mime:"audio/mp4",ext:"mp4"},mhm1_ra3:{num:"18",gw:"MHM1_RA3",mime:"audio/mp4",ext:"mp4"},sbc_256:{num:"12",gw:"SBC_256",mime:"",ext:"sbc"},misc:{num:"0",gw:"MP3_MISC",mime:"audio/mpeg",ext:"mp3"}};async function o(t,e){"deezer.getUserData"===t&&(u=""),e||(e={});let r="arl="+ARL;f&&(r+="; sid="+f);const n={method:"POST",headers:new Headers({cookie:r}),body:JSON.stringify(e)},i=await fetch(`https://www.deezer.com/ajax/gw-light.php?method=${t}&input=3&api_version=1.0&api_token=${encodeURIComponent(u)}&cid=${Math.floor(1e9*Math.random())}`,n),a=await i.json();return 0!==a.error.length?new Response(JSON.stringify(a.error),{status:500,headers:{"content-type":"application/json"}}):("deezer.getUserData"===t&&(u=a.results.checkForm,await KV.put("checkForm",u),f=i.headers.get("set-cookie").split(",").map(t=>t.trimStart())[0],f=f.match(/^sid=(fr[\da-f]+)/)[1],await KV.put("sid",f)),a.results)}let s,u,f,c;i.get("/:type/:id",async e=>{const{query:i}=e;let{type:h,id:l}=e.params;if(!["track","album","playlist"].includes(h))return new Response("not found",{status:404,headers:{"content-type":"text/plain"}});if(l=parseInt(l),NaN===l||"track"!==h&&l<0)return new Response("Invalid ID",{status:400,headers:{"content-type":"text/plain"}});let p=i.f;if(void 0===p)p="320";else if(p=p.toLowerCase(),void 0===a[p]){let t=[];Object.values(a).forEach(e=>t.push(e.num));let e=t.indexOf(p);if(-1===e)return new Response("Invalid format",{status:400,headers:{"content-type":"text/plain"}});p=Object.keys(a)[e]}let g=i.t;switch(g=("true"===g||"1"===g)&&(["misc","128","320"].includes(p)||"track"!==h),h){case"track":return await async function(e,i,h,l){let p;if(e>=0){let t=await async function(){if(s=await KV.get("license_token"),u=await KV.get("checkForm"),f=await KV.get("sid"),null===s){const t=await o("deezer.getUserData");if("Response"===t.constructor.name)return t;if(0===t.USER.USER_ID)return new Response("Invalid arl",{status:500,headers:{"content-type":"text/plain"}});s=t.USER.OPTIONS.license_token,await KV.put("license_token",s,{expirationTtl:3600})}}();if(t)return t;if(p=await o("song.getData",{SNG_ID:e}),"Response"===p.constructor.name)return p}else{let t=await async function(){if(c=await KV.get("access_token"),null===c){const t=await fetch("https://connect.deezer.com/oauth/access_token.php?grant_type=client_credentials&client_id=447462&client_secret=a83bf7f38ad2f137e444727cfc3775cf&output=json"),e=await t.json();if(void 0!==e.error)return new Response("Couldn't get access token from Deezer",{status:500,headers:{"content-type":"text/plain"}});c=e.access_token,await KV.put("access_token",c,{expirationTtl:parseInt(e.expires)})}}();if(t)return t;const r=await fetch(`https://api.deezer.com/track/${e}?access_token=${c}`);if(p=await r.json(),void 0!==p.error)return new Response(JSON.stringify(p.error),{status:403,headers:{"content-type":"application/json"}});p={SNG_ID:p.id,FILESIZE_MP3_MISC:p.filesize_misc,SNG_TITLE:p.title,ALB_TITLE:p.album.title,ART_NAME:p.artist.name,ARTISTS:[{ART_NAME:p.artist.name}],ISRC:"",ALB_PICTURE:p.md5_image,MD5_ORIGIN:p.md5_origin,MEDIA_VERSION:p.media_version},i="misc"}if(0==p["FILESIZE_"+a[i].gw])return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});let g=null,d=null;if(null!==l){const t=l.match(/^bytes=(\d+)-(\d*)/);null!==t&&(g=parseInt(t[1]),d=parseInt(t[2]))}const m=await r.e(1).then(r.bind(null,9));let y;if(["320","flac"].includes(i)){let t;t=void 0!==p.FALLBACK?p.FALLBACK.TRACK_TOKEN:p.TRACK_TOKEN;const e={license_token:s,media:[{type:"FULL",formats:[{cipher:"BF_CBC_STRIPE",format:a[i].gw}]}],track_tokens:[t]},r={method:"POST",body:JSON.stringify(e)},n=await fetch("https://media.deezer.com/v1/get_url",r);if(200!==n.status)return new Response("Couldn't get stream URL",{status:403,headers:{"content-type":"text/plain"}});const o=await n.json();if(void 0===o.data[0].media)return new Response("Couldn't get stream URL",{status:403,headers:{"content-type":"text/plain"}});y=o.data[0].media[0].sources[0].url}else y=await function(t,e,r){t.FALLBACK&&(t=t.FALLBACK);const n=t.SNG_ID.toString(),i=t.MD5_ORIGIN,o=t.MEDIA_VERSION;return e=a[e].num,r(i,e,n,o)}(p,i,m.legacy_stream_url);let w=p.SNG_TITLE;p.VERSION&&(w+=" "+p.VERSION);let b,v={},A={status:200,headers:{"content-type":a[i].mime,"content-disposition":`inline; filename="${w.replaceAll('"','\\"')} [${e}].${a[i].ext}"`,"accept-ranges":"bytes"}},_=await fetch(y,{method:"HEAD"});if(200!==_.status)return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});b=parseInt(_.headers.get("content-length"));let E,T=b;if(h){let e=new n(t.alloc(0));if(e.padding=0,e.setFrame("TIT2",w).setFrame("TALB",p.ALB_TITLE).setFrame("TPE2",p.ART_NAME),void 0!==p.ARTISTS){let t=[];for(const e of p.ARTISTS)t.push(e.ART_NAME);e.setFrame("TPE1",t)}if(void 0!==p.TRACK_NUMBER&&e.setFrame("TRCK",p.TRACK_NUMBER),void 0!==p.DISK_NUMBER&&e.setFrame("TPOS",p.DISK_NUMBER),""!==p.ISRC&&e.setFrame("TSRC",p.ISRC),void 0!==p.PHYSICAL_RELEASE_DATE){const t=p.PHYSICAL_RELEASE_DATE.split("-");e.setFrame("TYER",t[0]),e.setFrame("TDAT",t[2]+t[1])}if(""!==p.ALB_PICTURE){const t=`https://cdns-images.dzcdn.net/images/cover/${p.ALB_PICTURE}/1000x1000-000000-80-0-0.jpg`,r=await fetch(t),n=await r.arrayBuffer();e.setFrame("APIC",{type:3,data:n,description:"cover"})}e.addTag(),E=e.arrayBuffer,T+=E.byteLength}let R,S=!1,P=!1,I=0,U=b,B=0,L=0;if(null!==g){if(isNaN(d)?d=T:d++,g<0||g>T||dT)return new Response("Range invalid",{status:416,headers:{"content-type":"text/plain"}});let t=g,e=d;if(h){let t=E.byteLength;if(g=b&&(U=b,L=0),v={headers:new Headers({range:`bytes=${I}-${U-1}`})}),A.status=206,A.headers["content-range"]=`bytes ${t}-${e-1}/${T}`,T=e-t}if(!P&&(R=await fetch(y,v),![200,206].includes(R.status)))return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});let{readable:C,writable:O}=new FixedLengthStream(T);const M=O.getWriter();h&&!S&&M.write(E);if(P)M.close();else{p.FALLBACK&&(e=p.FALLBACK.SNG_ID);const t=new m.Cipher(String(e));!async function(t,e,r,n,i,a,o){const s=e.getReader({mode:"byob"});let u=i,f=!1;for(;!f;){f=u+2048>=r;let e=(await s.readAtLeast(2048,new Uint8Array(2048))).value;u%6144==0&&2048==e.byteLength&&n.decrypt_chunk(e),0!==a&&(e=e.slice(a),a=0),f&&0!==o&&(e=e.slice(0,e.byteLength-o)),t.write(e),u+=2048}t.close()}(M,R.body,U,t,I,B,L)}return new Response(C,A)}(l,p,g,e.headers.get("range"));case"album":case"playlist":return await async function(t,e,r,n,i){const a=await fetch(`https://api.deezer.com/${t}/${e}?limit=-1`),o=await a.json();if(void 0!==o.error)return new Response(JSON.stringify(o.error),{status:403,headers:{"content-type":"application/json"}});let s="#EXTM3U\n";for(const t of o.tracks.data){let e=r;t.id<0&&(e="misc");let a=`https://${i}/track/${t.id}?f=${e}&t=${+n}`;s+=`#EXTINF:${t.duration},${t.title}\n${a}\n`}return new Response(s,{status:200,headers:{"content-type":"audio/mpegurl"}})}(h,l,p,g,e.headers.get("host"))}}),i.get("/",()=>new Response(r(8),{status:200,headers:{"content-type":"text/html"}})),i.all("*",()=>new Response("not found",{status:404,headers:{"content-type":"text/plain"}})),addEventListener("fetch",t=>t.respondWith(i.handle(t.request)))}.call(this,r(2).Buffer)},function(t,e,r){"use strict";(function(t){ /*! * The buffer module from node.js, for the browser. * diff --git a/index.js b/index.js index b59cd7c..cb49a4b 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ const client_id = "447462" const client_secret = "a83bf7f38ad2f137e444727cfc3775cf" const formats = { - aac_96: { num: '8', gw: 'AAC_96', mime: 'audio/aac', ext: '3gp' }, + aac_96: { num: '8', gw: 'AAC_96', mime: 'audio/3gpp', ext: '3gp' }, 64: { num: '10', gw: 'MP3_64', mime: 'audio/mpeg', ext: 'mp3' }, 128: { num: '1', gw: 'MP3_128', mime: 'audio/mpeg', ext: 'mp3' }, 320: { num: '3', gw: 'MP3_320', mime: 'audio/mpeg', ext: 'mp3' }, diff --git a/package.json b/package.json index 7a112b8..cf9ff68 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,11 @@ "devDependencies": { "@wasm-tool/wasm-pack-plugin": "^1.6.0", "html-loader": "^1.3.2", - "prettier": "^2.5.1" + "prettier": "^2.6.1" }, "dependencies": { "browser-id3-writer": "^4.4.0", - "itty-router": "^2.5.2", + "itty-router": "^2.6.1", "serverless-cloudflare-workers": "^1.2.0" } } diff --git a/wrangler.toml b/wrangler.toml index f748dd9..c56d90a 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -6,7 +6,7 @@ workers_dev = true kv_namespaces = [ { binding = "KV", id = "974c0967a84e415daa054bbbcc7f80c6", preview_id = "cfcc6491f3484cbca664913836635113" } ] -compatibility_date = "2022-03-09" +compatibility_date = "2022-03-29" # [secrets] # ARL \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index b2bdc6a..6fdf302 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1462,10 +1462,10 @@ isobject@^3.0.0, isobject@^3.0.1: resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8= -itty-router@^2.5.2: - version "2.5.2" - resolved "https://registry.yarnpkg.com/itty-router/-/itty-router-2.5.2.tgz#296e2db945e8f75a47fa9ffe16eecb30a6551a77" - integrity sha512-igVdp/qoMe7aMnwB1eI9OCgV9HGyQlQ9LBDWPMSDkoYv7SpcxZp0t86noQcXKCSVK2B7y7z8d5SiaNbRMLUIyg== +itty-router@^2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/itty-router/-/itty-router-2.6.1.tgz#eecb59fa25b5f6f519276cc5bcaaa1cb341d5fee" + integrity sha512-l9gxWe5TOLUESYnBn85Jxd6tIZLWdRX5YKkHIBfSgbNQ7UFPNUGuWihRV+LlEbfJJIzgLmhwAbaWRi5yWJm8kg== json-parse-better-errors@^1.0.2: version "1.0.2" @@ -1962,10 +1962,10 @@ posix-character-classes@^0.1.0: resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab" integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs= -prettier@^2.5.1: - version "2.5.1" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a" - integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg== +prettier@^2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.1.tgz#d472797e0d7461605c1609808e27b80c0f9cfe17" + integrity sha512-8UVbTBYGwN37Bs9LERmxCPjdvPxlEowx2urIL6urHzdb3SDq4B/Z6xLFCblrSnE4iKWcS6ziJ3aOYrc1kz/E2A== process-nextick-args@~2.0.0: version "2.0.1"