Add recently played tracking with shows and broadcasts

- sql/schema.sql: shows, broadcasts and played_tracks tables, seeded
  with the five shows
- cli/poll_icecast.php: cron-run poller that records broadcasts and
  tracks every 15 seconds while streaming; tracks are cleared ten
  minutes after a broadcast ends
- cli/set_show.php: queue the next show, or assign one to the live
  broadcast
- recently_played.php: track history rows for live.php, with album art
  and album title linking to Last.fm
- live.php: recently played list, show name in heading, and per-show
  header background
- includes/icecast.php: Icecast parsing, album art and Last.fm helpers
  shared by now_playing.php and the poller
- includes/db.php: use UTC for the database session

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel MesserandClaude Opus 5.5 committed 2026-10-29 06:45:44 -05:00
1 parent 9a1e8a33a6
commit 74dfb3c146
11 files changed
+417 -50

No files matched your search

+16 -45
View File
@@ -1,58 +1,29 @@
<?php
header('Content-Type: text/html; charset=utf-8');
// 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');
}
require __DIR__ . '/includes/icecast.php';
$icecastStatusURL = "https://radio.cyberpunklibrarian.nohost.me/status-json.xsl";
$response = @file_get_contents($icecastStatusURL);
$track = fetchCurrentTrack();
if ($response === FALSE) {
if ($track === false) {
echo "Unable to retrieve stream information.";
} elseif ($track === null) {
echo "RFE is currently offline!<br>Please check back later!";
} else {
$data = json_decode($response, true);
['title' => $title, 'artist' => $artist, 'album' => $album] = $track;
if (isset($data['icestats']['source'])) {
$source = $data['icestats']['source'];
$currentStream = (!is_array($source) || isset($source['title'])) ? $source : $source[0];
$artUrl = lookupAlbumArt($artist, $album);
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;">';
}
$raw = decodeMetaField($currentStream, 'title');
$parts = array_map('trim', explode(' - ', $raw, 3));
$title = $parts[0] ?? '';
$artist = $parts[1] ?? '';
$album = $parts[2] ?? '';
echo htmlspecialchars($title ?: 'No song metadata available', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
if ($artist !== '') echo '<br>' . htmlspecialchars($artist, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
if ($album !== '') echo '<br>' . htmlspecialchars($album, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
// 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']);
}
}
}
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;">';
}
echo htmlspecialchars($title ?: 'No song metadata available', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
if ($artist !== '') echo '<br>' . htmlspecialchars($artist, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
if ($album !== '') echo '<br>' . htmlspecialchars($album, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
if ($artist !== '' && $title !== '') {
$lastfmUrl = 'https://www.last.fm/music/' . rawurlencode($artist) . '/_/' . rawurlencode($title);
echo '<br><a href="' . htmlspecialchars($lastfmUrl, ENT_QUOTES, 'UTF-8') . '" target="_blank" rel="noopener" style="color:#97C9D3;font-size:0.9em;">More on Last.fm &rarr;</a>';
}
} else {
echo "RFE is currently offline!<br>Please check back later!";
if ($artist !== '' && $title !== '') {
$lastfmUrl = lastfmTrackUrl($artist, $title);
echo '<br><a href="' . htmlspecialchars($lastfmUrl, ENT_QUOTES, 'UTF-8') . '" target="_blank" rel="noopener" style="color:#97C9D3;font-size:0.9em;">More on Last.fm &rarr;</a>';
}
}
?>