From 90f3d6bf4e328b4475692786c07570a879b1a2a6 Mon Sep 17 00:00:00 2001 From: uh wot Date: Tue, 24 Aug 2021 17:36:22 +0200 Subject: [PATCH] fixed filesize check --- 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 26aea1e..d09ac7f 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:"d53c7e889000314b7b50"}[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+",()=>o("track",t)),n.get("/album/\\d+",()=>o("album",t)),n.get("/playlist/\\d+",()=>o("playlist",t));return await n.route(t)}(t.request))});const i={aac_96:"8",64:"10",128:"1",320:"3",mp4_ra1:"13",mp4_ra2:"14",mp4_ra3:"15",mhm1_ra1:"16",mhm1_ra2:"17",mhm1:"18",sbc_256:"12",misc:"0"};async function o(e,o){if(access_token=await KV.get("access_token"),null===access_token){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"}});access_token=e.access_token,await KV.put("access_token",access_token,{expirationTtl:parseInt(e.expires)})}const a=new URL(o.url),s=a.pathname.split("/")[2];if(format=a.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 u=a.searchParams.get("t");switch(u="true"===u||"1"===u,e){case"track":return await async function(e,o,a,s){const u=await fetch(`https://api.deezer.com/track/${e}?access_token=${a}`),f=await u.json();if(void 0!==f.error)return new Response(JSON.stringify(f.error),{status:403,headers:{"content-type":"application/json"}});const h=await r.e(1).then(r.bind(null,9));if(result=await function(t,e,r){t.alternative&&(t=t.alternative);const n=t.id,o=t.md5_origin,a=t.media_version;n<0&&(e="misc");if("0"===t["filesize_"+e])return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});return r(o,e=i[e],n.toString(),a)}(f,o,h.stream_url),"object"==typeof result)return result;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(s){if(l=new n(t.alloc(0)),l.padding=0,l.setFrame("TIT2",f.title).setFrame("TALB",f.album.title).setFrame("TPE2",f.artist.name),void 0!==f.contributors){contr_list=[];for(const t of f.contributors)contr_list.push(t.name);l.setFrame("TPE1",contr_list)}if(void 0!==f.track_position&&l.setFrame("TRCK",f.track_position),void 0!==f.disk_number&&l.setFrame("TPOS",f.disk_number),""!==f.isrc&&l.setFrame("TSRC",f.isrc),void 0!==f.bpm&&l.setFrame("TBPM",f.bpm),void 0!==f.release_date){const t=f.release_date.split("-");l.setFrame("TYER",t[0]),l.setFrame("TDAT",t[2]+t[1])}if(""!==f.md5_image){const t=`https://cdns-images.dzcdn.net/images/cover/${f.md5_image}/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();l&&d.write(l.arrayBuffer);f.alternative&&(e=f.alternative.id.toString());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"}})}(s,format,access_token,u);case"album":case"playlist":return await async function(t,e,r,n,i,o){const a=await fetch(`https://api.deezer.com/${t}/${e}?access_token=${n}&limit=-1`),s=await a.json();if(void 0!==s.error)return new Response(JSON.stringify(s.error),{status:403,headers:{"content-type":"application/json"}});let u="#EXTM3U\n";for(const t of s.tracks.data){t.id<0&&(r="misc");let e=`https://${o}/track/${t.id}?f=${r}&t=${+i}`;u+=`#EXTINF:${t.duration},${t.title}\n${e}\n`}return new Response(u,{status:200,headers:{"content-type":"audio/mpegurl"}})}(e,s,format,access_token,u,a.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:"d53c7e889000314b7b50"}[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+",()=>o("track",t)),n.get("/album/\\d+",()=>o("album",t)),n.get("/playlist/\\d+",()=>o("playlist",t));return await n.route(t)}(t.request))});const i={aac_96:"8",64:"10",128:"1",320:"3",mp4_ra1:"13",mp4_ra2:"14",mp4_ra3:"15",mhm1_ra1:"16",mhm1_ra2:"17",mhm1:"18",sbc_256:"12",misc:"0"};async function o(e,o){if(access_token=await KV.get("access_token"),null===access_token){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"}});access_token=e.access_token,await KV.put("access_token",access_token,{expirationTtl:parseInt(e.expires)})}const a=new URL(o.url),s=a.pathname.split("/")[2];if(format=a.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 u=a.searchParams.get("t");switch(u="true"===u||"1"===u,e){case"track":return await async function(e,o,a,s){const u=await fetch(`https://api.deezer.com/track/${e}?access_token=${a}`),f=await u.json();if(void 0!==f.error)return new Response(JSON.stringify(f.error),{status:403,headers:{"content-type":"application/json"}});const h=await r.e(1).then(r.bind(null,9));if(result=await function(t,e,r){t.alternative&&(t=t.alternative);const n=t.id,o=t.md5_origin,a=t.media_version;n<0&&(e="misc");if(0==t["filesize_"+e])return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});return r(o,e=i[e],n.toString(),a)}(f,o,h.stream_url),"object"==typeof result)return result;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(s){if(l=new n(t.alloc(0)),l.padding=0,l.setFrame("TIT2",f.title).setFrame("TALB",f.album.title).setFrame("TPE2",f.artist.name),void 0!==f.contributors){contr_list=[];for(const t of f.contributors)contr_list.push(t.name);l.setFrame("TPE1",contr_list)}if(void 0!==f.track_position&&l.setFrame("TRCK",f.track_position),void 0!==f.disk_number&&l.setFrame("TPOS",f.disk_number),""!==f.isrc&&l.setFrame("TSRC",f.isrc),void 0!==f.bpm&&l.setFrame("TBPM",f.bpm),void 0!==f.release_date){const t=f.release_date.split("-");l.setFrame("TYER",t[0]),l.setFrame("TDAT",t[2]+t[1])}if(""!==f.md5_image){const t=`https://cdns-images.dzcdn.net/images/cover/${f.md5_image}/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();l&&d.write(l.arrayBuffer);f.alternative&&(e=f.alternative.id.toString());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"}})}(s,format,access_token,u);case"album":case"playlist":return await async function(t,e,r,n,i,o){const a=await fetch(`https://api.deezer.com/${t}/${e}?access_token=${n}&limit=-1`),s=await a.json();if(void 0!==s.error)return new Response(JSON.stringify(s.error),{status:403,headers:{"content-type":"application/json"}});let u="#EXTM3U\n";for(const t of s.tracks.data){t.id<0&&(r="misc");let e=`https://${o}/track/${t.id}?f=${r}&t=${+i}`;u+=`#EXTINF:${t.duration},${t.title}\n${e}\n`}return new Response(u,{status:200,headers:{"content-type":"audio/mpegurl"}})}(e,s,format,access_token,u,a.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 3f34dca..a6e0640 100644 --- a/index.js +++ b/index.js @@ -205,7 +205,7 @@ function track_url(json, format, url_func) { format = 'misc' } - if (json['filesize_' + format] === '0') { + if (json['filesize_' + format] == false) { return new Response('Format unavailable', { status: 403, headers: { 'content-type': 'text/plain' } }) }