diff --git a/dist/worker.js b/dist/worker.js index 33c0168..43cd694 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 o(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,o),n.l=!0,n.exports}o.e=function(t){var e=[];return e.push(Promise.resolve().then((function(){r[t]||importScripts(o.p+""+t+".worker.js")}))),({1:[11]}[t]||[]).forEach((function(t){var r=n[t];if(r)e.push(r);else{var a,s=i[t](),u=fetch(o.p+""+{11:"a4982acc65fc9945faaa"}[t]+".module.wasm");if(s instanceof Promise&&"function"==typeof WebAssembly.compileStreaming)a=Promise.all([WebAssembly.compileStreaming(u),s]).then((function(t){return WebAssembly.instantiate(t[0],t[1])}));else if("function"==typeof WebAssembly.instantiateStreaming)a=WebAssembly.instantiateStreaming(u,s);else{a=u.then((function(t){return t.arrayBuffer()})).then((function(t){return WebAssembly.instantiate(t,s)}))}e.push(n[t]=a.then((function(e){return o.w[t]=(e.instance||e).exports})))}})),Promise.all(e)},o.m=t,o.c=e,o.d=function(t,e,r){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)o.d(r,n,function(e){return t[e]}.bind(null,n));return r},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o.w={},o(o.s=0)}([function(t,e,r){(function(t){const e=r(6),n=r(7);addEventListener("fetch",t=>{t.respondWith(async function(t){const n=new e;n.get("/",()=>async function(){return new Response(r(8),{status:200,headers:{"content-type":"text/html"}})}()),n.get("/track/-?\\d+",()=>s("track",t)),n.get("/album/\\d+",()=>s("album",t)),n.get("/playlist/\\d+",()=>s("playlist",t));return await n.route(t)}(t.request))});const i={aac_96:"8",64:"10",128:"1",320:"3",flac:"9",mp4_ra1:"13",mp4_ra2:"14",mp4_ra3:"15",mhm1_ra1:"16",mhm1_ra2:"17",mhm1_ra3:"18",sbc_256:"12",misc:"0"},o={aac_96:"AAC_96",64:"MP3_64",128:"MP3_128",320:"MP3_320",flac:"FLAC",mp4_ra1:"MP4_RA1",mp4_ra2:"MP4_RA2",mp4_ra3:"MP4_RA3",mhm1_ra1:"MHM1_RA1",mhm1_ra2:"MHM1_RA2",mhm1_ra3:"MHM1_RA3",sbc_256:"SBC_256",misc:"MP3_MISC"};async function a(t,e){"deezer.getUserData"===t&&(checkForm=""),e||(e={});let r="arl="+ARL;sid&&(r+="; sid="+sid);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=${checkForm}`,n),o=await i.json();return 0!==o.error.length?new Response(JSON.stringify(o.error),{status:500,headers:{"content-type":"application/json"}}):("deezer.getUserData"===t&&(checkForm=o.results.checkForm,await KV.put("checkForm",checkForm),sid=i.headers.get("set-cookie").split(",").map(t=>t.trimStart())[0],sid=sid.match(/^sid=(fr[\da-f]+)/)[1],await KV.put("sid",sid)),o.results)}async function s(e,s){if(license_token=await KV.get("license_token"),checkForm=await KV.get("checkForm"),sid=await KV.get("sid"),null===license_token){const t=await a("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"}});license_token=t.USER.OPTIONS.license_token;const e=t.USER.OPTIONS.expiration_timestamp;await KV.put("license_token",license_token,{expiration:e})}const u=new URL(s.url),f=u.pathname.split("/")[2];if(format=u.searchParams.get("f"),null===format)format="320";else if(format=format.toLowerCase(),void 0===i[format]){if(index=Object.values(i).indexOf(format),-1===index)return new Response("Invalid format",{status:400,headers:{"content-type":"text/plain"}});format=Object.keys(i)[index]}let h=u.searchParams.get("t");switch(h=("true"===h||"1"===h)&&["misc","128","320"].includes(format),e){case"track":return await async function(e,s,u){const f=await a("song.getData",{SNG_ID:e});if("Response"===f.constructor.name)return f;parseInt(f.SNG_ID)<0&&(s="misc");if(0==f["FILESIZE_"+o[s]])return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});const h=await r.e(1).then(r.bind(null,9));if(legacy_url=!["320","flac"].includes(s),legacy_url){if(result=await function(t,e,r){t.FALLBACK&&(t=t.FALLBACK);const n=t.SNG_ID.toString(),o=t.MD5_ORIGIN,a=t.MEDIA_VERSION;return r(o,e=i[e],n,a)}(f,s,h.legacy_stream_url),"object"==typeof result)return result}else{let t;t=void 0!==f.FALLBACK?f.FALLBACK.TRACK_TOKEN:f.TRACK_TOKEN;const e={license_token:license_token,media:[{type:"FULL",formats:[{cipher:"BF_CBC_STRIPE",format:o[s]}]}],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 i=await n.json();result=i.data[0].media[0].sources[0].url}const c=await fetch(result);if(200!==c.status)return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});let l;if(u){if(l=new n(t.alloc(0)),l.padding=0,l.setFrame("TIT2",f.SNG_TITLE).setFrame("TALB",f.ALB_TITLE).setFrame("TPE2",f.ART_NAME),void 0!==f.ARTISTS){artist_list=[];for(const t of f.ARTISTS)artist_list.push(t.ART_NAME);l.setFrame("TPE1",artist_list)}if(void 0!==f.TRACK_NUMBER&&l.setFrame("TRCK",f.TRACK_NUMBER),void 0!==f.DISK_NUMBER&&l.setFrame("TPOS",f.DISK_NUMBER),""!==f.ISRC&&l.setFrame("TSRC",f.ISRC),void 0!==f.PHYSICAL_RELEASE_DATE){const t=f.PHYSICAL_RELEASE_DATE.split("-");l.setFrame("TYER",t[0]),l.setFrame("TDAT",t[2]+t[1])}if(""!==f.ALB_PICTURE){const t=`https://cdns-images.dzcdn.net/images/cover/${f.ALB_PICTURE}/1000x1000-000000-80-0-0.jpg`,e=await fetch(t),r=await e.arrayBuffer();l.setFrame("APIC",{type:3,data:r,description:"cover"})}l.addTag()}let{readable:p,writable:g}=new TransformStream;const d=g.getWriter();u&&d.write(l.arrayBuffer);f.FALLBACK&&(e=f.FALLBACK.SNG_ID);const y=new h.Cipher(e),m=parseInt(c.headers.get("Content-Length"));return async function(t,e,r,n){const i=e.getReader({mode:"byob"});let o=0,a=!1;for(;!a;){let e;a=o+2048>r,e=a?new Int8Array(r-o):new Int8Array(2048);let s=0;for(;s!==e.length;){let t=(await i.read(new Int8Array(e.length-s))).value;e.set(t,s),s+=t.length}o%6144!=0||a||n.decrypt_chunk(e),await t.write(e),o+=2048}await i.cancel(),await t.close()}(d,c.body,m,y),new Response(p,{status:200,headers:{"content-type":"audio/mpeg"}})}(f,format,h);case"album":case"playlist":return await async function(t,e,r,n,i){const o=await fetch(`https://api.deezer.com/${t}/${e}?limit=-1`),a=await o.json();if(void 0!==a.error)return new Response(JSON.stringify(a.error),{status:403,headers:{"content-type":"application/json"}});let s="#EXTM3U\n";for(const t of a.tracks.data){t.id<0&&(r="misc");let e=`https://${i}/track/${t.id}?f=${r}&t=${+n}`;s+=`#EXTINF:${t.duration},${t.title}\n${e}\n`}return new Response(s,{status:200,headers:{"content-type":"audio/mpegurl"}})}(e,f,format,h,u.host)}}}).call(this,r(1).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 o(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,o),n.l=!0,n.exports}o.e=function(t){var e=[];return e.push(Promise.resolve().then((function(){r[t]||importScripts(o.p+""+t+".worker.js")}))),({1:[11]}[t]||[]).forEach((function(t){var r=n[t];if(r)e.push(r);else{var a,s=i[t](),u=fetch(o.p+""+{11:"a4982acc65fc9945faaa"}[t]+".module.wasm");if(s instanceof Promise&&"function"==typeof WebAssembly.compileStreaming)a=Promise.all([WebAssembly.compileStreaming(u),s]).then((function(t){return WebAssembly.instantiate(t[0],t[1])}));else if("function"==typeof WebAssembly.instantiateStreaming)a=WebAssembly.instantiateStreaming(u,s);else{a=u.then((function(t){return t.arrayBuffer()})).then((function(t){return WebAssembly.instantiate(t,s)}))}e.push(n[t]=a.then((function(e){return o.w[t]=(e.instance||e).exports})))}})),Promise.all(e)},o.m=t,o.c=e,o.d=function(t,e,r){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)o.d(r,n,function(e){return t[e]}.bind(null,n));return r},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o.w={},o(o.s=0)}([function(t,e,r){(function(t){const e=r(6),n=r(7);addEventListener("fetch",t=>{t.respondWith(async function(t){const n=new e;n.get("/",()=>async function(){return new Response(r(8),{status:200,headers:{"content-type":"text/html"}})}()),n.get("/track/-?\\d+",()=>s("track",t)),n.get("/album/\\d+",()=>s("album",t)),n.get("/playlist/\\d+",()=>s("playlist",t));return await n.route(t)}(t.request))});const i={aac_96:"8",64:"10",128:"1",320:"3",flac:"9",mp4_ra1:"13",mp4_ra2:"14",mp4_ra3:"15",mhm1_ra1:"16",mhm1_ra2:"17",mhm1_ra3:"18",sbc_256:"12",misc:"0"},o={aac_96:"AAC_96",64:"MP3_64",128:"MP3_128",320:"MP3_320",flac:"FLAC",mp4_ra1:"MP4_RA1",mp4_ra2:"MP4_RA2",mp4_ra3:"MP4_RA3",mhm1_ra1:"MHM1_RA1",mhm1_ra2:"MHM1_RA2",mhm1_ra3:"MHM1_RA3",sbc_256:"SBC_256",misc:"MP3_MISC"};async function a(t,e){"deezer.getUserData"===t&&(checkForm=""),e||(e={});let r="arl="+ARL;sid&&(r+="; sid="+sid);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(checkForm)}&cid=${Math.floor(1e9*Math.random())}`,n),o=await i.json();return 0!==o.error.length?new Response(JSON.stringify(o.error),{status:500,headers:{"content-type":"application/json"}}):("deezer.getUserData"===t&&(checkForm=o.results.checkForm,await KV.put("checkForm",checkForm),sid=i.headers.get("set-cookie").split(",").map(t=>t.trimStart())[0],sid=sid.match(/^sid=(fr[\da-f]+)/)[1],await KV.put("sid",sid)),o.results)}async function s(e,s){if(license_token=await KV.get("license_token"),checkForm=await KV.get("checkForm"),sid=await KV.get("sid"),null===license_token){const t=await a("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"}});license_token=t.USER.OPTIONS.license_token;const e=t.USER.OPTIONS.expiration_timestamp;await KV.put("license_token",license_token,{expiration:e})}const u=new URL(s.url),f=u.pathname.split("/")[2];if(format=u.searchParams.get("f"),null===format)format="320";else if(format=format.toLowerCase(),void 0===i[format]){if(index=Object.values(i).indexOf(format),-1===index)return new Response("Invalid format",{status:400,headers:{"content-type":"text/plain"}});format=Object.keys(i)[index]}let h=u.searchParams.get("t");switch(h=("true"===h||"1"===h)&&["misc","128","320"].includes(format),e){case"track":return await async function(e,s,u){const f=await a("song.getData",{SNG_ID:e});if("Response"===f.constructor.name)return f;parseInt(f.SNG_ID)<0&&(s="misc");if(0==f["FILESIZE_"+o[s]])return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});const h=await r.e(1).then(r.bind(null,9));if(legacy_url=!["320","flac"].includes(s),legacy_url){if(result=await function(t,e,r){t.FALLBACK&&(t=t.FALLBACK);const n=t.SNG_ID.toString(),o=t.MD5_ORIGIN,a=t.MEDIA_VERSION;return r(o,e=i[e],n,a)}(f,s,h.legacy_stream_url),"object"==typeof result)return result}else{let t;t=void 0!==f.FALLBACK?f.FALLBACK.TRACK_TOKEN:f.TRACK_TOKEN;const e={license_token:license_token,media:[{type:"FULL",formats:[{cipher:"BF_CBC_STRIPE",format:o[s]}]}],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 i=await n.json();result=i.data[0].media[0].sources[0].url}const c=await fetch(result);if(200!==c.status)return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});let l;if(u){if(l=new n(t.alloc(0)),l.padding=0,l.setFrame("TIT2",f.SNG_TITLE).setFrame("TALB",f.ALB_TITLE).setFrame("TPE2",f.ART_NAME),void 0!==f.ARTISTS){artist_list=[];for(const t of f.ARTISTS)artist_list.push(t.ART_NAME);l.setFrame("TPE1",artist_list)}if(void 0!==f.TRACK_NUMBER&&l.setFrame("TRCK",f.TRACK_NUMBER),void 0!==f.DISK_NUMBER&&l.setFrame("TPOS",f.DISK_NUMBER),""!==f.ISRC&&l.setFrame("TSRC",f.ISRC),void 0!==f.PHYSICAL_RELEASE_DATE){const t=f.PHYSICAL_RELEASE_DATE.split("-");l.setFrame("TYER",t[0]),l.setFrame("TDAT",t[2]+t[1])}if(""!==f.ALB_PICTURE){const t=`https://cdns-images.dzcdn.net/images/cover/${f.ALB_PICTURE}/1000x1000-000000-80-0-0.jpg`,e=await fetch(t),r=await e.arrayBuffer();l.setFrame("APIC",{type:3,data:r,description:"cover"})}l.addTag()}let{readable:p,writable:g}=new TransformStream;const d=g.getWriter();u&&d.write(l.arrayBuffer);f.FALLBACK&&(e=f.FALLBACK.SNG_ID);const y=new h.Cipher(e),m=parseInt(c.headers.get("Content-Length"));return async function(t,e,r,n){const i=e.getReader({mode:"byob"});let o=0,a=!1;for(;!a;){let e;a=o+2048>r,e=a?new Int8Array(r-o):new Int8Array(2048);let s=0;for(;s!==e.length;){let t=(await i.read(new Int8Array(e.length-s))).value;e.set(t,s),s+=t.length}o%6144!=0||a||n.decrypt_chunk(e),await t.write(e),o+=2048}await i.cancel(),await t.close()}(d,c.body,m,y),new Response(p,{status:200,headers:{"content-type":"audio/mpeg"}})}(f,format,h);case"album":case"playlist":return await async function(t,e,r,n,i){const o=await fetch(`https://api.deezer.com/${t}/${e}?limit=-1`),a=await o.json();if(void 0!==a.error)return new Response(JSON.stringify(a.error),{status:403,headers:{"content-type":"application/json"}});let s="#EXTM3U\n";for(const t of a.tracks.data){t.id<0&&(r="misc");let e=`https://${i}/track/${t.id}?f=${r}&t=${+n}`;s+=`#EXTINF:${t.duration},${t.title}\n${e}\n`}return new Response(s,{status:200,headers:{"content-type":"audio/mpegurl"}})}(e,f,format,h,u.host)}}}).call(this,r(1).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 b182ebb..bf8aba7 100644 --- a/index.js +++ b/index.js @@ -59,7 +59,7 @@ async function gw_api_call(method, params) { body: JSON.stringify(params), } - const response = await fetch(`https://www.deezer.com/ajax/gw-light.php?method=${method}&input=3&api_version=1.0&api_token=${checkForm}`, init) + const response = await fetch(`https://www.deezer.com/ajax/gw-light.php?method=${method}&input=3&api_version=1.0&api_token=${encodeURIComponent(checkForm)}&cid=${Math.floor(Math.random() * 1e9)}`, init) const json = await response.json() if (json.error.length !== 0) {