Files
radio-free-elsewhere/now_playing.php
T
2026-04-23 19:46:08 -04:00

34 lines
1.1 KiB
PHP

<?php
header('Content-Type: text/html; charset=utf-8');
$icecastStatusURL = "https://radio.cyberpunklibrarian.nohost.me/status-json.xsl";
$response = @file_get_contents($icecastStatusURL);
if ($response === FALSE) {
echo "Unable to retrieve stream information.";
} else {
$data = json_decode($response, true);
if (isset($data['icestats']['source'])) {
$source = $data['icestats']['source'];
if (!is_array($source) || isset($source['title'])) {
$currentStream = $source;
} else {
$currentStream = $source[0];
}
$currentSong = isset($currentStream['title']) ? $currentStream['title'] : 'No song metadata available';
// 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 {
echo "RFE is currently offline! Please check back later!";
}
}
?>