updated API to v2 for better efficiency

Este commit está contenido en:
Joey
2024-01-29 21:41:21 +00:00
cometido por GitHub
padre 3a35c7b3f0
commit 6140a05686

Ver fichero

@@ -3,13 +3,13 @@
const RADIO_NAME = 'Game! Radio 1'; const RADIO_NAME = 'Game! Radio 1';
// SELECT ARTWORK PROVIDER, ITUNES, DEEZER & SPOTIFY eg : spotify // SELECT ARTWORK PROVIDER, ITUNES, DEEZER & SPOTIFY eg : spotify
var API_SERVICE = 'SPOTIFY'; var API_SERVICE = 'deezer';
// Change Stream URL Here, Supports, ICECAST, ZENO, SHOUTCAST, RADIOJAR ETC.... DOES NOT SUPPORT HLS // Change Stream URL Here, Supports, ICECAST, ZENO, SHOUTCAST, RADIOJAR ETC.... DOES NOT SUPPORT HLS
const URL_STREAMING = 'https://stream-51.zeno.fm/cfhkm5fs1uhvv?zs=HOu6hxV1SG-7iGi9WGVTqQ'; const URL_STREAMING = 'https://stream-51.zeno.fm/cfhkm5fs1uhvv?zs=HOu6hxV1SG-7iGi9WGVTqQ';
//NOW PLAYING API. //NOW PLAYING API.
const API_URL = 'https://api.joeycast.com/songid/4eb1b192-cff3-4b95-a46c-13cbc5048730' const API_URL = 'https://api-v2.streamafrica.net/metadata?url=' + URL_STREAMING
// Visit https://api.vagalume.com.br/docs/ to get your API key // Visit https://api.vagalume.com.br/docs/ to get your API key
const API_KEY = "18fe07917957c289983464588aabddfb"; const API_KEY = "18fe07917957c289983464588aabddfb";
@@ -75,10 +75,10 @@ function Page() {
xhttp.onreadystatechange = function () { xhttp.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) { if (this.readyState === 4 && this.status === 200) {
var data = JSON.parse(this.responseText); var data = JSON.parse(this.responseText);
var artworking = data.results; var artwork = data.results.artwork;
var gotit = artworking.artwork; var artworkXL = artwork.large;
document.querySelectorAll('#historicSong article .cover-historic')[n].style.backgroundImage = 'url(' + gotit + ')'; document.querySelectorAll('#historicSong article .cover-historic')[n].style.backgroundImage = 'url(' + artworkXL + ')';
} }
// Formating characters to UTF-8 // Formating characters to UTF-8
var music = info.song.replace(/'/g, '\''); var music = info.song.replace(/'/g, '\'');
@@ -94,7 +94,7 @@ function Page() {
$historicDiv[n].classList.add('animated'); $historicDiv[n].classList.add('animated');
$historicDiv[n].classList.add('slideInRight'); $historicDiv[n].classList.add('slideInRight');
} }
xhttp.open('GET', 'https://api.streamafrica.net/new.search.php?query=' + info.artist + ' ' + info.song + '&service=' + API_SERVICE.toLowerCase()); xhttp.open('GET', 'https://api-v2.streamafrica.net/musicsearch?query=' + info.artist + ' ' + info.song + '&service=' + API_SERVICE.toLowerCase());
xhttp.send(); xhttp.send();
setTimeout(function () { setTimeout(function () {
@@ -118,7 +118,7 @@ function Page() {
if (this.readyState === 4 && this.status === 200) { if (this.readyState === 4 && this.status === 200) {
var data = JSON.parse(this.responseText); var data = JSON.parse(this.responseText);
var artworkUrl100 = data.results; var artworkUrl100 = data.results;
var urlCoverArt = artworkUrl100.artwork; var urlCoverArt = artworkUrl100.artwork.medium;
coverArt.style.backgroundImage = 'url(' + urlCoverArt + ')'; coverArt.style.backgroundImage = 'url(' + urlCoverArt + ')';
coverArt.className = 'animated bounceInLeft'; coverArt.className = 'animated bounceInLeft';
@@ -168,7 +168,7 @@ function Page() {
} }
} }
} }
xhttp.open('GET', 'https://api.streamafrica.net/new.search.php?query=' + artist + ' ' + song + '&service=' + API_SERVICE.toLowerCase()); xhttp.open('GET', 'https://api-v2.streamafrica.net/musicsearch?query=' + artist + ' ' + song + '&service=' + API_SERVICE.toLowerCase());
xhttp.send(); xhttp.send();
} }
@@ -334,37 +334,33 @@ function mute() {
function getStreamingData() { function getStreamingData() {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () { xhttp.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) { if (this.readyState === 4 && this.status === 200) {
if (this.response.length === 0) {
if(this.response.length === 0) { console.log('%cdebug', 'font-size: 22px');
console.log('%cdebug', 'font-size: 22px')
} }
var data = JSON.parse(this.responseText); var data = JSON.parse(this.responseText);
console.log('Received data:', data); // Add this line for debugging
var page = new Page(); var page = new Page();
// Formating characters to UTF-8 // Formating characters to UTF-8
let song = data.currentSong.replace(/'/g, '\''); let song = data.song ? data.song.replace(/'/g, '\'') : '';
currentSong = song.replace(/&/g, '&'); let artist = data.artist ? data.artist.replace(/'/g, '\'') : '';
let artist = data.currentArtist.replace(/'/g, '\'');
currentArtist = artist.replace(/&/g, '&');
// Change the title // Change the title
document.title = currentSong + ' - ' + currentArtist + ' | ' + RADIO_NAME; document.title = song + ' - ' + artist + ' | ' + RADIO_NAME;
if (document.getElementById('currentSong').innerHTML !== song) { if (document.getElementById('currentSong').innerHTML !== song) {
page.refreshCover(currentSong, currentArtist); page.refreshCover(song, artist);
page.refreshCurrentSong(currentSong, currentArtist); page.refreshCurrentSong(song, artist);
page.refreshLyric(currentSong, currentArtist); page.refreshLyric(song, artist);
for (var i = 0; i < 2; i++) { for (var i = 0; i < 2; i++) {
page.refreshHistoric(data.songHistory[i], i); page.refreshHistoric(data.history[i], i);
} }
} }
} }
}; };
var d = new Date(); var d = new Date();
@@ -538,4 +534,3 @@ function intToDecimal(vol) {
function decimalToInt(vol) { function decimalToInt(vol) {
return vol * 100; return vol * 100;
} }