From 1a802e76546129c56f77661930b6a017c04f198a Mon Sep 17 00:00:00 2001 From: uh wot Date: Wed, 10 Nov 2021 00:15:28 +0100 Subject: [PATCH] readded user-uploaded track support --- .vscode/tasks.json | 6 ++-- dist/worker.js | 6 ++-- index.js | 88 +++++++++++++++++++++++++++++++++------------- wrangler.toml | 2 +- 4 files changed, 70 insertions(+), 32 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 2593615..c98c5ca 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,7 +6,7 @@ { "label": "build", "type": "shell", - "command": "wrangler build", + "command": "NODE_OPTIONS=--openssl-legacy-provider wrangler build", "problemMatcher": [], "group": { "kind": "build", @@ -16,7 +16,7 @@ { "label": "dev", "type": "shell", - "command": "wrangler dev", + "command": "NODE_OPTIONS=--openssl-legacy-provider wrangler dev", "problemMatcher": [], "group": { "kind": "test", @@ -26,7 +26,7 @@ { "label": "publish", "type": "shell", - "command": "wrangler publish" + "command": "NODE_OPTIONS=--openssl-legacy-provider wrangler publish" } ] } \ No newline at end of file diff --git a/dist/worker.js b/dist/worker.js index 35e8403..d7d9930 100644 --- a/dist/worker.js +++ b/dist/worker.js @@ -1,10 +1,10 @@ -!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:"c877fc4d14dcbba7a9d9"}[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));let h;if(["320","flac"].includes(a)){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();if(void 0===o.data[0].media)return new Response("Couldn't get stream URL",{status:403,headers:{"content-type":"text/plain"}});h=o.data[0].media[0].sources[0].url}else h=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);const c=await fetch(h);if(200!==c.status)return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});let l;if(s){l=new n(t.alloc(0)),l.padding=0;let e=u.SNG_TITLE;if(void 0!==u.VERSION&&(e+=" "+u.VERSION),l.setFrame("TIT2",e).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);l.setFrame("TPE1",artist_list)}if(void 0!==u.TRACK_NUMBER&&l.setFrame("TRCK",u.TRACK_NUMBER),void 0!==u.DISK_NUMBER&&l.setFrame("TPOS",u.DISK_NUMBER),""!==u.ISRC&&l.setFrame("TSRC",u.ISRC),void 0!==u.PHYSICAL_RELEASE_DATE){const t=u.PHYSICAL_RELEASE_DATE.split("-");l.setFrame("TYER",t[0]),l.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();l.setFrame("APIC",{type:3,data:r,description:"cover"})}l.addTag()}let{readable:p,writable:g}=new TransformStream;const d=g.getWriter();s&&d.write(l.arrayBuffer);u.FALLBACK&&(e=u.FALLBACK.SNG_ID);const m=new f.Cipher(e),y=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,y,m),new Response(p,{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:"6778a0238c8462ed4a85"}[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){const s=new URL(a.url),u=s.pathname.split("/")[2];if("-"!==u[0]){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})}}else 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)})}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){let u;if("-"!==e[0]){if(u=await o("song.getData",{SNG_ID:e}),"Response"===u.constructor.name)return u}else{const t=await fetch(`https://api.deezer.com/track/${e}?access_token=${access_token}`);if(u=await t.json(),void 0!==u.error)return new Response(JSON.stringify(u.error),{status:403,headers:{"content-type":"application/json"}});u={SNG_ID:u.id,FILESIZE_MISC:u.filesize_misc,SNG_TITLE:u.title,ALB_TITLE:u.album.title,ART_NAME:u.artist.name,ARTISTS:[{ART_NAME:u.artist.name}],ISRC:"",ALB_PICTURE:u.md5_image,MD5_ORIGIN:u.md5_origin,MEDIA_VERSION:u.media_version},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));let c;if(["320","flac"].includes(a)){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();if(void 0===o.data[0].media)return new Response("Couldn't get stream URL",{status:403,headers:{"content-type":"text/plain"}});c=o.data[0].media[0].sources[0].url}else c=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);const h=await fetch(c);if(200!==h.status)return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});let l;if(s){l=new n(t.alloc(0)),l.padding=0;let e=u.SNG_TITLE;if(void 0!==u.VERSION&&(e+=" "+u.VERSION),l.setFrame("TIT2",e).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);l.setFrame("TPE1",artist_list)}if(void 0!==u.TRACK_NUMBER&&l.setFrame("TRCK",u.TRACK_NUMBER),void 0!==u.DISK_NUMBER&&l.setFrame("TPOS",u.DISK_NUMBER),""!==u.ISRC&&l.setFrame("TSRC",u.ISRC),void 0!==u.PHYSICAL_RELEASE_DATE){const t=u.PHYSICAL_RELEASE_DATE.split("-");l.setFrame("TYER",t[0]),l.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();l.setFrame("APIC",{type:3,data:r,description:"cover"})}l.addTag()}let{readable:p,writable:g}=new TransformStream;const d=g.getWriter();s&&d.write(l.arrayBuffer);u.FALLBACK&&(e=u.FALLBACK.SNG_ID);const m=new f.Cipher(e),y=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()}(d,h.body,y,m),new Response(p,{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. * * @author Feross Aboukhadijeh * @license MIT */ -var n=r(3),i=r(4),o=r(5);function a(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(u.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return N(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return j(t).length;default:if(n)return N(t).length;e=(""+e).toLowerCase(),n=!0}}function d(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return B(this,e,r);case"utf8":case"utf-8":return P(this,e,r);case"ascii":return S(this,e,r);case"latin1":case"binary":return U(this,e,r);case"base64":return R(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function m(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=u.from(e,n)),u.isBuffer(e))return 0===e.length?-1:w(t,e,r,n,i);if("number"==typeof e)return e&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):w(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function w(t,e,r,n,i){var o,a=1,s=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,s/=2,u/=2,r/=2}function f(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(i){var h=-1;for(o=r;os&&(r=s-u),o=r;o>=0;o--){for(var c=!0,l=0;li&&(n=i):n=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var a=0;a>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function R(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function P(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i239?4:f>223?3:f>191?2:1;if(i+c<=r)switch(c){case 1:f<128&&(h=f);break;case 2:128==(192&(o=t[i+1]))&&(u=(31&f)<<6|63&o)>127&&(h=u);break;case 3:o=t[i+1],a=t[i+2],128==(192&o)&&128==(192&a)&&(u=(15&f)<<12|(63&o)<<6|63&a)>2047&&(u<55296||u>57343)&&(h=u);break;case 4:o=t[i+1],a=t[i+2],s=t[i+3],128==(192&o)&&128==(192&a)&&128==(192&s)&&(u=(15&f)<<18|(63&o)<<12|(63&a)<<6|63&s)>65535&&u<1114112&&(h=u)}null===h?(h=65533,c=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=c}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),""},u.prototype.compare=function(t,e,r,n,i){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0),s=Math.min(o,a),f=this.slice(n,i),h=t.slice(e,r),c=0;ci)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return b(this,t,e,r);case"utf8":case"utf-8":return v(this,t,e,r);case"ascii":return A(this,t,e,r);case"latin1":case"binary":return _(this,t,e,r);case"base64":return T(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return E(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function S(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;in)&&(r=n);for(var i="",o=e;or)throw new RangeError("Trying to access beyond buffer length")}function L(t,e,r,n,i,o){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function O(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i>>8*(n?i:1-i)}function M(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i>>8*(n?i:3-i)&255}function k(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function F(t,e,r,n,o){return o||k(t,0,r,4),i.write(t,e,r,n,23,4),r+4}function Y(t,e,r,n,o){return o||k(t,0,r,8),i.write(t,e,r,n,52,8),r+8}u.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(i*=256);)n+=this[t+--e]*i;return n},u.prototype.readUInt8=function(t,e){return e||C(t,1,this.length),this[t]},u.prototype.readUInt16LE=function(t,e){return e||C(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUInt16BE=function(t,e){return e||C(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUInt32LE=function(t,e){return e||C(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUInt32BE=function(t,e){return e||C(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||C(t,e,this.length);for(var n=this[t],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*e)),n},u.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||C(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},u.prototype.readInt8=function(t,e){return e||C(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){e||C(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(t,e){e||C(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(t,e){return e||C(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return e||C(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readFloatLE=function(t,e){return e||C(t,4,this.length),i.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return e||C(t,4,this.length),i.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return e||C(t,8,this.length),i.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return e||C(t,8,this.length),i.read(this,t,!1,52,8)},u.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||L(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[e]=255&t;++o=0&&(o*=256);)this[e+i]=t/o&255;return e+r},u.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,1,255,0),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},u.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):O(this,t,e,!0),e+2},u.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):O(this,t,e,!1),e+2},u.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):M(this,t,e,!0),e+4},u.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},u.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var o=0,a=1,s=0;for(this[e]=255&t;++o>0)-s&255;return e+r},u.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var o=r-1,a=1,s=0;for(this[e+o]=255&t;--o>=0&&(a*=256);)t<0&&0===s&&0!==this[e+o+1]&&(s=1),this[e+o]=(t/a>>0)-s&255;return e+r},u.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,1,127,-128),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):O(this,t,e,!0),e+2},u.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):O(this,t,e,!1),e+2},u.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):M(this,t,e,!0),e+4},u.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},u.prototype.writeFloatLE=function(t,e,r){return F(this,t,e,!0,r)},u.prototype.writeFloatBE=function(t,e,r){return F(this,t,e,!1,r)},u.prototype.writeDoubleLE=function(t,e,r){return Y(this,t,e,!0,r)},u.prototype.writeDoubleBE=function(t,e,r){return Y(this,t,e,!1,r)},u.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--i)t[i+e]=this[i+r];else if(o<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function j(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(x,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function z(t,e,r,n){for(var i=0;i=e.length||i>=t.length);++i)e[i+r]=t[i];return i}}).call(this,r(2))},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";e.byteLength=function(t){var e=f(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,n=f(t),a=n[0],s=n[1],u=new o(function(t,e,r){return 3*(e+r)/4-r}(0,a,s)),h=0,c=s>0?a-4:a;for(r=0;r>16&255,u[h++]=e>>8&255,u[h++]=255&e;2===s&&(e=i[t.charCodeAt(r)]<<2|i[t.charCodeAt(r+1)]>>4,u[h++]=255&e);1===s&&(e=i[t.charCodeAt(r)]<<10|i[t.charCodeAt(r+1)]<<4|i[t.charCodeAt(r+2)]>>2,u[h++]=e>>8&255,u[h++]=255&e);return u},e.fromByteArray=function(t){for(var e,r=t.length,i=r%3,o=[],a=0,s=r-i;as?s:a+16383));1===i?(e=t[r-1],o.push(n[e>>2]+n[e<<4&63]+"==")):2===i&&(e=(t[r-2]<<8)+t[r-1],o.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,u=a.length;s0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function h(t,e,r){for(var i,o,a=[],s=e;s>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return a.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(t,e){ +var n=r(3),i=r(4),o=r(5);function a(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(t,e){if(a()=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function g(t,e){if(u.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return D(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return j(t).length;default:if(n)return D(t).length;e=(""+e).toLowerCase(),n=!0}}function d(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return U(this,e,r);case"utf8":case"utf-8":return S(this,e,r);case"ascii":return P(this,e,r);case"latin1":case"binary":return I(this,e,r);case"base64":return R(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function m(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=u.from(e,n)),u.isBuffer(e))return 0===e.length?-1:w(t,e,r,n,i);if("number"==typeof e)return e&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):w(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function w(t,e,r,n,i){var o,a=1,s=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,s/=2,u/=2,r/=2}function f(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(i){var c=-1;for(o=r;os&&(r=s-u),o=r;o>=0;o--){for(var h=!0,l=0;li&&(n=i):n=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var a=0;a>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function R(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function S(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i239?4:f>223?3:f>191?2:1;if(i+h<=r)switch(h){case 1:f<128&&(c=f);break;case 2:128==(192&(o=t[i+1]))&&(u=(31&f)<<6|63&o)>127&&(c=u);break;case 3:o=t[i+1],a=t[i+2],128==(192&o)&&128==(192&a)&&(u=(15&f)<<12|(63&o)<<6|63&a)>2047&&(u<55296||u>57343)&&(c=u);break;case 4:o=t[i+1],a=t[i+2],s=t[i+3],128==(192&o)&&128==(192&a)&&128==(192&s)&&(u=(15&f)<<18|(63&o)<<12|(63&a)<<6|63&s)>65535&&u<1114112&&(c=u)}null===c?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),i+=h}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),""},u.prototype.compare=function(t,e,r,n,i){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0),s=Math.min(o,a),f=this.slice(n,i),c=t.slice(e,r),h=0;hi)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return b(this,t,e,r);case"utf8":case"utf-8":return _(this,t,e,r);case"ascii":return v(this,t,e,r);case"latin1":case"binary":return A(this,t,e,r);case"base64":return T(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return E(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function P(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;in)&&(r=n);for(var i="",o=e;or)throw new RangeError("Trying to access beyond buffer length")}function L(t,e,r,n,i,o){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function O(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i>>8*(n?i:1-i)}function k(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i>>8*(n?i:3-i)&255}function M(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function F(t,e,r,n,o){return o||M(t,0,r,4),i.write(t,e,r,n,23,4),r+4}function x(t,e,r,n,o){return o||M(t,0,r,8),i.write(t,e,r,n,52,8),r+8}u.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(i*=256);)n+=this[t+--e]*i;return n},u.prototype.readUInt8=function(t,e){return e||C(t,1,this.length),this[t]},u.prototype.readUInt16LE=function(t,e){return e||C(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUInt16BE=function(t,e){return e||C(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUInt32LE=function(t,e){return e||C(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUInt32BE=function(t,e){return e||C(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||C(t,e,this.length);for(var n=this[t],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*e)),n},u.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||C(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},u.prototype.readInt8=function(t,e){return e||C(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){e||C(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(t,e){e||C(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(t,e){return e||C(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return e||C(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readFloatLE=function(t,e){return e||C(t,4,this.length),i.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return e||C(t,4,this.length),i.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return e||C(t,8,this.length),i.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return e||C(t,8,this.length),i.read(this,t,!1,52,8)},u.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||L(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[e]=255&t;++o=0&&(o*=256);)this[e+i]=t/o&255;return e+r},u.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,1,255,0),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},u.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):O(this,t,e,!0),e+2},u.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):O(this,t,e,!1),e+2},u.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):k(this,t,e,!0),e+4},u.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):k(this,t,e,!1),e+4},u.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var o=0,a=1,s=0;for(this[e]=255&t;++o>0)-s&255;return e+r},u.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var o=r-1,a=1,s=0;for(this[e+o]=255&t;--o>=0&&(a*=256);)t<0&&0===s&&0!==this[e+o+1]&&(s=1),this[e+o]=(t/a>>0)-s&255;return e+r},u.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,1,127,-128),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):O(this,t,e,!0),e+2},u.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):O(this,t,e,!1),e+2},u.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):k(this,t,e,!0),e+4},u.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||L(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):k(this,t,e,!1),e+4},u.prototype.writeFloatLE=function(t,e,r){return F(this,t,e,!0,r)},u.prototype.writeFloatBE=function(t,e,r){return F(this,t,e,!1,r)},u.prototype.writeDoubleLE=function(t,e,r){return x(this,t,e,!0,r)},u.prototype.writeDoubleBE=function(t,e,r){return x(this,t,e,!1,r)},u.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--i)t[i+e]=this[i+r];else if(o<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function j(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Y,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function z(t,e,r,n){for(var i=0;i=e.length||i>=t.length);++i)e[i+r]=t[i];return i}}).call(this,r(2))},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";e.byteLength=function(t){var e=f(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,n=f(t),a=n[0],s=n[1],u=new o(function(t,e,r){return 3*(e+r)/4-r}(0,a,s)),c=0,h=s>0?a-4:a;for(r=0;r>16&255,u[c++]=e>>8&255,u[c++]=255&e;2===s&&(e=i[t.charCodeAt(r)]<<2|i[t.charCodeAt(r+1)]>>4,u[c++]=255&e);1===s&&(e=i[t.charCodeAt(r)]<<10|i[t.charCodeAt(r+1)]<<4|i[t.charCodeAt(r+2)]>>2,u[c++]=e>>8&255,u[c++]=255&e);return u},e.fromByteArray=function(t){for(var e,r=t.length,i=r%3,o=[],a=0,s=r-i;as?s:a+16383));1===i?(e=t[r-1],o.push(n[e>>2]+n[e<<4&63]+"==")):2===i&&(e=(t[r-2]<<8)+t[r-1],o.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,u=a.length;s0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function c(t,e,r){for(var i,o,a=[],s=e;s>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return a.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(t,e){ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ -e.read=function(t,e,r,n,i){var o,a,s=8*i-n-1,u=(1<>1,h=-7,c=r?i-1:0,l=r?-1:1,p=t[e+c];for(c+=l,o=p&(1<<-h)-1,p>>=-h,h+=s;h>0;o=256*o+t[e+c],c+=l,h-=8);for(a=o&(1<<-h)-1,o>>=-h,h+=n;h>0;a=256*a+t[e+c],c+=l,h-=8);if(0===o)o=1-f;else{if(o===u)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,n),o-=f}return(p?-1:1)*a*Math.pow(2,o-n)},e.write=function(t,e,r,n,i,o){var a,s,u,f=8*o-i-1,h=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,g=n?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,a=h):(a=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-a))<1&&(a--,u*=2),(e+=a+c>=1?l/u:l*Math.pow(2,1-c))*u>=2&&(a++,u/=2),a+c>=h?(s=0,a=h):a+c>=1?(s=(e*u-1)*Math.pow(2,i),a+=c):(s=e*Math.pow(2,c-1)*Math.pow(2,i),a=0));i>=8;t[r+p]=255&s,p+=g,s/=256,i-=8);for(a=a<0;t[r+p]=255&a,p+=g,a/=256,f-=8);t[r+p-g]|=128*d}},function(t,e){var r={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==r.call(t)}},function(t,e){const r=t=>e=>e.method.toLowerCase()===t.toLowerCase(),n=r("connect"),i=r("delete"),o=r("get"),a=r("head"),s=r("options"),u=r("patch"),f=r("post"),h=r("put"),c=r("trace"),l=t=>e=>{const r=new URL(e.url).pathname;return(r.match(t)||[])[0]===r};t.exports=class{constructor(){this.routes=[]}handle(t,e){return this.routes.push({conditions:t,handler:e}),this}connect(t,e){return this.handle([n,l(t)],e)}delete(t,e){return this.handle([i,l(t)],e)}get(t,e){return this.handle([o,l(t)],e)}head(t,e){return this.handle([a,l(t)],e)}options(t,e){return this.handle([s,l(t)],e)}patch(t,e){return this.handle([u,l(t)],e)}post(t,e){return this.handle([f,l(t)],e)}put(t,e){return this.handle([h,l(t)],e)}trace(t,e){return this.handle([c,l(t)],e)}all(t){return this.handle([],t)}route(t){const e=this.resolve(t);return e?e.handler(t):new Response("resource not found",{status:404,statusText:"not found",headers:{"content-type":"text/plain"}})}resolve(t){return this.routes.find(e=>!(e.conditions&&(!Array.isArray(e)||e.conditions.length))||("function"==typeof e.conditions?e.conditions(t):e.conditions.every(e=>e(t))))}}},function(t,e,r){t.exports=function(){"use strict";function t(t){return String(t).split("").map((function(t){return t.charCodeAt(0)}))}function e(e){return new Uint8Array(t(e))}function r(e){var r=new Uint8Array(2*e.length);return new Uint16Array(r.buffer).set(t(e)),r}return function(){var t=n.prototype;function n(t){if(!t||"object"!=typeof t||!("byteLength"in t))throw new Error("First argument should be an instance of ArrayBuffer or Buffer");this.arrayBuffer=t,this.padding=4096,this.frames=[],this.url=""}return t._setIntegerFrame=function(t,e){var r=parseInt(e,10);this.frames.push({name:t,value:r,size:11+r.toString().length})},t._setStringFrame=function(t,e){var r=e.toString();this.frames.push({name:t,value:r,size:13+2*r.length})},t._setPictureFrame=function(t,e,r,n){var i,o,a,s=function(t){if(!t||!t.length)return null;if(255===t[0]&&216===t[1]&&255===t[2])return"image/jpeg";if(137===t[0]&&80===t[1]&&78===t[2]&&71===t[3])return"image/png";if(71===t[0]&&73===t[1]&&70===t[2])return"image/gif";if(87===t[8]&&69===t[9]&&66===t[10]&&80===t[11])return"image/webp";var e=73===t[0]&&73===t[1]&&42===t[2]&&0===t[3],r=77===t[0]&&77===t[1]&&0===t[2]&&42===t[3];return e||r?"image/tiff":66===t[0]&&77===t[1]?"image/bmp":0===t[0]&&0===t[1]&&1===t[2]&&0===t[3]?"image/x-icon":null}(new Uint8Array(e)),u=r.toString();if(!s)throw new Error("Unknown picture MIME type");r||(n=!1),this.frames.push({name:"APIC",value:e,pictureType:t,mimeType:s,useUnicodeEncoding:n,description:u,size:(i=e.byteLength,o=s.length,a=u.length,11+o+1+1+(n?2+2*(a+1):a+1)+i)})},t._setLyricsFrame=function(t,e,r){var n,i,o=t.split("").map((function(t){return t.charCodeAt(0)})),a=e.toString(),s=r.toString();this.frames.push({name:"USLT",value:s,language:o,description:a,size:(n=a.length,i=s.length,16+2*n+2+2+2*i)})},t._setCommentFrame=function(t,e,r){var n,i,o=t.split("").map((function(t){return t.charCodeAt(0)})),a=e.toString(),s=r.toString();this.frames.push({name:"COMM",value:s,language:o,description:a,size:(n=a.length,i=s.length,16+2*n+2+2+2*i)})},t._setPrivateFrame=function(t,e){var r,n,i=t.toString();this.frames.push({name:"PRIV",value:e,id:i,size:(r=i.length,n=e.byteLength,10+r+1+n)})},t._setUserStringFrame=function(t,e){var r,n,i=t.toString(),o=e.toString();this.frames.push({name:"TXXX",description:i,value:o,size:(r=i.length,n=o.length,13+2*r+2+2+2*n)})},t._setUrlLinkFrame=function(t,e){var r=e.toString();this.frames.push({name:t,value:r,size:10+r.length})},t.setFrame=function(t,e){switch(t){case"TPE1":case"TCOM":case"TCON":if(!Array.isArray(e))throw new Error(t+" frame value should be an array of strings");var r="TCON"===t?";":"/",n=e.join(r);this._setStringFrame(t,n);break;case"TLAN":case"TIT1":case"TIT2":case"TIT3":case"TALB":case"TPE2":case"TPE3":case"TPE4":case"TRCK":case"TPOS":case"TMED":case"TPUB":case"TCOP":case"TKEY":case"TEXT":case"TSRC":this._setStringFrame(t,e);break;case"TBPM":case"TLEN":case"TDAT":case"TYER":this._setIntegerFrame(t,e);break;case"USLT":if(e.language=e.language||"eng","object"!=typeof e||!("description"in e)||!("lyrics"in e))throw new Error("USLT frame value should be an object with keys description and lyrics");if(e.language&&!e.language.match(/[a-z]{3}/i))throw new Error("Language must be coded following the ISO 639-2 standards");this._setLyricsFrame(e.language,e.description,e.lyrics);break;case"APIC":if(!("object"==typeof e&&"type"in e&&"data"in e&&"description"in e))throw new Error("APIC frame value should be an object with keys type, data and description");if(e.type<0||20>>21&127,t>>>14&127,t>>>7&127,127&t],a.set(u,s),s+=u.length,this.frames.forEach((function(t){var i;switch(u=e(t.name),a.set(u,s),s+=u.length,i=t.size-10,u=[i>>>24&255,i>>>16&255,i>>>8&255,255&i],a.set(u,s),s+=u.length,s+=2,t.name){case"WCOM":case"WCOP":case"WOAF":case"WOAR":case"WOAS":case"WORS":case"WPAY":case"WPUB":u=e(t.value),a.set(u,s),s+=u.length;break;case"TPE1":case"TCOM":case"TCON":case"TLAN":case"TIT1":case"TIT2":case"TIT3":case"TALB":case"TPE2":case"TPE3":case"TPE4":case"TRCK":case"TPOS":case"TKEY":case"TMED":case"TPUB":case"TCOP":case"TEXT":case"TSRC":u=[1].concat(n),a.set(u,s),s+=u.length,u=r(t.value),a.set(u,s),s+=u.length;break;case"TXXX":case"USLT":case"COMM":u=[1],"USLT"!==t.name&&"COMM"!==t.name||(u=u.concat(t.language)),u=u.concat(n),a.set(u,s),s+=u.length,u=r(t.description),a.set(u,s),s+=u.length,u=[0,0].concat(n),a.set(u,s),s+=u.length,u=r(t.value),a.set(u,s),s+=u.length;break;case"TBPM":case"TLEN":case"TDAT":case"TYER":s++,u=e(t.value),a.set(u,s),s+=u.length;break;case"PRIV":u=e(t.id),a.set(u,s),s+=u.length,s++,a.set(new Uint8Array(t.value),s),s+=t.value.byteLength;break;case"APIC":u=[t.useUnicodeEncoding?1:0],a.set(u,s),s+=u.length,u=e(t.mimeType),a.set(u,s),s+=u.length,u=[0,t.pictureType],a.set(u,s),s+=u.length,t.useUnicodeEncoding?(u=[].concat(n),a.set(u,s),s+=u.length,u=r(t.description),a.set(u,s),s+=u.length,s+=2):(u=e(t.description),a.set(u,s),s+=u.length,s++),a.set(new Uint8Array(t.value),s),s+=t.value.byteLength}})),s+=this.padding,a.set(new Uint8Array(this.arrayBuffer),s),this.arrayBuffer=o},t.getBlob=function(){return new Blob([this.arrayBuffer],{type:"audio/mpeg"})},t.getURL=function(){return this.url||(this.url=URL.createObjectURL(this.getBlob())),this.url},t.revokeURL=function(){URL.revokeObjectURL(this.url)},n}()}()},function(t,e){t.exports=' dzserver

dzserver

source code


how 2 use:

/track/<id>

/album/<id>

/playlist/<id>


params are:

t: tagging, boolean

f: format, can be one of these:

aac_96, 64, 128, 320, flac, mp4_ra1, mp4_ra2, mp4_ra3, mhm1_ra1, mhm1_ra2, mhm1_ra3, sbc_256, misc

available formats depend on the track

'}]); \ No newline at end of file +e.read=function(t,e,r,n,i){var o,a,s=8*i-n-1,u=(1<>1,c=-7,h=r?i-1:0,l=r?-1:1,p=t[e+h];for(h+=l,o=p&(1<<-c)-1,p>>=-c,c+=s;c>0;o=256*o+t[e+h],h+=l,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=n;c>0;a=256*a+t[e+h],h+=l,c-=8);if(0===o)o=1-f;else{if(o===u)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,n),o-=f}return(p?-1:1)*a*Math.pow(2,o-n)},e.write=function(t,e,r,n,i,o){var a,s,u,f=8*o-i-1,c=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,g=n?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-a))<1&&(a--,u*=2),(e+=a+h>=1?l/u:l*Math.pow(2,1-h))*u>=2&&(a++,u/=2),a+h>=c?(s=0,a=c):a+h>=1?(s=(e*u-1)*Math.pow(2,i),a+=h):(s=e*Math.pow(2,h-1)*Math.pow(2,i),a=0));i>=8;t[r+p]=255&s,p+=g,s/=256,i-=8);for(a=a<0;t[r+p]=255&a,p+=g,a/=256,f-=8);t[r+p-g]|=128*d}},function(t,e){var r={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==r.call(t)}},function(t,e){const r=t=>e=>e.method.toLowerCase()===t.toLowerCase(),n=r("connect"),i=r("delete"),o=r("get"),a=r("head"),s=r("options"),u=r("patch"),f=r("post"),c=r("put"),h=r("trace"),l=t=>e=>{const r=new URL(e.url).pathname;return(r.match(t)||[])[0]===r};t.exports=class{constructor(){this.routes=[]}handle(t,e){return this.routes.push({conditions:t,handler:e}),this}connect(t,e){return this.handle([n,l(t)],e)}delete(t,e){return this.handle([i,l(t)],e)}get(t,e){return this.handle([o,l(t)],e)}head(t,e){return this.handle([a,l(t)],e)}options(t,e){return this.handle([s,l(t)],e)}patch(t,e){return this.handle([u,l(t)],e)}post(t,e){return this.handle([f,l(t)],e)}put(t,e){return this.handle([c,l(t)],e)}trace(t,e){return this.handle([h,l(t)],e)}all(t){return this.handle([],t)}route(t){const e=this.resolve(t);return e?e.handler(t):new Response("resource not found",{status:404,statusText:"not found",headers:{"content-type":"text/plain"}})}resolve(t){return this.routes.find(e=>!(e.conditions&&(!Array.isArray(e)||e.conditions.length))||("function"==typeof e.conditions?e.conditions(t):e.conditions.every(e=>e(t))))}}},function(t,e,r){t.exports=function(){"use strict";function t(t){return String(t).split("").map((function(t){return t.charCodeAt(0)}))}function e(e){return new Uint8Array(t(e))}function r(e){var r=new Uint8Array(2*e.length);return new Uint16Array(r.buffer).set(t(e)),r}return function(){var t=n.prototype;function n(t){if(!t||"object"!=typeof t||!("byteLength"in t))throw new Error("First argument should be an instance of ArrayBuffer or Buffer");this.arrayBuffer=t,this.padding=4096,this.frames=[],this.url=""}return t._setIntegerFrame=function(t,e){var r=parseInt(e,10);this.frames.push({name:t,value:r,size:11+r.toString().length})},t._setStringFrame=function(t,e){var r=e.toString();this.frames.push({name:t,value:r,size:13+2*r.length})},t._setPictureFrame=function(t,e,r,n){var i,o,a,s=function(t){if(!t||!t.length)return null;if(255===t[0]&&216===t[1]&&255===t[2])return"image/jpeg";if(137===t[0]&&80===t[1]&&78===t[2]&&71===t[3])return"image/png";if(71===t[0]&&73===t[1]&&70===t[2])return"image/gif";if(87===t[8]&&69===t[9]&&66===t[10]&&80===t[11])return"image/webp";var e=73===t[0]&&73===t[1]&&42===t[2]&&0===t[3],r=77===t[0]&&77===t[1]&&0===t[2]&&42===t[3];return e||r?"image/tiff":66===t[0]&&77===t[1]?"image/bmp":0===t[0]&&0===t[1]&&1===t[2]&&0===t[3]?"image/x-icon":null}(new Uint8Array(e)),u=r.toString();if(!s)throw new Error("Unknown picture MIME type");r||(n=!1),this.frames.push({name:"APIC",value:e,pictureType:t,mimeType:s,useUnicodeEncoding:n,description:u,size:(i=e.byteLength,o=s.length,a=u.length,11+o+1+1+(n?2+2*(a+1):a+1)+i)})},t._setLyricsFrame=function(t,e,r){var n,i,o=t.split("").map((function(t){return t.charCodeAt(0)})),a=e.toString(),s=r.toString();this.frames.push({name:"USLT",value:s,language:o,description:a,size:(n=a.length,i=s.length,16+2*n+2+2+2*i)})},t._setCommentFrame=function(t,e,r){var n,i,o=t.split("").map((function(t){return t.charCodeAt(0)})),a=e.toString(),s=r.toString();this.frames.push({name:"COMM",value:s,language:o,description:a,size:(n=a.length,i=s.length,16+2*n+2+2+2*i)})},t._setPrivateFrame=function(t,e){var r,n,i=t.toString();this.frames.push({name:"PRIV",value:e,id:i,size:(r=i.length,n=e.byteLength,10+r+1+n)})},t._setUserStringFrame=function(t,e){var r,n,i=t.toString(),o=e.toString();this.frames.push({name:"TXXX",description:i,value:o,size:(r=i.length,n=o.length,13+2*r+2+2+2*n)})},t._setUrlLinkFrame=function(t,e){var r=e.toString();this.frames.push({name:t,value:r,size:10+r.length})},t.setFrame=function(t,e){switch(t){case"TPE1":case"TCOM":case"TCON":if(!Array.isArray(e))throw new Error(t+" frame value should be an array of strings");var r="TCON"===t?";":"/",n=e.join(r);this._setStringFrame(t,n);break;case"TLAN":case"TIT1":case"TIT2":case"TIT3":case"TALB":case"TPE2":case"TPE3":case"TPE4":case"TRCK":case"TPOS":case"TMED":case"TPUB":case"TCOP":case"TKEY":case"TEXT":case"TSRC":this._setStringFrame(t,e);break;case"TBPM":case"TLEN":case"TDAT":case"TYER":this._setIntegerFrame(t,e);break;case"USLT":if(e.language=e.language||"eng","object"!=typeof e||!("description"in e)||!("lyrics"in e))throw new Error("USLT frame value should be an object with keys description and lyrics");if(e.language&&!e.language.match(/[a-z]{3}/i))throw new Error("Language must be coded following the ISO 639-2 standards");this._setLyricsFrame(e.language,e.description,e.lyrics);break;case"APIC":if(!("object"==typeof e&&"type"in e&&"data"in e&&"description"in e))throw new Error("APIC frame value should be an object with keys type, data and description");if(e.type<0||20>>21&127,t>>>14&127,t>>>7&127,127&t],a.set(u,s),s+=u.length,this.frames.forEach((function(t){var i;switch(u=e(t.name),a.set(u,s),s+=u.length,i=t.size-10,u=[i>>>24&255,i>>>16&255,i>>>8&255,255&i],a.set(u,s),s+=u.length,s+=2,t.name){case"WCOM":case"WCOP":case"WOAF":case"WOAR":case"WOAS":case"WORS":case"WPAY":case"WPUB":u=e(t.value),a.set(u,s),s+=u.length;break;case"TPE1":case"TCOM":case"TCON":case"TLAN":case"TIT1":case"TIT2":case"TIT3":case"TALB":case"TPE2":case"TPE3":case"TPE4":case"TRCK":case"TPOS":case"TKEY":case"TMED":case"TPUB":case"TCOP":case"TEXT":case"TSRC":u=[1].concat(n),a.set(u,s),s+=u.length,u=r(t.value),a.set(u,s),s+=u.length;break;case"TXXX":case"USLT":case"COMM":u=[1],"USLT"!==t.name&&"COMM"!==t.name||(u=u.concat(t.language)),u=u.concat(n),a.set(u,s),s+=u.length,u=r(t.description),a.set(u,s),s+=u.length,u=[0,0].concat(n),a.set(u,s),s+=u.length,u=r(t.value),a.set(u,s),s+=u.length;break;case"TBPM":case"TLEN":case"TDAT":case"TYER":s++,u=e(t.value),a.set(u,s),s+=u.length;break;case"PRIV":u=e(t.id),a.set(u,s),s+=u.length,s++,a.set(new Uint8Array(t.value),s),s+=t.value.byteLength;break;case"APIC":u=[t.useUnicodeEncoding?1:0],a.set(u,s),s+=u.length,u=e(t.mimeType),a.set(u,s),s+=u.length,u=[0,t.pictureType],a.set(u,s),s+=u.length,t.useUnicodeEncoding?(u=[].concat(n),a.set(u,s),s+=u.length,u=r(t.description),a.set(u,s),s+=u.length,s+=2):(u=e(t.description),a.set(u,s),s+=u.length,s++),a.set(new Uint8Array(t.value),s),s+=t.value.byteLength}})),s+=this.padding,a.set(new Uint8Array(this.arrayBuffer),s),this.arrayBuffer=o},t.getBlob=function(){return new Blob([this.arrayBuffer],{type:"audio/mpeg"})},t.getURL=function(){return this.url||(this.url=URL.createObjectURL(this.getBlob())),this.url},t.revokeURL=function(){URL.revokeObjectURL(this.url)},n}()}()},function(t,e){t.exports=' dzserver

dzserver

source code


how 2 use:

/track/<id>

/album/<id>

/playlist/<id>


params are:

t: tagging, boolean

f: format, can be one of these:

aac_96, 64, 128, 320, flac, mp4_ra1, mp4_ra2, mp4_ra3, mhm1_ra1, mhm1_ra2, mhm1_ra3, sbc_256, misc

available formats depend on the track

'}]); \ No newline at end of file diff --git a/index.js b/index.js index fd30ea6..a223057 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,9 @@ addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) }) +const client_id = "447462" +const client_secret = "a83bf7f38ad2f137e444727cfc3775cf" + const formats = { aac_96: { num: '8', gw: 'AAC_96', mime: 'audio/aac' }, 64: { num: '10', gw: 'MP3_64', mime: 'audio/mpeg' }, @@ -63,28 +66,42 @@ async function gw_api_call(method, params) { } async function handler(type, request) { - license_token = await KV.get('license_token') - checkForm = await KV.get('checkForm') - sid = await KV.get('sid') - - if (license_token === null) { - const user_data = await gw_api_call('deezer.getUserData') - if (user_data.constructor.name === 'Response') { - return user_data - } - - if (user_data.USER.USER_ID === 0) { - return new Response('Invalid arl', { status: 500, headers: { 'content-type': 'text/plain' } }) - } - - license_token = user_data.USER.OPTIONS.license_token - - await KV.put('license_token', license_token, { expirationTtl: 3600 }) - } - const url = new URL(request.url) const id = url.pathname.split('/')[2] + if (id[0] !== '-') { // checks if not user-upped track + license_token = await KV.get('license_token') + checkForm = await KV.get('checkForm') + sid = await KV.get('sid') + + if (license_token === null) { + const user_data = await gw_api_call('deezer.getUserData') + if (user_data.constructor.name === 'Response') { + return user_data + } + + if (user_data.USER.USER_ID === 0) { + return new Response('Invalid arl', { status: 500, headers: { 'content-type': 'text/plain' } }) + } + + license_token = user_data.USER.OPTIONS.license_token + + await KV.put('license_token', license_token, { expirationTtl: 3600 }) + } + } else { + access_token = await KV.get('access_token') + if (access_token === null) { + const response = await fetch(`https://connect.deezer.com/oauth/access_token.php?grant_type=client_credentials&client_id=${client_id}&client_secret=${client_secret}&output=json`) + const json = await response.json() + if (json.error !== undefined) { + return new Response("Couldn't get access token from Deezer", { status: 500, headers: { 'content-type': 'text/plain' } }) + } + + access_token = json.access_token + await KV.put('access_token', access_token, { expirationTtl: parseInt(json.expires) }) + } + } + format = url.searchParams.get('f') if (format === null) { format = '320' @@ -115,13 +132,34 @@ async function handler(type, request) { } async function track(id, format, tagging) { - const json = await gw_api_call('song.getData', { 'SNG_ID': id }) - if (json.constructor.name === 'Response') { - return json - } + // other users' user-upped tracks cannot be downloaded with the gw-light API + let json; + if (id[0] !== '-') { + json = await gw_api_call('song.getData', { 'SNG_ID': id }) + if (json.constructor.name === 'Response') { + return json + } + } else { // user-upped track + const response = await fetch(`https://api.deezer.com/track/${id}?access_token=${access_token}`) + json = await response.json() + if (json.error !== undefined) { + return new Response(JSON.stringify(json.error), { status: 403, headers: { 'content-type': "application/json" } }) + } - if (parseInt(json.SNG_ID) < 0) { // user-uploaded track - format = 'misc' + json = { + SNG_ID: json.id, + FILESIZE_MISC: json.filesize_misc, + SNG_TITLE: json.title, + ALB_TITLE: json.album.title, + ART_NAME: json.artist.name, + ARTISTS: [{ART_NAME: json.artist.name}], + ISRC: '', + ALB_PICTURE: json.md5_image, + MD5_ORIGIN: json.md5_origin, + MEDIA_VERSION: json.media_version, + } + + format = 'misc' // user-upped tracks always use 'misc' as format } if (json['FILESIZE_' + formats[format].gw] == false) { diff --git a/wrangler.toml b/wrangler.toml index 5c374f4..435f631 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -7,4 +7,4 @@ kv_namespaces = [ { binding = "KV", id = "974c0967a84e415daa054bbbcc7f80c6", preview_id = "cfcc6491f3484cbca664913836635113" } ] vars = { ARL = "amogus" } -compatibility_date = "2021-10-14" \ No newline at end of file +compatibility_date = "2021-11-09" \ No newline at end of file