Files
Daniel MesserandClaude Opus 5.5 170ae6eed0 Add optional episode titles to queued and live broadcasts
Store an episode_title on each broadcast, settable from the dashboard
or with set_show.php --title=, and show it under the show name on
index.php and under the heading on live.php.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 16:11:22 -05:00

69 lines
2.8 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)
// php cli/set_show.php <slug> 2026-10-30 19:30
// queue it with an advertised start time (Eastern) for the main page
// php cli/set_show.php <slug> 2026-10-30 19:30 --title="Ethereal and Enya"
// also give the episode a title (works with or without a start time)
if (PHP_SAPI !== 'cli') {
http_response_code(403);
exit;
}
require __DIR__ . '/../includes/db.php';
require __DIR__ . '/../includes/broadcasts.php';
$db = getDB();
// Pull out --title=... so the remaining arguments stay positional
$episodeTitle = null;
$args = [];
foreach (array_slice($argv, 1) as $arg) {
if (str_starts_with($arg, '--title=')) {
$episodeTitle = substr($arg, 8);
} else {
$args[] = $arg;
}
}
$slug = $args[0] ?? null;
$scheduledAt = null;
if (isset($args[1])) {
$scheduledAt = stationTimeToUtc($args[1] . ' ' . ($args[2] ?? ''));
if ($scheduledAt === null) {
fwrite(STDERR, "Start time must be a valid date and time like 2026-10-30 19:30 (" . STATION_TIMEZONE_LABEL . ").\n");
exit(1);
}
}
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)')
. ($current && $current['episode_title'] ? " \"{$current['episode_title']}\"" : '') . (liveBroadcast($db) ? ' [live]' : '');
if ($current && $current['scheduled_at'] && !$current['started_at']) {
echo ', scheduled for ' . utcToStationTime($current['scheduled_at'])->format('Y-m-d H:i') . ' ' . STATION_TIMEZONE_LABEL . " ({$current['scheduled_at']} UTC)";
}
echo "\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);
}
$label = $show['name'] . (trim((string)$episodeTitle) !== '' ? ' "' . trim($episodeTitle) . '"' : '');
if (setBroadcastShow($db, (int)$show['id'], $scheduledAt, $episodeTitle) === 'live') {
echo "Live broadcast is now {$label}." . ($scheduledAt ? ' (Start time ignored.)' : '') . "\n";
} else {
echo "{$label} is queued for the next broadcast" . ($scheduledAt ? " at {$args[1]} {$args[2]} " . STATION_TIMEZONE_LABEL . " ({$scheduledAt} UTC)" : '') . ".\n";
}