diff --git a/dist/worker.js b/dist/worker.js index 574f5b0..e4891ae 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+",()=>a("track",t)),n.get("/album/\\d+",()=>a("album",t)),n.get("/playlist/\\d+",()=>a("playlist",t));return await n.route(t)}(t.request))});const i={aac_96:{num:"8",gw:"AAC_96",mime:"audio/aac"},64:{num:"10",gw:"MP3_64",mime:"audio/mpeg"},128:{num:"1",gw:"MP3_128",mime:"audio/mpeg"},320:{num:"3",gw:"MP3_320",mime:"audio/mpeg"},flac:{num:"9",gw:"FLAC",mime:"audio/flac"},mp4_ra1:{num:"13",gw:"MP4_RA1",mime:"audio/mp4"},mp4_ra2:{num:"14",gw:"MP4_RA2",mime:"audio/mp4"},mp4_ra3:{num:"15",gw:"MP4_RA3",mime:"audio/mp4"},mhm1_ra1:{num:"16",gw:"MHM1_RA1",mime:"audio/mp4"},mhm1_ra2:{num:"17",gw:"MHM1_RA2",mime:"audio/mp4"},mhm1_ra3:{num:"18",gw:"MHM1_RA3",mime:"audio/mp4"},sbc_256:{num:"12",gw:"SBC_256",mime:""},misc:{num:"0",gw:"MP3_MISC",mime:"audio/mpeg"}};async function o(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 a(e,a){if(license_token=await KV.get("license_token"),checkForm=await KV.get("checkForm"),sid=await KV.get("sid"),null===license_token){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"}});license_token=t.USER.OPTIONS.license_token;const e=t.USER.OPTIONS.expiration_timestamp;await KV.put("license_token",license_token,{expiration:e})}const s=new URL(a.url),u=s.pathname.split("/")[2];if(format=s.searchParams.get("f"),null===format)format="320";else if(format=format.toLowerCase(),void 0===i[format]){let t=[];if(Object.values(i).forEach(e=>t.push(e.num)),index=t.indexOf(format),-1===index)return new Response("Invalid format",{status:400,headers:{"content-type":"text/plain"}});format=Object.keys(i)[index]}let f=s.searchParams.get("t");switch(f=("true"===f||"1"===f)&&["misc","128","320"].includes(format),e){case"track":return await async function(e,a,s){const u=await o("song.getData",{SNG_ID:e});if("Response"===u.constructor.name)return u;parseInt(u.SNG_ID)<0&&(a="misc");if(0==u["FILESIZE_"+i[a].gw])return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});const f=await r.e(1).then(r.bind(null,9));if(legacy_url=!["320","flac"].includes(a),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 e=i[e].num,r(o,e,n,a)}(u,a,f.legacy_stream_url),"object"==typeof result)return result}else{let t;t=void 0!==u.FALLBACK?u.FALLBACK.TRACK_TOKEN:u.TRACK_TOKEN;const e={license_token:license_token,media:[{type:"FULL",formats:[{cipher:"BF_CBC_STRIPE",format:i[a].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();result=o.data[0].media[0].sources[0].url}const h=await fetch(result);if(200!==h.status)return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});let c;if(s){if(c=new n(t.alloc(0)),c.padding=0,c.setFrame("TIT2",u.SNG_TITLE).setFrame("TALB",u.ALB_TITLE).setFrame("TPE2",u.ART_NAME),void 0!==u.ARTISTS){artist_list=[];for(const t of u.ARTISTS)artist_list.push(t.ART_NAME);c.setFrame("TPE1",artist_list)}if(void 0!==u.TRACK_NUMBER&&c.setFrame("TRCK",u.TRACK_NUMBER),void 0!==u.DISK_NUMBER&&c.setFrame("TPOS",u.DISK_NUMBER),""!==u.ISRC&&c.setFrame("TSRC",u.ISRC),void 0!==u.PHYSICAL_RELEASE_DATE){const t=u.PHYSICAL_RELEASE_DATE.split("-");c.setFrame("TYER",t[0]),c.setFrame("TDAT",t[2]+t[1])}if(""!==u.ALB_PICTURE){const t=`https://cdns-images.dzcdn.net/images/cover/${u.ALB_PICTURE}/1000x1000-000000-80-0-0.jpg`,e=await fetch(t),r=await e.arrayBuffer();c.setFrame("APIC",{type:3,data:r,description:"cover"})}c.addTag()}let{readable:l,writable:p}=new TransformStream;const g=p.getWriter();s&&g.write(c.arrayBuffer);u.FALLBACK&&(e=u.FALLBACK.SNG_ID);const d=new f.Cipher(e),m=parseInt(h.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()}(g,h.body,m,d),new Response(l,{status:200,headers:{"content-type":i[a].mime}})}(u,format,f);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,u,format,f,s.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+",()=>a("track",t)),n.get("/album/\\d+",()=>a("album",t)),n.get("/playlist/\\d+",()=>a("playlist",t));return await n.route(t)}(t.request))});const i={aac_96:{num:"8",gw:"AAC_96",mime:"audio/aac"},64:{num:"10",gw:"MP3_64",mime:"audio/mpeg"},128:{num:"1",gw:"MP3_128",mime:"audio/mpeg"},320:{num:"3",gw:"MP3_320",mime:"audio/mpeg"},flac:{num:"9",gw:"FLAC",mime:"audio/flac"},mp4_ra1:{num:"13",gw:"MP4_RA1",mime:"audio/mp4"},mp4_ra2:{num:"14",gw:"MP4_RA2",mime:"audio/mp4"},mp4_ra3:{num:"15",gw:"MP4_RA3",mime:"audio/mp4"},mhm1_ra1:{num:"16",gw:"MHM1_RA1",mime:"audio/mp4"},mhm1_ra2:{num:"17",gw:"MHM1_RA2",mime:"audio/mp4"},mhm1_ra3:{num:"18",gw:"MHM1_RA3",mime:"audio/mp4"},sbc_256:{num:"12",gw:"SBC_256",mime:""},misc:{num:"0",gw:"MP3_MISC",mime:"audio/mpeg"}};async function o(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 a(e,a){if(license_token=await KV.get("license_token"),checkForm=await KV.get("checkForm"),sid=await KV.get("sid"),null===license_token){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"}});license_token=t.USER.OPTIONS.license_token,await KV.put("license_token",license_token,{expirationTtl:3600})}const s=new URL(a.url),u=s.pathname.split("/")[2];if(format=s.searchParams.get("f"),null===format)format="320";else if(format=format.toLowerCase(),void 0===i[format]){let t=[];if(Object.values(i).forEach(e=>t.push(e.num)),index=t.indexOf(format),-1===index)return new Response("Invalid format",{status:400,headers:{"content-type":"text/plain"}});format=Object.keys(i)[index]}let f=s.searchParams.get("t");switch(f=("true"===f||"1"===f)&&["misc","128","320"].includes(format),e){case"track":return await async function(e,a,s){const u=await o("song.getData",{SNG_ID:e});if("Response"===u.constructor.name)return u;parseInt(u.SNG_ID)<0&&(a="misc");if(0==u["FILESIZE_"+i[a].gw])return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});const f=await r.e(1).then(r.bind(null,9));if(legacy_url=!["320","flac"].includes(a),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 e=i[e].num,r(o,e,n,a)}(u,a,f.legacy_stream_url),"object"==typeof result)return result}else{let t;t=void 0!==u.FALLBACK?u.FALLBACK.TRACK_TOKEN:u.TRACK_TOKEN;const e={license_token:license_token,media:[{type:"FULL",formats:[{cipher:"BF_CBC_STRIPE",format:i[a].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();result=o.data[0].media[0].sources[0].url}const h=await fetch(result);if(200!==h.status)return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});let c;if(s){if(c=new n(t.alloc(0)),c.padding=0,c.setFrame("TIT2",u.SNG_TITLE).setFrame("TALB",u.ALB_TITLE).setFrame("TPE2",u.ART_NAME),void 0!==u.ARTISTS){artist_list=[];for(const t of u.ARTISTS)artist_list.push(t.ART_NAME);c.setFrame("TPE1",artist_list)}if(void 0!==u.TRACK_NUMBER&&c.setFrame("TRCK",u.TRACK_NUMBER),void 0!==u.DISK_NUMBER&&c.setFrame("TPOS",u.DISK_NUMBER),""!==u.ISRC&&c.setFrame("TSRC",u.ISRC),void 0!==u.PHYSICAL_RELEASE_DATE){const t=u.PHYSICAL_RELEASE_DATE.split("-");c.setFrame("TYER",t[0]),c.setFrame("TDAT",t[2]+t[1])}if(""!==u.ALB_PICTURE){const t=`https://cdns-images.dzcdn.net/images/cover/${u.ALB_PICTURE}/1000x1000-000000-80-0-0.jpg`,e=await fetch(t),r=await e.arrayBuffer();c.setFrame("APIC",{type:3,data:r,description:"cover"})}c.addTag()}let{readable:l,writable:p}=new TransformStream;const g=p.getWriter();s&&g.write(c.arrayBuffer);u.FALLBACK&&(e=u.FALLBACK.SNG_ID);const d=new f.Cipher(e),m=parseInt(h.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()}(g,h.body,m,d),new Response(l,{status:200,headers:{"content-type":i[a].mime}})}(u,format,f);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,u,format,f,s.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 4f57f62..02143a1 100644 --- a/index.js +++ b/index.js @@ -78,9 +78,8 @@ async function handler(type, request) { } license_token = user_data.USER.OPTIONS.license_token - const expiration = user_data.USER.OPTIONS.expiration_timestamp - await KV.put('license_token', license_token, { expiration: expiration }) + await KV.put('license_token', license_token, { expirationTtl: 3600 }) } const url = new URL(request.url)