From 695fd9ebc2ba9d222fb8f7a71d4be9b4c9a783ea Mon Sep 17 00:00:00 2001 From: uh wot Date: Wed, 1 Sep 2021 21:40:01 +0200 Subject: [PATCH] switched to different method of getting stream urls cause of retarded quota --- dist/worker.js | 6 +- index.html | 2 +- index.js | 230 +++++++++++++++++++++++++++++++++---------------- src/lib.rs | 11 +-- wrangler.toml | 6 +- 5 files changed, 166 insertions(+), 89 deletions(-) diff --git a/dist/worker.js b/dist/worker.js index b116518..33c0168 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:"4371fde8bf684fe55fb6"}[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",flac:"9",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){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)&&["misc","128","320"].includes(format),e){case"track":return await async function(e,o,a){const s=await fetch(`https://api.deezer.com/streaming_url.php?access_token=${ACCESS_TOKEN}&track_id=${e}`),u=await s.json();if(void 0!==u.error)return new Response(JSON.stringify(u.error),{status:403,headers:{"content-type":"application/json"}});u.id<0&&(o="misc");const f=await r.e(1).then(r.bind(null,9));if(encrypted=!["320","flac"].includes(o),encrypted){if(result=await function(t,e,r){t.alternative&&(t=t.alternative);const n=t.id,o=t.md5_origin,a=t.media_version;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)}(u,o,f.legacy_stream_url),"object"==typeof result)return result}else{let t;if(u.alternative){const e=await fetch(`https://api.deezer.com/streaming_url.php?access_token=${ACCESS_TOKEN}&track_id=${u.alternative.id}`);t=await e.json()}else t=u;if(result=t["url_"+o],void 0===result)return new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}});result=f.decrypt_stream_url(result)}let h,c;if((a||encrypted)&&(h=await fetch(result),200!==h.status))return new Response("Couldn't get track stream",{status:403,headers:{"content-type":"text/plain"}});if(a){if(c=new n(t.alloc(0)),c.padding=0,c.setFrame("TIT2",u.title).setFrame("TALB",u.album.title).setFrame("TPE2",u.artist.name),void 0!==u.contributors){contr_list=[];for(const t of u.contributors)contr_list.push(t.name);c.setFrame("TPE1",contr_list)}if(void 0!==u.track_position&&c.setFrame("TRCK",u.track_position),void 0!==u.disk_number&&c.setFrame("TPOS",u.disk_number),""!==u.isrc&&c.setFrame("TSRC",u.isrc),void 0!==u.bpm&&c.setFrame("TBPM",u.bpm),void 0!==u.release_date){const t=u.release_date.split("-");c.setFrame("TYER",t[0]),c.setFrame("TDAT",t[2]+t[1])}if(""!==u.md5_image){const t=`https://cdns-images.dzcdn.net/images/cover/${u.md5_image}/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 l,{readable:p,writable:g}=new TransformStream;(a||encrypted)&&(l=g.getWriter());a&&l.write(c.arrayBuffer);u.alternative&&(e=u.alternative.id.toString());if(encrypted){const t=new f.Cipher(e),r=parseInt(h.headers.get("Content-Length"));!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()}(l,h.body,r,t)}else{if(!a)return new Response(null,{status:302,headers:{location:result}});l.releaseLock(),h.body.pipeTo(g)}return new Response(p,{status:200,headers:{"content-type":"audio/mpeg"}})}(s,format,u);case"album":case"playlist":return await async function(t,e,r,n,i){const o=await fetch(`https://api.deezer.com/${t}/${e}?access_token=${ACCESS_TOKEN}&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,s,format,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:"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){ /*! * 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 D(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return z(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 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 C(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function m(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 T(this,t,e,r);case"latin1":case"binary":return A(this,t,e,r);case"base64":return _(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 I(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 L(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 Y(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||O(t,1,this.length),this[t]},u.prototype.readUInt16LE=function(t,e){return e||O(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUInt16BE=function(t,e){return e||O(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUInt32LE=function(t,e){return e||O(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||O(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||O(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||O(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||O(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){e||O(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||O(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||O(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||O(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||O(t,4,this.length),i.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return e||O(t,4,this.length),i.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return e||O(t,8,this.length),i.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return e||O(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)||I(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||I(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||I(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},u.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||I(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},u.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||I(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||I(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);I(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);I(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||I(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||I(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},u.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||I(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},u.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||I(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||I(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 Y(this,t,e,!0,r)},u.prototype.writeFloatBE=function(t,e,r){return Y(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 z(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(F,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function N(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 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 y(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function m(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){ /*! 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, 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,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 diff --git a/index.html b/index.html index 28af516..a64b546 100644 --- a/index.html +++ b/index.html @@ -31,7 +31,7 @@

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, sbc_256, misc

+

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

diff --git a/index.js b/index.js index eead0f3..4515da2 100644 --- a/index.js +++ b/index.js @@ -16,12 +16,89 @@ const format_string_to_num = { 'mp4_ra3': '15', 'mhm1_ra1': '16', 'mhm1_ra2': '17', - 'mhm1': '18', + 'mhm1_ra3': '18', 'sbc_256': '12', 'misc': '0', } +const format_string_to_gw = { + '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 gw_api_call(method, params) { + if (method === 'deezer.getUserData') { + checkForm = '' + } + + if (!params) { + params = {} + } + + let cookies = `arl=${ARL}` + if (sid) { + cookies += `; sid=${sid}` + } + + const headers = new Headers({ 'cookie': cookies }) + + const init = { + method: 'POST', + headers: headers, + 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 json = await response.json() + + if (json.error.length !== 0) { + return new Response(JSON.stringify(json.error), { status: 500, headers: { 'content-type': 'application/json' } }) + } + + if (method === "deezer.getUserData") { + checkForm = json.results.checkForm + await KV.put('checkForm', checkForm) + + sid = response.headers.get('set-cookie').split(',').map(v => v.trimStart())[0] + sid = sid.match(/^sid=(fr[\da-f]+)/)[1] + await KV.put('sid', sid) + } + + return json.results +} + 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 + const expiration = user_data.USER.OPTIONS.expiration_timestamp + + await KV.put('license_token', license_token, { expiration: expiration }) + } + const url = new URL(request.url) const id = url.pathname.split('/')[2] @@ -52,36 +129,60 @@ async function handler(type, request) { } async function track(id, format, tagging) { - const response = await fetch(`https://api.deezer.com/streaming_url.php?access_token=${ACCESS_TOKEN}&track_id=${id}`) - const json = await response.json() - if (json.error !== undefined) { - return new Response(JSON.stringify(json.error), { status: 403, headers: { 'content-type': "application/json" } }) + const json = await gw_api_call('song.getData', { 'SNG_ID': id }) + if (json.constructor.name === 'Response') { + return json } - if (json.id < 0) { // user-uploaded track + if (parseInt(json.SNG_ID) < 0) { // user-uploaded track format = 'misc' } + if (json['FILESIZE_' + format_string_to_gw[format]] == false) { + return new Response('Format unavailable', { status: 403, headers: { 'content-type': 'text/plain' } }) + } + const wasm = await import('./pkg') - encrypted = !['320', 'flac'].includes(format) - if (!encrypted) { // server-side stream url + legacy_url = !['320', 'flac'].includes(format) + if (!legacy_url) { // server-side stream url // needed if track has fallback, like https://www.deezer.com/track/11835714 - let urls - if (!json.alternative) { - urls = json + let track_token + if (json.FALLBACK !== undefined) { + track_token = json.FALLBACK.TRACK_TOKEN } else { - const temp = await fetch(`https://api.deezer.com/streaming_url.php?access_token=${ACCESS_TOKEN}&track_id=${json.alternative.id}`) - urls = await temp.json() + track_token = json.TRACK_TOKEN } - result = urls['url_' + format] - - if (result === undefined) { - return new Response('Format unavailable', { status: 403, headers: { 'content-type': 'text/plain' } }) + const body = { + license_token: license_token, + media: [ + { + type: "FULL", + formats: [ + { + cipher: "BF_CBC_STRIPE", + format: format_string_to_gw[format] + } + ] + } + ], + track_tokens: [ track_token ] } - result = wasm.decrypt_stream_url(result) + const init = { + method: 'POST', + body: JSON.stringify(body) + } + + const resp = await fetch('https://media.deezer.com/v1/get_url', init) + if (resp.status !== 200) { + return new Response("Couldn't get stream URL", { status: 403, headers: { 'content-type': 'text/plain' } }) + } + + const media_json = await resp.json() + + result = media_json.data[0].media[0].sources[0].url } else { // legacy stream url result = await legacy_track_url(json, format, wasm.legacy_stream_url) if (typeof result === 'object') { @@ -89,55 +190,48 @@ async function track(id, format, tagging) { } } - let track - if (tagging || encrypted) { - track = await fetch(result) - if (track.status !== 200) { - return new Response("Couldn't get track stream", { status: 403, headers: { 'content-type': 'text/plain' } }) - } + const track = await fetch(result) + if (track.status !== 200) { + return new Response("Couldn't get track stream", { status: 403, headers: { 'content-type': 'text/plain' } }) } let id3 if (tagging) { id3 = new ID3Writer(Buffer.alloc(0)); id3.padding = 0 - id3.setFrame('TIT2', json.title) - .setFrame('TALB', json.album.title) - .setFrame('TPE2', json.artist.name) + id3.setFrame('TIT2', json.SNG_TITLE) + .setFrame('TALB', json.ALB_TITLE) + .setFrame('TPE2', json.ART_NAME) - if (json.contributors !== undefined) { - contr_list = []; - for (const c of json.contributors) { - contr_list.push(c.name) + if (json.ARTISTS !== undefined) { + artist_list = []; + for (const a of json.ARTISTS) { + artist_list.push(a.ART_NAME) } - id3.setFrame('TPE1', contr_list) + id3.setFrame('TPE1', artist_list) } - if (json.track_position !== undefined) { - id3.setFrame('TRCK', json.track_position) + if (json.TRACK_NUMBER !== undefined) { + id3.setFrame('TRCK', json.TRACK_NUMBER) } - if (json.disk_number !== undefined) { - id3.setFrame('TPOS', json.disk_number) + if (json.DISK_NUMBER !== undefined) { + id3.setFrame('TPOS', json.DISK_NUMBER) } - if (json.isrc !== "") { - id3.setFrame('TSRC', json.isrc) + if (json.ISRC !== "") { + id3.setFrame('TSRC', json.ISRC) } - if (json.bpm !== undefined) { - id3.setFrame('TBPM', json.bpm) - } - - if (json.release_date !== undefined) { - const split = json.release_date.split('-') + if (json.PHYSICAL_RELEASE_DATE !== undefined) { + const split = json.PHYSICAL_RELEASE_DATE.split('-') id3.setFrame('TYER', split[0]) id3.setFrame('TDAT', split[2] + split[1]) } - if (json.md5_image !== "") { - const url = `https://cdns-images.dzcdn.net/images/cover/${json.md5_image}/1000x1000-000000-80-0-0.jpg` + if (json.ALB_PICTURE !== "") { + const url = `https://cdns-images.dzcdn.net/images/cover/${json.ALB_PICTURE}/1000x1000-000000-80-0-0.jpg` const cover = await fetch(url) const coverBuffer = await cover.arrayBuffer() @@ -152,31 +246,23 @@ async function track(id, format, tagging) { } let { readable, writable } = new TransformStream() - let writer - if (tagging || encrypted) { - writer = writable.getWriter() - } + const writer = writable.getWriter() if (tagging) { writer.write(id3.arrayBuffer) } // needed if track has fallback, like https://www.deezer.com/track/11835714 - if (json.alternative) { - id = json.alternative.id.toString() - } - - if (encrypted) { - const cipher = new wasm.Cipher(id) - const length = parseInt(track.headers.get('Content-Length')) - pipeDecryptedStream(writer, track.body, length, cipher) - } else if (tagging) { - writer.releaseLock() - track.body.pipeTo(writable) - } else { - return new Response(null, { status: 302, headers: { 'location': result } }) + if (json.FALLBACK) { + id = json.FALLBACK.SNG_ID } + const cipher = new wasm.Cipher(id) + + const length = parseInt(track.headers.get('Content-Length')) + + pipeDecryptedStream(writer, track.body, length, cipher) + return new Response(readable, { status: 200, headers: { 'content-type': 'audio/mpeg' } }) } @@ -217,25 +303,21 @@ async function pipeDecryptedStream(writer, body, length, cipher) { function legacy_track_url(json, format, url_func) { // needed if track has fallback, like https://www.deezer.com/track/11835714 - if (json.alternative) { - json = json.alternative + if (json.FALLBACK) { + json = json.FALLBACK } - const id = json.id - const md5_origin = json.md5_origin - const media_version = json.media_version - - if (json['filesize_' + format] == false) { - return new Response('Format unavailable', { status: 403, headers: { 'content-type': 'text/plain' } }) - } + const id = json.SNG_ID.toString() + const md5_origin = json.MD5_ORIGIN + const media_version = json.MEDIA_VERSION format = format_string_to_num[format] - return url_func(md5_origin, format, id.toString(), media_version) + return url_func(md5_origin, format, id, media_version) } async function m3u8(type, id, format, tagging, host) { - const response = await fetch(`https://api.deezer.com/${type}/${id}?access_token=${ACCESS_TOKEN}&limit=-1`) + const response = await fetch(`https://api.deezer.com/${type}/${id}?limit=-1`) const json = await response.json() if (json.error !== undefined) { return new Response(JSON.stringify(json.error), { status: 403, headers: { 'content-type': "application/json" } }) diff --git a/src/lib.rs b/src/lib.rs index 1b1e5e5..2fe9e4e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,13 @@ use wasm_bindgen::prelude::*; use blowfish::Blowfish; -use aes::{Aes128, Aes256}; +use aes::Aes128; use block_modes::{BlockMode, Cbc, Ecb}; use block_modes::block_padding::{NoPadding, ZeroPadding}; use md5::{Md5, Digest}; type BfCbc = Cbc; type Aes128Ecb = Ecb; -type Aes256Ecb = Ecb; const TRACK_CDN_KEY: [u8; 16] = [106, 111, 54, 97, 101, 121, 54, 104, 97, 105, 100, 50, 84, 101, 105, 104]; const BF_SECRET: [u8; 16] = [103, 52, 101, 108, 53, 56, 119, 99, 48, 122, 118, 102, 57, 110, 97, 49]; @@ -63,12 +62,4 @@ pub fn legacy_stream_url(md5_origin: &str, format: &str, id: &str, media_version let ciphertext = cipher.encrypt_vec(&metadata_hash); format!("https://cdns-proxy-{}.dzcdn.net/mobile/1/{}", md5_origin.chars().next().unwrap(), hex::encode(ciphertext)) -} - -#[wasm_bindgen] -pub fn decrypt_stream_url(url: &str) -> String { - let url = hex::decode(url).unwrap(); - let cipher = Aes256Ecb::new_from_slices("2f5b4c9785ddc367975b83d90dc46f5c".as_bytes(), Default::default()).unwrap(); - let url = cipher.decrypt_vec(&url).unwrap(); - String::from_utf8_lossy(&url).into_owned() } \ No newline at end of file diff --git a/wrangler.toml b/wrangler.toml index de810fe..45c2260 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -2,4 +2,8 @@ name = "dz" type = "webpack" webpack_config = "webpack.config.js" account_id = "03479b0523a52b140e0dabac40cb0fc8" -workers_dev = true \ No newline at end of file +workers_dev = true +kv_namespaces = [ + { binding = "KV", id = "974c0967a84e415daa054bbbcc7f80c6", preview_id = "cfcc6491f3484cbca664913836635113" } +] +vars = { ARL = "haha nope" } \ No newline at end of file