Files
radio-free-elsewhere/cli/set_show.php
T
Daniel MesserandClaude Opus 5.5 74dfb3c146 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>
2026-10-29 06:45:44 -05:00

45 lines
1.5 KiB
PHP

<?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";
}