PageSourceSearch

https://valedoiguacufm.com.br/js/radio-player.js?3112

js valedoiguacufm.com.br collected 2026-10-08 12:14:16 UTC 20,239 bytes, 567 lines download raw bytes

1/*
2The MIT License (MIT)
3
4Github: https://github.com/gsavio
5
6Permission is hereby granted, free of charge, to any person obtaining a copy of
7this software and associated documentation files (the "Software"), to deal in
8the Software without restriction, including without limitation the rights to
9use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10the Software, and to permit persons to whom the Software is furnished to do so,
11subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24//const RADIO_NAME = settings.radio_name;
25const URL_STREAMING = settings.url_streaming;
26const STREAMING_TYPE = settings.streaming_type;
27//const API_KEY = settings.api_key;
28//const HISTORIC = settings.historic;
29//const NEXT_SONG = settings.next_song;
30//const DEFAULT_COVER_ART = settings.default_cover_art;
31
32window.onload = function () {
33    var page = new Page;
34    //page.changeTitlePage();
35    page.setVolume();
36
37    /*var player = new Player();
38    player.play();
39	
40	
41    getStreamingData();
42    // Interval to get streaming data in miliseconds
43    setInterval(function () {
44        getStreamingData();
45    }, 4000);
46
47    var coverArt = document.getElementsByClassName('cover-album')[0];
48
49    coverArt.style.height = coverArt.offsetWidth + 'px';
50	*/
51}
52
53// DOM control
54function Page() {
55    // this.changeTitlePage = function (title = RADIO_NAME) {
56    //     document.title = title;
57    // };
58
59    // this.refreshCurrentSong = function (song, artist) {
60    //     var currentSong = document.getElementById('currentSong');
61    //     var currentArtist = document.getElementById('currentArtist');
62
63    //     if (song !== currentSong.innerHTML) {
64    //         // Animate transition
65    //         currentSong.className = 'animated flipInY text-uppercase';
66    //         currentSong.innerHTML = song;
67
68    //         currentArtist.className = 'animated flipInY text-capitalize';
69    //         currentArtist.innerHTML = artist;
70
71    //         // Refresh modal title
72    //         document.getElementById('lyricsSong').innerHTML = song + ' - ' + artist;
73
74    //         // Remove animation classes
75    //         setTimeout(function () {
76    //             currentSong.className = 'text-uppercase';
77    //             currentArtist.className = 'text-capitalize';
78    //         }, 2000);
79    //     }
80    // }
81
82    // this.refreshHistoric = function (info, n) {
83    //     var $historicDiv = document.querySelectorAll('#historicSong article');
84    //     var $songName = document.querySelectorAll('#historicSong article .music-info .song');
85    //     var $artistName = document.querySelectorAll('#historicSong article .music-info .artist');
86
87    //     // Default cover art
88    //     var urlCoverArt = DEFAULT_COVER_ART;
89
90    //     // Get cover art for song history
91    //     var xhttp = new XMLHttpRequest();
92    //     xhttp.onreadystatechange = function () {
93    //         if (this.readyState === 4 && this.status === 200) {
94    //             var data = JSON.parse(this.responseText);
95    //             var artworkUrl100 = (data.resultCount) ? data.results[0].artworkUrl100 : urlCoverArt;
96
97    //             document.querySelectorAll('#historicSong article .cover-historic')[n].style.backgroundImage = 'url(' + artworkUrl100 + ')';
98    //         }
99    //         // Formating characters to UTF-8
100    //         var music = info.song.replace(/'/g, '\'');
101    //         var songHist = music.replace(/&/g, '&');
102
103    //         var artist = info.artist.replace(/'/g, '\'');
104    //         var artistHist = artist.replace(/&/g, '&');
105
106    //         $songName[n].innerHTML = songHist;
107    //         $artistName[n].innerHTML = artistHist;
108
109    //         // Add class for animation
110    //         $historicDiv[n].classList.add('animated');
111    //         $historicDiv[n].classList.add('slideInRight');
112    //     }
113    //     xhttp.open('GET', 'https://itunes.apple.com/search?term=' + info.artist + ' ' + info.song + '&media=music&limit=1', true);
114    //     xhttp.send();
115
116    //     setTimeout(function () {
117    //         for (var j = 0; j < 2; j++) {
118    //             $historicDiv[j].classList.remove('animated');
119    //             $historicDiv[j].classList.remove('slideInRight');
120    //         }
121    //     }, 2000);
122    // }
123
124    // this.refreshCover = function (song = '', artist) {
125    //     // Default cover art
126    //     var urlCoverArt = DEFAULT_COVER_ART;
127
128    //     var xhttp = new XMLHttpRequest();
129    //     xhttp.onreadystatechange = function () {
130    //         var coverArt = document.getElementById('currentCoverArt');
131    //         var coverBackground = document.getElementById('bgCover');
132
133    //         // Get cover art URL on iTunes API
134    //         if (this.readyState === 4 && this.status === 200) {
135    //             var data = JSON.parse(this.responseText);
136    //             var artworkUrl100 = (data.resultCount) ? data.results[0].artworkUrl100 : urlCoverArt;
137
138    //             // Se retornar algum dado, alterar a resolução da imagem ou definir a padrão
139    //             urlCoverArt = (artworkUrl100 != urlCoverArt) ? artworkUrl100.replace('100x100bb', '512x512bb') : urlCoverArt;
140    //             var urlCoverArt96 = (artworkUrl100 != urlCoverArt) ? urlCoverArt.replace('512x512bb', '96x96bb') : urlCoverArt;
141    //             var urlCoverArt128 = (artworkUrl100 != urlCoverArt) ? urlCoverArt.replace('512x512bb', '128x128bb') : urlCoverArt;
142    //             var urlCoverArt192 = (artworkUrl100 != urlCoverArt) ? urlCoverArt.replace('512x512bb', '192x192bb') : urlCoverArt;
143    //             var urlCoverArt256 = (artworkUrl100 != urlCoverArt) ? urlCoverArt.replace('512x512bb', '256x256bb') : urlCoverArt;
144    //             var urlCoverArt384 = (artworkUrl100 != urlCoverArt) ? urlCoverArt.replace('512x512bb', '384x384bb') : urlCoverArt;
145
146    //             coverArt.style.backgroundImage = 'url(' + urlCoverArt + ')';
147    //             coverArt.className = 'animated bounceInLeft';
148
149    //             coverBackground.style.backgroundImage = 'url(' + urlCoverArt + ')';
150
151    //             setTimeout(function () {
152    //                 coverArt.className = '';
153    //             }, 2000);
154
155    //             if ('mediaSession' in navigator) {
156    //                 navigator.mediaSession.metadata = new MediaMetadata({
157    //                     title: song,
158    //                     artist: artist,
159    //                     artwork: [{
160    //                             src: urlCoverArt96,
161    //                             sizes: '96x96',
162    //                             type: 'image/png'
163    //                         },
164    //                         {
165    //                             src: urlCoverArt128,
166    //                             sizes: '128x128',
167    //                             type: 'image/png'
168    //                         },
169    //                         {
170    //                             src: urlCoverArt192,
171    //                             sizes: '192x192',
172    //                             type: 'image/png'
173    //                         },
174    //                         {
175    //                             src: urlCoverArt256,
176    //                             sizes: '256x256',
177    //                             type: 'image/png'
178    //                         },
179    //                         {
180    //                             src: urlCoverArt384,
181    //                             sizes: '384x384',
182    //                             type: 'image/png'
183    //                         },
184    //                         {
185    //                             src: urlCoverArt,
186    //                             sizes: '512x512',
187    //                             type: 'image/png'
188    //                         }
189    //                     ]
190    //                 });
191    //             }
192    //         }
193    //     }
194    //     xhttp.open('GET', 'https://itunes.apple.com/search?term=' + artist + ' ' + song + '&media=music&limit=1', true);
195    //     xhttp.send();
196    // }
197
198    this.changeVolumeIndicator = function (volume) {
199        //document.getElementById('volIndicator').innerHTML = volume;
200
201        if (typeof (Storage) !== 'undefined') {
202            localStorage.setItem('volume', volume);
203        }
204    }
205
206    this.setVolume = function () {
207        if (typeof (Storage) !== 'undefined') {
208            var volumeLocalStorage = (!localStorage.getItem('volume')) ? 50 : localStorage.getItem('volume');
209            document.getElementById('volume').value = volumeLocalStorage;
210            //document.getElementById('volIndicator').innerHTML = volumeLocalStorage;
211        }
212    }
213
214    // this.refreshLyric = function (currentSong, currentArtist) {
215    //     var xhttp = new XMLHttpRequest();
216    //     xhttp.onreadystatechange = function () {
217    //         if (this.readyState === 4 && this.status === 200) {
218    //             var data = JSON.parse(this.responseText);
219
220    //             var openLyric = document.getElementsByClassName('lyrics')[0];
221
222    //             if (data.type === 'exact' || data.type === 'aprox') {
223    //                 var lyric = data.mus[0].text;
224
225    //                 document.getElementById('lyric').innerHTML = lyric.replace(/\n/g, '<br />');
226    //                 openLyric.style.opacity = "1";
227    //                 openLyric.setAttribute('data-toggle', 'modal');
228    //             } else {
229    //                 openLyric.style.opacity = "0.3";
230    //                 openLyric.removeAttribute('data-toggle');
231
232    //                 var modalLyric = document.getElementById('modalLyrics');
233    //                 modalLyric.style.display = "none";
234    //                 modalLyric.setAttribute('aria-hidden', 'true');
235    //                 (document.getElementsByClassName('modal-backdrop')[0]) ? document.getElementsByClassName('modal-backdrop')[0].remove(): '';
236    //             }
237    //         } else {
238    //             document.getElementsByClassName('lyrics')[0].style.opacity = "0.3";
239    //             document.getElementsByClassName('lyrics')[0].removeAttribute('data-toggle');
240    //         }
241    //     }
242    //     xhttp.open('GET', 'https://api.vagalume.com.br/search.php?apikey=' + API_KEY + '&art=' + currentArtist + '&mus=' + currentSong.toLowerCase(), true);
243    //     xhttp.send()
244    // }
245}
246
247var audio = new Audio(URL_STREAMING);
248
249// Player control
250function Player() {
251    this.play = async function () {
252        await audio.play();
253
254        var defaultVolume = document.getElementById('volume').value;
255
256        if (typeof (Storage) !== 'undefined') {
257            if (localStorage.getItem('volume') !== null) {
258                audio.volume = intToDecimal(localStorage.getItem('volume'));
259            } else {
260                audio.volume = intToDecimal(defaultVolume);
261            }
262        } else {
263            audio.volume = intToDecimal(defaultVolume);
264        }
265        //document.getElementById('volIndicator').innerHTML = defaultVolume;
266    };
267
268    this.pause = function () {
269        audio.pause();
270    };
271}
272
273// On play, change the button to pause
274audio.onplay = function () {
275    var botao = document.getElementById('playerButton');
276
277    if (botao.className === 'icon-play') {
278        botao.className = 'icon-pause';
279    }
280}
281
282// On pause, change the button to play
283audio.onpause = function () {
284    var botao = document.getElementById('playerButton');
285
286    if (botao.className === 'icon-pause') {
287        botao.className = 'icon-play';
288    }
289}
290
291// Unmute when volume changed
292audio.onvolumechange = function () {
293    if (audio.volume > 0) {
294        audio.muted = false;
295    }
296}
297
298//validar stream
299// audio.onerror = function () {
300//     var confirmacao = confirm('Erro ao carregar stream. \nClick OK to try again.');
301
302//     if (confirmacao) {
303//         window.location.reload();
304//     }
305// }
306
307document.getElementById('volume').oninput = function () {
308    audio.volume = intToDecimal(this.value);
309
310    var page = new Page();
311    page.changeVolumeIndicator(this.value);
312}
313
314function togglePlay() {
315    if (!audio.paused) {
316        audio.pause();
317    } else {
318        audio.load();
319        audio.play();
320    }
321}
322
323function volumeUp() {
324    var vol = audio.volume;
325    if(audio) {
326        if(audio.volume >= 0 && audio.volume < 1) {
327            audio.volume = (vol + .01).toFixed(2);
328        }
329    }
330}
331
332function volumeDown() {
333    var vol = audio.volume;
334    if(audio) {
335        if(audio.volume >= 0.01 && audio.volume <= 1) {
336            audio.volume = (vol - .01).toFixed(2);
337        }
338    }
339}
340
341function mute() {
342    if (!audio.muted) {
343        //document.getElementById('volIndicator').innerHTML = 0;
344        document.getElementById('volume').value = 0;
345        audio.volume = 0;
346        audio.muted = true;
347    } else {
348        var localVolume = localStorage.getItem('volume');
349        //document.getElementById('volIndicator').innerHTML = localVolume;
350        document.getElementById('volume').value = localVolume;
351        audio.volume = intToDecimal(localVolume);
352        audio.muted = false;
353    }
354}
355
356function getStreamingData() {
357    var xhttp = new XMLHttpRequest();
358    xhttp.onreadystatechange = function () {
359
360        if (this.readyState === 4 && this.status === 200) {
361
362            if(this.response.length === 0) {
363                console.log('%cdebug', 'font-size: 22px')
364            }
365
366            var data = JSON.parse(this.responseText);
367
368            var page = new Page();
369
370            var currentSongElement = document.getElementById('currentSong').innerHTML.replace(/&apos;/g, '\'');
371            let currentSongEl = currentSongElement.replace(/&amp;/g, '&');
372
373            // Formating characters to UTF-8
374            let song = data.currentSong.replace(/&apos;/g, '\'');
375            let currentSong = song.replace(/&amp;/g, '&');
376
377            let artist = data.currentArtist.replace(/&apos;/g, '\'');
378            let currentArtist = artist.replace(/&amp;/g, '&');
379            currentArtist = currentArtist.replace('  ', ' '); 
380            
381            // Change the title
382            document.title = currentSong + ' - ' + currentArtist + ' | ' + RADIO_NAME;
383
384            if (currentSongEl.trim() !== currentSong.trim()) {
385                page.refreshCover(currentSong, currentArtist);
386                page.refreshCurrentSong(currentSong, currentArtist);
387                page.refreshLyric(currentSong, currentArtist);
388
389                for (var i = 0; i < 2; i++) {
390                    page.refreshHistoric(data.songHistory[i], i);
391                }
392            }
393        } 
394    };
395
396    var d = new Date();
397
398    // Requisition with timestamp to prevent cache on mobile devices
399    xhttp.open('GET', 'api.php?url=' + URL_STREAMING + '&streamtype=' + STREAMING_TYPE + '&historic=' + HISTORIC + '&next=' + NEXT_SONG + '&t=' + d.getTime(), true);
400    xhttp.send();
401}
402
403// Player control by keys
404//removed action
405// document.addEventListener('keydown', function (k) {
406//     var k = k || window.event;
407//     var key = k.keyCode || k.which;
408    
409//     var slideVolume = document.getElementById('volume');
410
411//     var page = new Page();
412
413//     switch (key) {
414//         // Arrow up
415//         case 38:
416//             volumeUp();
417//             slideVolume.value = decimalToInt(audio.volume);
418//             page.changeVolumeIndicator(decimalToInt(audio.volume));
419//             break;
420//         // Arrow down
421//         case 40:
422//             volumeDown();
423//             slideVolume.value = decimalToInt(audio.volume);
424//             page.changeVolumeIndicator(decimalToInt(audio.volume));
425//             break;
426//         // Spacebar
427//         case 32:
428//             togglePlay();
429//             break;
430//         // P
431//         case 80:
432//             togglePlay();
433//             break;
434//         // M
435//         case 77:
436//             mute();
437//             break;
438//         // 0
439//         case 48:
440//             audio.volume = 0;
441//             slideVolume.value = 0;
442//             page.changeVolumeIndicator(0);
443//             break;
444//         // 0 numeric keyboard
445//         case 96:
446//             audio.volume = 0;
447//             slideVolume.value = 0;
448//             page.changeVolumeIndicator(0);
449//             break;
450//         // 1
451//         case 49:
452//             audio.volume = .1;
453//             slideVolume.value = 10;
454//             page.changeVolumeIndicator(10);
455//             break;
456//         // 1 numeric key
457//         case 97:
458//             audio.volume = .1;
459//             slideVolume.value = 10;
460//             page.changeVolumeIndicator(10);
461//             break;
462//         // 2
463//         case 50:
464//             audio.volume = .2;
465//             slideVolume.value = 20;
466//             page.changeVolumeIndicator(20);
467//             break;
468//         // 2 numeric key
469//         case 98:
470//             audio.volume = .2;
471//             slideVolume.value = 20;
472//             page.changeVolumeIndicator(20);
473//             break;
474//         // 3
475//         case 51:
476//             audio.volume = .3;
477//             slideVolume.value = 30;
478//             page.changeVolumeIndicator(30);
479//             break;
480//         // 3 numeric key
481//         case 99:
482//             audio.volume = .3;
483//             slideVolume.value = 30;
484//             page.changeVolumeIndicator(30);
485//             break;
486//         // 4
487//         case 52:
488//             audio.volume = .4;
489//             slideVolume.value = 40;
490//             page.changeVolumeIndicator(40);
491//             break;
492//         // 4 numeric key
493//         case 100:
494//             audio.volume = .4;
495//             slideVolume.value = 40;
496//             page.changeVolumeIndicator(40);
497//             break;
498//         // 5
499//         case 53:
500//             audio.volume = .5;
501//             slideVolume.value = 50;
502//             page.changeVolumeIndicator(50);
503//             break;
504//         // 5 numeric key
505//         case 101:
506//             audio.volume = .5;
507//             slideVolume.value = 50;
508//             page.changeVolumeIndicator(50);
509//             break;
510//         // 6 
511//         case 54:
512//             audio.volume = .6;
513//             slideVolume.value = 60;
514//             page.changeVolumeIndicator(60);
515//             break;
516//         // 6 numeric key
517//         case 102:
518//             audio.volume = .6;
519//             slideVolume.value = 60;
520//             page.changeVolumeIndicator(60);
521//             break;
522//         // 7
523//         case 55:
524//             audio.volume = .7;
525//             slideVolume.value = 70;
526//             page.changeVolumeIndicator(70);
527//             break;
528//         // 7 numeric key
529//         case 103:
530//             audio.volume = .7;
531//             slideVolume.value = 70;
532//             page.changeVolumeIndicator(70);
533//             break;
534//         // 8
535//         case 56:
536//             audio.volume = .8;
537//             slideVolume.value = 80;
538//             page.changeVolumeIndicator(80);
539//             break;
540//         // 8 numeric key
541//         case 104:
542//             audio.volume = .8;
543//             slideVolume.value = 80;
544//             page.changeVolumeIndicator(80);
545//             break;
546//         // 9
547//         case 57:
548//             audio.volume = .9;
549//             slideVolume.value = 90;
550//             page.changeVolumeIndicator(90);
551//             break;
552//         // 9 numeric key
553//         case 105:
554//             audio.volume = .9;
555//             slideVolume.value = 90;
556//             page.changeVolumeIndicator(90);
557//             break;
558//     }
559// });
560
561function intToDecimal(vol) {
562    return vol / 100;
563}
564
565function decimalToInt(vol) {
566    return vol * 100;
567}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.