Files
radio-free-elsewhere/cli/set_show.php
T

41 lines
1.2 KiB
PHP
Executable File

<?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);
}
if (setBroadcastShow($db, (int)$show['id']) === 'live') {
echo "Live broadcast is now {$show['name']}.\n";
} else {
echo "{$show['name']} is queued for the next broadcast.\n";
}