Skip to content

Commit

Permalink
deploy: 88ac7d0
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Mar 7, 2024
1 parent db1c525 commit a1062d6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
19 changes: 12 additions & 7 deletions SongDownloader/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var y=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import{store as q}from"@neptune";import{intercept as P}from"@neptune";import{storage as T}from"@plugin";import{appendStyle as $}from"@neptune/utils";var h=`
var b=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import{store as P}from"@neptune";import{intercept as _}from"@neptune";import{storage as N}from"@plugin";import{appendStyle as T}from"@neptune/utils";var k=`
.settings-section {
color: #ffffff;
padding: 20px;
Expand All @@ -17,8 +17,8 @@ var y=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,o)=>(t
.settings-spacer {
margin-bottom: 15px;
}
`;$(`
${h}
`;T(`
${k}
.download-button {
align-items: center;
display: flex;
Expand Down Expand Up @@ -71,10 +71,15 @@ ${h}
outline: none;
border-color: #4f4f4f;
}
`);import{html as B}from"@neptune/voby";import{storage as g}from"@plugin";var f=(n=>(n.HiRes="HI_RES_LOSSLESS",n.MQA="HI_RES",n.High="LOSSLESS",n))(f||{});var b=Object.values(f),S=new Set(b),v=["HI_RES_LOSSLESS","LOSSLESS"],m=Object.fromEntries(Object.entries(f).map(([t,e])=>[e,t]));g.desiredDownloadQuality??="HI_RES_LOSSLESS";var L=()=>B`<div class="settings-section">
`);import{html as I}from"@neptune/voby";import{storage as l}from"@plugin";var y=(n=>(n.HiRes="HI_RES_LOSSLESS",n.MQA="HI_RES",n.High="LOSSLESS",n))(y||{});var h=Object.values(y),S=new Set(h),v=["HI_RES_LOSSLESS","LOSSLESS"],g=Object.fromEntries(Object.entries(y).map(([t,e])=>[e,t]));import{store as L}from"@neptune";var{request:C}=b("https"),w=null,x=()=>{if(w===null)throw new Error("oAuthAccessToken token not set");let t=L.getState();return{Authorization:`Bearer ${w}`,"x-tidal-token":t.session.clientId}},f=t=>w=t,B=(t,e,o=0,n)=>new Promise((r,s)=>{let i=x();if(typeof o!="number")throw new Error("byteRangeStart must be a number");if(n!==void 0){if(typeof n!="number")throw new Error("byteRangeEnd must be a number");i.Range=`bytes=${o}-${n}`}let d=C(t,{headers:i},a=>{let c=-1;if(a.headers["content-range"]){let u=/\/(\d+)$/.exec(a.headers["content-range"]);u&&(c=parseInt(u[1],10))}else a.headers["content-length"]!==void 0&&(c=parseInt(a.headers["content-length"],10));let p=0,A=[];a.on("data",u=>{A.push(u),p+=u.length,e!==void 0&&e({total:c,downloaded:p,percent:p/c*100})}),a.on("end",()=>{let u=Buffer.concat(A);e!==void 0&&e({total:c,downloaded:c,percent:100}),r(u)})});d.on("error",s),d.end()});l.desiredDownloadQuality??="HI_RES_LOSSLESS";l.oAuthAccessToken??=null;l.oAuthAccessToken!==null&&f(l.oAuthAccessToken);var D=()=>I`<div class="settings-section">
<br class="settings-spacer" />
<h3 class="settings-header">OAuth Access Token</h3>
<p class="settings-explainer">Use Ctrl+Shift+I to open inspector tools. Go to Network and enter the Bearer token from a tidal api request here</p>
<input onChange=${({target:t})=>l.oAuthAccessToken=f(t.value===""?null:t.value)} value=${l.oAuthAccessToken} />
<h3 class="settings-header">Download Quality</h3>
<p class="settings-explainer">Select the desired max download quality:</p>
<select id="qualityDropdown" onChange=${t=>g.desiredDownloadQuality=t.target.value}>
${v.map(t=>B`<option value=${t} selected=${g.desiredDownloadQuality===t}>${m[t]}</option>`)}
<select id="qualityDropdown" onChange=${t=>l.desiredDownloadQuality=t.target.value}>
${v.map(t=>I`<option value=${t} selected=${l.desiredDownloadQuality===t}>${g[t]}</option>`)}
</select>
</div>`;var{createDecipheriv:D}=y("crypto"),O="UIlTTEMmmLfGowo/UC60x2H45W6MdGgTRfo/umg4754=",k=async t=>{let e=Buffer.from(O,"base64"),o=Buffer.from(t,"base64"),n=o.slice(0,16),r=o.slice(16),s=D("aes-256-cbc",e,n).update(r),c=s.slice(0,16),i=s.slice(16,24);return{key:c,nonce:i}};import{store as R}from"@neptune";var{request:C}=y("https"),w=()=>{let t=R.getState();return{Authorization:`Bearer ${t.session.oAuthAccessToken}`,"x-tidal-token":t.session.clientId}},I=(t,e,o=0,n)=>new Promise((r,a)=>{let s=w();if(typeof o!="number")throw new Error("byteRangeStart must be a number");if(n!==void 0){if(typeof n!="number")throw new Error("byteRangeEnd must be a number");s.Range=`bytes=${o}-${n}`}let c=C(t,{headers:s},i=>{let d=-1;if(i.headers["content-range"]){let l=/\/(\d+)$/.exec(i.headers["content-range"]);l&&(d=parseInt(l[1],10))}else i.headers["content-length"]!==void 0&&(d=parseInt(i.headers["content-length"],10));let u=0,x=[];i.on("data",l=>{x.push(l),u+=l.length,e!==void 0&&e({total:d,downloaded:u,percent:u/d*100})}),i.on("end",()=>{let l=Buffer.concat(x);e!==void 0&&e({total:d,downloaded:d,percent:100}),r(l)})});c.on("error",a),c.end()});var A=async(t,e)=>{if(!S.has(e))throw new Error(`Invalid audio quality: ${e}, should be one of ${b.join(", ")}`);if(t===void 0)throw new Error("trackId is required");let o=`https://desktop.tidal.com/v1/tracks/${t}/playbackinfopostpaywall/v4?audioquality=${e}&playbackmode=STREAM&assetpresentation=FULL`,n=await fetch(o,{headers:w()}).then(a=>a.json()),r=JSON.parse(atob(n.manifest));if(r.encryptionType!=="OLD_AES")throw new Error(`Unexpected manifest encryption type ${r.encryptionType}`);return n.manifest=r,n.cryptKey=await k(r.keyId),n};var H=y("crypto"),Q=async(t,e,o)=>{let n=Buffer.concat([o,Buffer.alloc(8,0)]),r=new H.createDecipheriv("aes-128-ctr",e,n);return Buffer.concat([r.update(t),r.final()])};var E=(t,e)=>{let o=URL.createObjectURL(t),n=document.createElement("a");n.href=o,n.download=e,n.click(),URL.revokeObjectURL(o)};var M=async(t,e,o,n)=>{let r=await A(t,o),{key:a,nonce:s}=r.cryptKey,c=r.manifest.urls[0],i=await I(c,n),d=await Q(i,a,s);E(new Blob([d],{type:"application/octet-stream"}),`${e} [${m[r.audioQuality]}].flac`)};var p={},_=t=>({prep:()=>{let e=p[t];e.disabled=!0,e.classList.add("loading"),e.textContent="Fetching Meta..."},tick:({total:e,downloaded:o,percent:n})=>{let r=p[t];r.style.setProperty("--progress",`${n}%`);let a=(o/1048576).toFixed(0),s=(e/1048576).toFixed(0);r.textContent=`Downloading... ${a}/${s}MB ${n.toFixed(0)}%`},clear:()=>{let e=p[t];e.classList.remove("loading"),e.disabled=!1,e.style.removeProperty("--progress"),e.textContent="Download"}}),N=P("contextMenu/OPEN_MEDIA_ITEM",([t])=>{setTimeout(()=>{let o=q.getState().content.mediaItems[+t.id]?.item;if(o?.contentType!=="track"||o.id===void 0)return;let n=document.querySelector('[data-type="list-container__context-menu"]');if(n===null)return;document.getElementsByClassName("download-button").length>=1&&document.getElementsByClassName("download-button")[0].remove();let r=document.createElement("button");r.type="button",r.role="menuitem",r.textContent="Download",r.className="download-button",p[o.id]?.disabled===!0&&(r.disabled=!0,r.classList.add("loading")),p[o.id]=r,n.appendChild(r);let a=o.artist??o.artists?.[0],s=a!==void 0?` by ${a.name}`:"",c=`${o.title}${s}`,{prep:i,tick:d,clear:u}=_(o.id);r.addEventListener("click",()=>{o.id!==void 0&&(i(),M(o.id,c,T.desiredDownloadQuality,d).then(u))})})}),ht=N;export{L as Settings,ht as onUnload};
</div>`;var{createDecipheriv:R}=b("crypto"),H="UIlTTEMmmLfGowo/UC60x2H45W6MdGgTRfo/umg4754=",O=async t=>{let e=Buffer.from(H,"base64"),o=Buffer.from(t,"base64"),n=o.slice(0,16),r=o.slice(16),i=R("aes-256-cbc",e,n).update(r),d=i.slice(0,16),a=i.slice(16,24);return{key:d,nonce:a}};var Q=async(t,e)=>{if(!S.has(e))throw new Error(`Invalid audio quality: ${e}, should be one of ${h.join(", ")}`);if(t===void 0)throw new Error("trackId is required");let o=`https://desktop.tidal.com/v1/tracks/${t}/playbackinfopostpaywall/v4?audioquality=${e}&playbackmode=STREAM&assetpresentation=FULL`,n=await fetch(o,{headers:x()}).then(s=>{if(s.status===401)throw alert("Failed to fetch Stream Info... Invalid OAuth Access Token! Please update it in settings."),f(null),new Error("Invalid OAuth Access Token!");return s.json()}),r=JSON.parse(atob(n.manifest));if(r.encryptionType!=="OLD_AES")throw new Error(`Unexpected manifest encryption type ${r.encryptionType}`);return n.manifest=r,n.cryptKey=await O(r.keyId),n};var q=b("crypto"),E=async(t,e,o)=>{let n=Buffer.concat([o,Buffer.alloc(8,0)]),r=new q.createDecipheriv("aes-128-ctr",e,n);return Buffer.concat([r.update(t),r.final()])};var $=(t,e)=>{let o=URL.createObjectURL(t),n=document.createElement("a");n.href=o,n.download=e,n.click(),URL.revokeObjectURL(o)};var M=async(t,e,o,n)=>{let r=await Q(t,o),{key:s,nonce:i}=r.cryptKey,d=r.manifest.urls[0],a=await B(d,n),c=await E(a,s,i);$(new Blob([c],{type:"application/octet-stream"}),`${e} [${g[r.audioQuality]}].flac`)};var m={},U=t=>({prep:()=>{let e=m[t];e.disabled=!0,e.classList.add("loading"),e.textContent="Fetching Meta..."},tick:({total:e,downloaded:o,percent:n})=>{let r=m[t];r.style.setProperty("--progress",`${n}%`);let s=(o/1048576).toFixed(0),i=(e/1048576).toFixed(0);r.textContent=`Downloading... ${s}/${i}MB ${n.toFixed(0)}%`},clear:()=>{let e=m[t];e.classList.remove("loading"),e.disabled=!1,e.style.removeProperty("--progress"),e.textContent="Download"}}),F=_("contextMenu/OPEN_MEDIA_ITEM",([t])=>{setTimeout(()=>{let o=P.getState().content.mediaItems[+t.id]?.item;if(o?.contentType!=="track"||o.id===void 0)return;let n=document.querySelector('[data-type="list-container__context-menu"]');if(n===null)return;document.getElementsByClassName("download-button").length>=1&&document.getElementsByClassName("download-button")[0].remove();let r=document.createElement("button");r.type="button",r.role="menuitem",r.textContent="Download",r.className="download-button",m[o.id]?.disabled===!0&&(r.disabled=!0,r.classList.add("loading")),m[o.id]=r,n.appendChild(r);let s=o.artist??o.artists?.[0],i=s!==void 0?` by ${s.name}`:"",d=`${o.title}${i}`,{prep:a,tick:c,clear:p}=U(o.id);r.addEventListener("click",()=>{o.id!==void 0&&(a(),M(o.id,d,N.desiredDownloadQuality,c).then(p))})})}),St=F;export{D as Settings,St as onUnload};
2 changes: 1 addition & 1 deletion SongDownloader/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"Song Downloader","description":"Download tidal songs as FLAC files.","author":"Inrixia","hash":"8bfb2e87d9d7164f00b977cbfa7cd43c"}
{"name":"Song Downloader","description":"Download tidal songs as FLAC files.","author":"Inrixia","hash":"b372c779a0814d535882d3f742ff1654"}
59 changes: 41 additions & 18 deletions TidalTags/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion TidalTags/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"Tidal Tags","description":"Adds tags showing track qualities and current song quality.","author":"Inrixia","hash":"bc86bda08ab3bdf0138fb16182f25e6c"}
{"name":"Tidal Tags","description":"Adds tags showing track qualities and current song quality.","author":"Inrixia","hash":"8825f1fc5c6cf32a4de5d9f5246a8d52"}

0 comments on commit a1062d6

Please sign in to comment.