Repository navigation
Expand file tree
/
Copy pathcustomradio.min.js
More file actions
51 lines (51 loc) · 6.84 KB
/
Copy pathcustomradio.min.js
File metadata and controls
51 lines (51 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function CustomRadio(){function W(){z&&clearInterval(z),z=null}function w(){g.setColor(U).fillRect(q)}function ah(){r&&clearInterval(r),r=null,s=null,h&&(h=null,E.defrag())}function t(){if(aa===!1)return;g.setColor(V),g.drawRect(b),g.drawRect(c),g.drawRect(q),g.drawRect(ab),g.drawRect(u),_()}function ai(){const d=a6.toUpperCase();const e='v'+a7;const a=5;const f=g.stringWidth(d);g.setColor(p).setFontAlign(-1,-1,0).setFontMonofonto16().drawString(d,c.x1,b.y1+8),g.setColor(A).setFontAlign(-1,-1,0).setFont('6x8').drawString(e,c.x1+f+a,b.y1+16),g.setColor(V).drawLine(c.x1,c.y1-a,c.x2,c.y1-a)}function aj(){W(),z=setInterval(drawFooter,af)}function X(d){let b=d.name;let c=p;d.type==='ptl'&&(b='FILE PATH TOO LONG!',c=F);const a=b.replace(/\.wav$/i,'');const e=a.length>21?a.slice(0,18)+'...':a;g.setColor(c).setFontAlign(1,-1,0).setFont('6x8').drawString(e,q.x2,q.y1+20)}function Y(){g.setColor(A).setFontAlign(1,1,0).setFont('6x8').drawString('Now Playing',q.x2,q.y1+15)}function Z(){const f=l*n;const h=d.slice(f,f+n);g.setColor(U).fillRect(c),g.setFontMonofonto16().setFontAlign(-1,-1,0);const a=4;const b=4;const i=5;const j=20;h.forEach((f,m)=>{const h=c.y1+m*j+i;let l=am(f);let k=A;f.type==='ptl'?m===e?k=F:k=ag:m===e&&(k=p),g.setColor(k);let d=c.x1;f.type==='folder'?(g.drawImage(P,d,h+a),d+=P.width+b):f.type==='up'?(g.drawImage(Q,d,h+a),d+=Q.width+b):f.type==='file'?(g.drawImage(R,d,h+a),d+=R.width+b):f.type==='ptl'?(g.drawImage(S,d,h+a),d+=S.width+b):f.type==='random'&&(g.drawImage(T,d,h+a),d+=T.width+b);const n=c.x2-2-d;l=al(l,n),g.drawString(l,d,h,!0)}),t()}function _(){}function ak(){}function al(a,f){if(g.stringWidth(a)<=f)return a;const d='...';const h=g.stringWidth(d);let b=0;let c=a.length;let e=0;while(b<=c){const d=b+c>>1;const i=a.slice(0,d);g.stringWidth(i)+h<=f?(e=d,b=d+1):c=d-1}return a.slice(0,e)+d}function am(b){let a=b.name;return b.type!=='folder'&&(a=a.replace(/\.wav$/i,'')),a}function an(b){const a=b.lastIndexOf('/');return a<=0?C:b.slice(0,a)}function ao(c){const b=Date.now();if(b-N<ac)return;if(N=b,c!==0)return a1(c*-1);const g=l*n;const a=d[g+e];if(!a)return;if(a.type==='random'){i?(i=!1,y()):m!==null?(i=!0,f='RANDOM',y()):a5();return}if(a.type==='ptl'){i=!1,f=null,m=null,Pip.radioClipPlaying=!1,y(),w(),Y(),X(a),t();return}if(a.type==='up'){a2(an(k));return}if(a.type==='folder'){a2(x(k,a.name));return}if(a.type==='file'){const b='/'+x(k,a.name);m===b?(f=null,y()):(i=!1,m!==null?(f=a,y()):B(a));return}}function ap(){W(),ah(),a4(),settings.idleTimeout=I,E.reboot()}function aq(a){a1(a)}function ar(){const a=[1,5,10,15,20];const b=a.findIndex(a=>a===Pip.brightness);const c=(b+1)%a.length;Pip.brightness=a[c],Pip.updateBrightness()}function as(a){try{return fs.readdir('/'+a),!0}catch(a){return!1}}function $(a,b){return('/'+x(a,b)).length>ad}function a0(g){let a=g||k;av();let b=[];try{b=fs.readdir('/'+a).filter(a=>a!=='.'&&a!=='..').sort()}catch(c){print('Failed to read dir:',a,c),b=[]}const c=[];const f=[];for(let d=0;d<b.length;d++){const e=b[d];const g=x(a,e);as(g)?c.push(e):/\.wav$/i.test(e)&&f.push(e)}d.push({type:'random',name:'RANDOM'}),a!==C&&d.push({type:'up',name:'BACK'}),c.forEach(b=>{$(a,b)?d.push({name:b,type:'ptl'}):d.push({name:b,type:'folder'})}),f.forEach(b=>{$(a,b)?d.push({name:b,type:'ptl'}):d.push({type:'file',name:b})}),v=d.filter(a=>a.type==='file'),print('Loaded folder '+a+': '+f.length+' songs, '+c.length+' folders.'),l=0,e=0,Z()}function a1(f){const a=l*n;const b=d.slice(a,a+n);const c=Math.floor((d.length-1)/n);e+=f,e<0?l>0?(l--,e=n-1):e=0:e>=b.length&&(l<c?(l++,e=0):e=b.length-1),Z()}function a2(a){i=!1,f=null,k=a,a0(k)}function at(){if(m=null,Pip.radioClipPlaying=!1,i){a3();return}if(f==='RANDOM'){f=null,a5();return}if(f){const a=f;f=null,B(a);return}w(),t()}function x(a,b){return a?b?a+'/'+b:a:b}function B(a){try{const b='/'+x(k,a.name);m=b,Pip.audioStart(b),Pip.radioClipPlaying=!0,j=a.name,w(),Y(),X(a)}catch(a){log('Error playing audio:',a),w(),Pip.radioClipPlaying=!1}t()}function a3(){const b=v;if(!b.length){i=!1;return}if(b.length===1){B(b[0]);return}if(!a||o>=a.length){if(a=b.slice(),G(a),j&&a.length>1&&a[0].name===j){const b=a[0];a[0]=a[1],a[1]=b}o=0}let c=a[o++];if(j&&c.name===j)if(o<a.length)c=a[o++];else{if(a=b.slice(),G(a),a.length>1&&a[0].name===j){const b=a[0];a[0]=a[1],a[1]=b}o=1,c=a[0]}B(c)}function a4(){Pip.removeAllListeners(K),Pip.removeAllListeners(L),Pip.removeAllListeners(M),Pip.removeAllListeners(O)}function au(){Pip.on(K,ao),Pip.on(L,aq),Pip.on(M,ar),Pip.on(O,at),setWatch(()=>ap(),BTN_POWER,{debounce:50,edge:'rising',repeat:!0})}function G(a){for(let b=a.length-1;b>0;b--){const c=(E.hwRand()>>>0)%(b+1);const d=a[b];a[b]=a[c],a[c]=d}}function a5(){if(i=!0,a=v.slice(),G(a),j&&a.length>1&&a[0].name===j){const b=1;const c=a[0];a[0]=a[b],a[b]=c}o=0,a3()}function y(){Pip.audioStop(),m=null,Pip.radioClipPlaying=!1,w(),t()}function av(){d=null,v=null,a=null,d=[],v=[],a=[]}const H={};const a6='Custom Radio';const a7='3.3.2';const a8=g.getWidth();const a9=g.getHeight();const aa=!1;let I=settings.idleTimeout;const J=40;const b={x1:60,y1:40,x2:a8-60,y2:a9-20};const c={x1:b.x1+10,y1:b.y1+30,x2:(b.x2+b.x1)/2+J,y2:b.y2-20};const ab={x1:c.x2,y1:b.y1+30,x2:b.x2-10,y2:b.y2-20};const q={x1:c.x2,y1:b.y2-100,x2:b.x2-10,y2:b.y2-60};const u={x1:c.x2+45,y1:b.y1+37,x2:b.x2-12,y2:b.y2-101};const K='knob1';const L='knob2';const M='torch';const ac=10;let N=0;const O='audioStopped';const C='RADIO';let m=null;let f=null;let j=null;const P=Graphics.createImage(`
.......XXXXX..
XXXXXXX.....XX
X............X
X............X
X............X
X............X
X............X
X............X
XXXXXXXXXXXXXX
`);const Q=Graphics.createImage(`
........X.....
.......XX.....
......XXX.....
.....XXXX.....
....XXXXX.....
.....XXXX.....
......XXX.....
.......XX.....
........X.....
`);const R=Graphics.createImage(`
..............
....XXXXXXXX..
....XX....XX..
....XX....XX..
....XX....XX..
....XX....XX..
..XXXX..XXXX..
..XXXX..XXXX..
..............
`);const S=Graphics.createImage(`
..............
..XX......XX..
...XX....XX...
....XX..XX....
.....XXXX.....
....XX..XX....
...XX....XX...
..XX......XX..
..............
`);const T=Graphics.createImage(`
..XX..........
.XX...........
XXXXXXXXXXXXX.
.XX...........
..XX......XX..
...........XX.
.XXXXXXXXXXXXX
...........XX.
..........XX..
`);const ad=56;let k=C;let v=[];const n=10;let l=0;let e=0;let d=null;let i=!1;let a=[];let o=0;const ae=50;let D=0;let h=null;let r=null;let s=null;const af=49.99923706054;let z=null;const U='#000000';const F='#FF0000';const ag=g.blendColor('#000',F,.5);const p=g.theme.fg;const A=g.blendColor('#000',p,.5);const V=g.blendColor('#000',p,.75);return H.run=function(){I=settings.idleTimeout,settings.idleTimeout=0,Pip.mode=MODE.RADIO,drawHeader(Pip.mode),a4(),au(),a0(k),ak(),_(),ai(),aj(),t()},H}CustomRadio().run()