From 71b9b7f23fc1d949162cf89e25158e7c0332b687 Mon Sep 17 00:00:00 2001 From: uh wot Date: Sun, 27 Feb 2022 22:47:15 +0100 Subject: [PATCH] fixed last chunk not being decrypted under certain conditions --- dist/worker.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/worker.js b/dist/worker.js index ff6f4f5..62f93cd 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:({base:t="",routes:e=[]}={})=>({__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"}let g=p["FILESIZE_"+a[i].gw];if(0==g)return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});let d=null,m=null;if(!h&&null!==l){const t=l.match(/^bytes=(\d+)-(\d*)/);null!==t&&(d=parseInt(t[1]),m=parseInt(t[2]))}const y=await r.e(1).then(r.bind(null,9));let w;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"}});w=o.data[0].media[0].sources[0].url}else w=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,y.legacy_stream_url);g=parseInt(g);let b=p.SNG_TITLE;p.VERSION&&(b+=" "+p.VERSION);let v={},A={status:200,headers:{"content-type":a[i].mime,"content-disposition":`inline; filename="${b.replaceAll('"','\\"')} [${e}].${a[i].ext}"`}};h||(A.headers["accept-ranges"]="bytes");let _,T=g,E=g,R=0,S=0;if(null!==d){if(isNaN(m)?m=g:m++,d<0||d>g||mg)return new Response("Range invalid",{status:416,headers:{"content-type":"text/plain"}});R=d%2048,S=2048-m%2048,_=d-R,E=m+S,E>=g&&(E=g,S=0),v={headers:new Headers({range:`bytes=${_}-${E-1}`})},A.status=206,A.headers["content-range"]=`bytes ${d}-${m-1}/${g}`,T=m-d}const P=await fetch(w,v);if(![200,206].includes(P.status))return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});let I;if(h){if(I=new n(t.alloc(0)),I.padding=0,I.setFrame("TIT2",b).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);I.setFrame("TPE1",t)}if(void 0!==p.TRACK_NUMBER&&I.setFrame("TRCK",p.TRACK_NUMBER),void 0!==p.DISK_NUMBER&&I.setFrame("TPOS",p.DISK_NUMBER),""!==p.ISRC&&I.setFrame("TSRC",p.ISRC),void 0!==p.PHYSICAL_RELEASE_DATE){const t=p.PHYSICAL_RELEASE_DATE.split("-");I.setFrame("TYER",t[0]),I.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`,e=await fetch(t),r=await e.arrayBuffer();I.setFrame("APIC",{type:3,data:r,description:"cover"})}I.addTag(),T+=I.arrayBuffer.byteLength}let{readable:U,writable:B}=new FixedLengthStream(T);const L=B.getWriter();h&&L.write(I.arrayBuffer);p.FALLBACK&&(e=p.FALLBACK.SNG_ID);const C=new y.Cipher(String(e));return async function(t,e,r,n,i,a,o){const s=e.getReader({mode:"byob"});let u=0;i&&(u=i);let f=!1;for(;!f;){let e;f=u+2048>=r,e=f?r-u:2048;let i=(await s.readAtLeast(e,new Uint8Array(2048))).value;u%6144!=0||f||n.decrypt_chunk(i),0!==a&&(i=i.slice(a),a=0),f&&0!==o&&(i=i.slice(0,i.length-o)),u+=2048,await t.write(i)}t.close()}(L,P.body,E,C,_,R,S),new Response(U,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:({base:t="",routes:e=[]}={})=>({__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"}let g=p["FILESIZE_"+a[i].gw];if(0==g)return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});let d=null,m=null;if(!h&&null!==l){const t=l.match(/^bytes=(\d+)-(\d*)/);null!==t&&(d=parseInt(t[1]),m=parseInt(t[2]))}const y=await r.e(1).then(r.bind(null,9));let w;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"}});w=o.data[0].media[0].sources[0].url}else w=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,y.legacy_stream_url);g=parseInt(g);let b=p.SNG_TITLE;p.VERSION&&(b+=" "+p.VERSION);let v={},A={status:200,headers:{"content-type":a[i].mime,"content-disposition":`inline; filename="${b.replaceAll('"','\\"')} [${e}].${a[i].ext}"`}};h||(A.headers["accept-ranges"]="bytes");let _,T=g,E=g,R=0,S=0;if(null!==d){if(isNaN(m)?m=g:m++,d<0||d>g||mg)return new Response("Range invalid",{status:416,headers:{"content-type":"text/plain"}});R=d%2048,S=2048-m%2048,_=d-R,E=m+S,E>=g&&(E=g,S=0),v={headers:new Headers({range:`bytes=${_}-${E-1}`})},A.status=206,A.headers["content-range"]=`bytes ${d}-${m-1}/${g}`,T=m-d}const P=await fetch(w,v);if(![200,206].includes(P.status))return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});let I;if(h){if(I=new n(t.alloc(0)),I.padding=0,I.setFrame("TIT2",b).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);I.setFrame("TPE1",t)}if(void 0!==p.TRACK_NUMBER&&I.setFrame("TRCK",p.TRACK_NUMBER),void 0!==p.DISK_NUMBER&&I.setFrame("TPOS",p.DISK_NUMBER),""!==p.ISRC&&I.setFrame("TSRC",p.ISRC),void 0!==p.PHYSICAL_RELEASE_DATE){const t=p.PHYSICAL_RELEASE_DATE.split("-");I.setFrame("TYER",t[0]),I.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`,e=await fetch(t),r=await e.arrayBuffer();I.setFrame("APIC",{type:3,data:r,description:"cover"})}I.addTag(),T+=I.arrayBuffer.byteLength}let{readable:U,writable:B}=new FixedLengthStream(T);const L=B.getWriter();h&&L.write(I.arrayBuffer);p.FALLBACK&&(e=p.FALLBACK.SNG_ID);const C=new y.Cipher(String(e));return async function(t,e,r,n,i,a,o){const s=e.getReader({mode:"byob"});let u=0;i&&(u=i);let f=!1;for(;!f;){let e;f=u+2048>=r,e=f?r-u:2048;let i=(await s.readAtLeast(e,new Uint8Array(2048))).value;u%6144==0&&2048==e&&n.decrypt_chunk(i),0!==a&&(i=i.slice(a),a=0),f&&0!==o&&(i=i.slice(0,i.length-o)),u+=2048,await t.write(i)}t.close()}(L,P.body,E,C,_,R,S),new Response(U,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 5cb501a..e03adcb 100644 --- a/index.js +++ b/index.js @@ -394,7 +394,7 @@ async function pipeDecryptedStream(writer, body, length, cipher, fixed_range_sta let chunk = (await reader.readAtLeast(min_bytes, new Uint8Array(2048))).value - if (byte_count % 6144 === 0 && !end) { + if (byte_count % 6144 === 0 && min_bytes == 2048) { // encrypted chunk cipher.decrypt_chunk(chunk) }