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:
1 parent
9a1e8a33a6
commit
74dfb3c146
11 files changed
+417
-50
No files matched your search
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// Polls Icecast and records track history. Run from cron once a minute; each run polls
|
||||
// four times, 15 seconds apart:
|
||||
// * * * * * php /path/to/rfe/cli/poll_icecast.php
|
||||
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
require __DIR__ . '/../includes/db.php';
|
||||
require __DIR__ . '/../includes/broadcasts.php';
|
||||
|
||||
// Skip this run if the previous one is still going
|
||||
$lock = fopen(sys_get_temp_dir() . '/rfe_poll_icecast.lock', 'c');
|
||||
if (!flock($lock, LOCK_EX | LOCK_NB)) exit;
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
if ($i > 0) sleep(15);
|
||||
|
||||
$track = fetchCurrentTrack();
|
||||
if ($track === false) continue; // Status API unreachable; don't treat it as the stream ending
|
||||
|
||||
try {
|
||||
recordPoll(getDB(), $track);
|
||||
} catch (Throwable $e) {
|
||||
fwrite(STDERR, date('c') . ' ' . $e->getMessage() . "\n");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// Sets which show is airing. Run before going live:
|
||||
// php cli/set_show.php list shows and the current state
|
||||
// php cli/set_show.php <slug> queue that show for the next broadcast
|
||||
// (or assign it to the live one if already streaming)
|
||||
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
require __DIR__ . '/../includes/db.php';
|
||||
require __DIR__ . '/../includes/broadcasts.php';
|
||||
|
||||
$db = getDB();
|
||||
$slug = $argv[1] ?? null;
|
||||
|
||||
if ($slug === null) {
|
||||
echo "Shows:\n";
|
||||
foreach ($db->query('SELECT slug, name FROM shows ORDER BY name') as $show) {
|
||||
printf(" %-20s %s\n", $show['slug'], $show['name']);
|
||||
}
|
||||
$current = currentShow($db);
|
||||
echo "\nCurrent: " . ($current ? $current['name'] : '(none)') . (liveBroadcast($db) ? ' [live]' : '') . "\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $db->prepare('SELECT id, name FROM shows WHERE slug = ?');
|
||||
$stmt->execute([$slug]);
|
||||
$show = $stmt->fetch();
|
||||
if (!$show) {
|
||||
fwrite(STDERR, "Unknown show '{$slug}'. Run without arguments to list shows.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$live = liveBroadcast($db);
|
||||
if ($live !== null) {
|
||||
$db->prepare('UPDATE broadcasts SET show_id = ? WHERE id = ?')->execute([$show['id'], $live['id']]);
|
||||
echo "Live broadcast is now {$show['name']}.\n";
|
||||
} else {
|
||||
$db->exec('DELETE FROM broadcasts WHERE started_at IS NULL');
|
||||
$db->prepare('INSERT INTO broadcasts (show_id) VALUES (?)')->execute([$show['id']]);
|
||||
echo "{$show['name']} is queued for the next broadcast.\n";
|
||||
}
|
||||
Reference in new issue
Block a user