Added fuller metadata and album covers from iTunes.
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
color: #97C9D3;
|
color: #97C9D3;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@@ -63,10 +64,10 @@
|
|||||||
<!-- <span class="image right"><img src="images/omorains-icon.jpg" alt="" /></span></p> -->
|
<!-- <span class="image right"><img src="images/omorains-icon.jpg" alt="" /></span></p> -->
|
||||||
<!-- <span class="image right"><img src="images/bisexual-icon.jpg" alt="" /></span></p> -->
|
<!-- <span class="image right"><img src="images/bisexual-icon.jpg" alt="" /></span></p> -->
|
||||||
|
|
||||||
<audio controls src="https://radio.cyberpunklibrarian.nohost.me/rfe"></audio>
|
<div id="now-playing">Loading current song...</div>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<div id="now-playing">Loading current song...</div>
|
<audio controls src="https://radio.cyberpunklibrarian.nohost.me/rfe"></audio>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function fetchNowPlaying() {
|
function fetchNowPlaying() {
|
||||||
|
|||||||
+30
-11
@@ -1,8 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
header('Content-Type: text/html; charset=utf-8');
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
|
||||||
$icecastStatusURL = "https://radio.cyberpunklibrarian.nohost.me/status-json.xsl";
|
// Undo double-encoding: strip the outer UTF-8 layer to recover the original correct UTF-8 byte sequence
|
||||||
|
function decodeMetaField(array $stream, string $key): string {
|
||||||
|
if (!isset($stream[$key]) || $stream[$key] === '') return '';
|
||||||
|
return mb_convert_encoding($stream[$key], 'ISO-8859-1', 'UTF-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
$icecastStatusURL = "https://radio.cyberpunklibrarian.nohost.me/status-json.xsl";
|
||||||
$response = @file_get_contents($icecastStatusURL);
|
$response = @file_get_contents($icecastStatusURL);
|
||||||
|
|
||||||
if ($response === FALSE) {
|
if ($response === FALSE) {
|
||||||
@@ -12,20 +17,34 @@ if ($response === FALSE) {
|
|||||||
|
|
||||||
if (isset($data['icestats']['source'])) {
|
if (isset($data['icestats']['source'])) {
|
||||||
$source = $data['icestats']['source'];
|
$source = $data['icestats']['source'];
|
||||||
|
$currentStream = (!is_array($source) || isset($source['title'])) ? $source : $source[0];
|
||||||
|
|
||||||
if (!is_array($source) || isset($source['title'])) {
|
$raw = decodeMetaField($currentStream, 'title');
|
||||||
$currentStream = $source;
|
$parts = array_map('trim', explode(' - ', $raw, 3));
|
||||||
} else {
|
$title = $parts[0] ?? '';
|
||||||
$currentStream = $source[0];
|
$artist = $parts[1] ?? '';
|
||||||
|
$album = $parts[2] ?? '';
|
||||||
|
|
||||||
|
// Look up album art from iTunes Search API
|
||||||
|
$artUrl = '';
|
||||||
|
if ($artist !== '' && $album !== '') {
|
||||||
|
$query = urlencode($artist . ' ' . $album);
|
||||||
|
$itunesResponse = @file_get_contents("https://itunes.apple.com/search?term={$query}&entity=album&media=music&limit=1");
|
||||||
|
if ($itunesResponse !== false) {
|
||||||
|
$itunesData = json_decode($itunesResponse, true);
|
||||||
|
if (!empty($itunesData['results'][0]['artworkUrl100'])) {
|
||||||
|
$artUrl = str_replace('100x100bb', '400x400bb', $itunesData['results'][0]['artworkUrl100']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentSong = isset($currentStream['title']) ? $currentStream['title'] : 'No song metadata available';
|
if ($artUrl !== '') {
|
||||||
|
echo '<img src="' . htmlspecialchars($artUrl, ENT_QUOTES, 'UTF-8') . '" alt="Album art" style="width:100%;max-width:200px;display:block;margin-bottom:8px;border-radius:4px;">';
|
||||||
|
}
|
||||||
|
|
||||||
// Undo the double-encoding: strip the outer UTF-8 layer to recover
|
echo htmlspecialchars($title ?: 'No song metadata available', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
// the original correct UTF-8 byte sequence
|
if ($artist !== '') echo '<br>' . htmlspecialchars($artist, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
$currentSong = mb_convert_encoding($currentSong, 'ISO-8859-1', 'UTF-8');
|
if ($album !== '') echo '<br>' . htmlspecialchars($album, ENT_QUOTES | ENT_SUBSTITUTE, '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