olá eu tentei fazer com que o nextsong funcionasse mas não conseguir. tem como vc me ajudar?
$curl = curl_multi_init();
foreach($urls as $key => $value){
$ch[$key] = curl_init($value);
curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch[$key], CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_multi_add_handle($curl, $ch[$key]);
}
do {
curl_multi_exec($curl, $running);
curl_multi_select($curl);
} while ($running > 0);
foreach(array_keys($ch) as $key){
curl_multi_remove_handle($curl, $ch[$key]);
$content[] = curl_multi_getcontent($ch[$key]);
}
$data = $content[0];
if($nextSong) {
$nextSongName = (isset($content[2])) ? explode('-', $content[2]) : '';
if(isset($nextSongName[1])) {
$array['nextSong'] = ['artist' => $nextSongName[0], 'song' => $nextSongName[1]];
} else {
$array['nextSong'] = ['artist' => '', 'song' => $nextSongName[0]];
}
}
// Put the songs name between <music> tag
$pagina = str_replace('</td><td>', '<music>', $content[1], $count);
$playedSongs = explode('<music>', $pagina);
// Remove unrelacionated content
unset($playedSongs[0]);
unset($playedSongs[1]);
unset($playedSongs[2]);
foreach($playedSongs as $song) {
// Get the name of the song
$cutStr = strpos($song, '</td></tr>');
$playedSong = substr($song, 0, $cutStr);
// Separate artist from song
$songData = explode('-', $playedSong);
$songNameHistoric = (!empty($songData[1])) ? trim($songData[1]) : '';
// Put in the principal array
$array['songHistory'][] = ['artist' => rtrim($songData[0]), 'song' => $songNameHistoric];
}
curl_multi_close($curl);
} else {
$curl = curl_init($url . '/7.html');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0');
$data = curl_exec($curl);
curl_close($curl);
}
this.refreshHistoric = function (info, n) {
var $nextDiv = document.querySelectorAll('#nextSong article');
var $songName = document.querySelectorAll('#nextSong article .music-info .song');
var $artistName = document.querySelectorAll('#nextSong article .music-info .artist');
// Default cover art
var urlCoverArt = 'img/bg-capa.jpg';
// Get cover art for song history
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
var data = JSON.parse(this.responseText);
var artworkUrl100 = (data.resultCount) ? data.results[0].artworkUrl100 : urlCoverArt;
document.querySelectorAll('#nextSong article .cover-historic')[n].style.backgroundImage = 'url(' + artworkUrl100 + ')';
}
// Formating characters to UTF-8
var music = info.song.replace(/'/g, '\'');
var songHist = music.replace(/&/g, '&');
var artist = info.artist.replace(/'/g, '\'');
var artistHist = artist.replace(/&/g, '&');
$songName[n].innerHTML = songHist;
$artistName[n].innerHTML = artistHist;
// Add class for animation
$nextDiv[n].classList.add('animated');
$nextDiv[n].classList.add('slideInRight');
}
xhttp.open('GET', 'https://itunes.apple.com/search?term=' + info.artist + ' ' + info.song + '&media=music&limit=1', true);
xhttp.send();
setTimeout(function () {
for (var j = 0; j < 2; j++) {
$nextDiv[j].classList.remove('animated');
$nextDiv[j].classList.remove('slideInRight');
}
}, 2000);
}
var d = new Date();
// Requisition with timestamp to prevent cache on mobile devices
xhttp.open('GET', 'api.php?url=' + URL_STREAMING + '&historic=' + HISTORIC + '&next=' + NEXT + '&t=' + d.getTime(), true);
xhttp.send();