Fixed UTF encoding issues
This commit is contained in:
@@ -70,19 +70,21 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
function fetchNowPlaying() {
|
function fetchNowPlaying() {
|
||||||
fetch('now_playing.php')
|
fetch('now_playing.php')
|
||||||
.then(response => response.text())
|
.then(response => response.arrayBuffer())
|
||||||
.then(data => {
|
.then(buffer => {
|
||||||
document.getElementById('now-playing').innerHTML = data;
|
const decoder = new TextDecoder('utf-8');
|
||||||
})
|
const data = decoder.decode(buffer);
|
||||||
.catch(error => {
|
document.getElementById('now-playing').innerHTML = data;
|
||||||
document.getElementById('now-playing').innerHTML = "Unable to load song data.";
|
})
|
||||||
console.error('Error fetching song data:', error);
|
.catch(error => {
|
||||||
});
|
document.getElementById('now-playing').innerHTML = "Unable to load song data.";
|
||||||
}
|
console.error('Error fetching song data:', error);
|
||||||
// Fetch immediately and then every 15 seconds
|
});
|
||||||
fetchNowPlaying();
|
}
|
||||||
setInterval(fetchNowPlaying, 15000);
|
// Fetch immediately and then every 15 seconds
|
||||||
|
fetchNowPlaying();
|
||||||
|
setInterval(fetchNowPlaying, 15000);
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
<p><span style = "color:white;">Add <a href="https://radio.cyberpunklibrarian.nohost.me/rfe">Radio Free Elsewhere</a> to VLC or your favourite audio streaming app.</span></p>
|
<p><span style = "color:white;">Add <a href="https://radio.cyberpunklibrarian.nohost.me/rfe">Radio Free Elsewhere</a> to VLC or your favourite audio streaming app.</span></p>
|
||||||
|
|||||||
+10
-7
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
// Icecast server status URL
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
|
||||||
$icecastStatusURL = "https://radio.cyberpunklibrarian.nohost.me/status-json.xsl";
|
$icecastStatusURL = "https://radio.cyberpunklibrarian.nohost.me/status-json.xsl";
|
||||||
|
|
||||||
// Fetch the status JSON
|
|
||||||
$response = @file_get_contents($icecastStatusURL);
|
$response = @file_get_contents($icecastStatusURL);
|
||||||
|
|
||||||
if ($response === FALSE) {
|
if ($response === FALSE) {
|
||||||
@@ -13,19 +13,22 @@ if ($response === FALSE) {
|
|||||||
if (isset($data['icestats']['source'])) {
|
if (isset($data['icestats']['source'])) {
|
||||||
$source = $data['icestats']['source'];
|
$source = $data['icestats']['source'];
|
||||||
|
|
||||||
// Ensure $source is treated as an array
|
|
||||||
if (!is_array($source) || isset($source['title'])) {
|
if (!is_array($source) || isset($source['title'])) {
|
||||||
$currentStream = $source;
|
$currentStream = $source;
|
||||||
} else {
|
} else {
|
||||||
$currentStream = $source[0]; // If multiple sources exist, take the first
|
$currentStream = $source[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract song metadata
|
|
||||||
$currentSong = isset($currentStream['title']) ? $currentStream['title'] : 'No song metadata available';
|
$currentSong = isset($currentStream['title']) ? $currentStream['title'] : 'No song metadata available';
|
||||||
|
|
||||||
echo htmlspecialchars($currentSong);
|
// Undo the double-encoding: strip the outer UTF-8 layer to recover
|
||||||
|
// the original correct UTF-8 byte sequence
|
||||||
|
$currentSong = mb_convert_encoding($currentSong, 'ISO-8859-1', 'UTF-8');
|
||||||
|
|
||||||
|
echo htmlspecialchars($currentSong, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo "RFE is currently offline! Please check back later!";
|
echo "RFE is currently offline! Please check back later!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user