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