36896-vm/index.php
Flatlogic Bot cf734ceaa6 Cloud
2026-02-27 02:45:40 +00:00

207 lines
10 KiB
PHP

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$page = $_GET['page'] ?? 'dashboard';
function get_video_stats() {
require_once 'db/config.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT status, COUNT(*) as count FROM streams GROUP BY status");
$stats = ['total' => 0, 'completed' => 0, 'converting' => 0, 'pending' => 0, 'failed' => 0];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$s = strtolower($row['status']);
if (isset($stats[$s])) {
$stats[$s] = (int)$row['count'];
}
$stats['total'] += (int)$row['count'];
}
return $stats;
} catch (Exception $e) {
return ['total' => 0, 'completed' => 0, 'converting' => 0, 'pending' => 0, 'failed' => 0];
}
}
$video_stats = get_video_stats();
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CloudStream - Painel</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<link rel="stylesheet" href="assets/css/app.css?v=<?= time() ?>">
</head>
<body>
<div class="bg-blobs">
<div class="blob blob-1"></div>
<div class="blob blob-2"></div>
<div class="blob blob-3"></div>
</div>
<div class="dashboard-layout">
<aside class="sidebar">
<h1>🎬 CloudStream</h1>
<nav>
<a href="index.php?page=dashboard" class="<?= $page === 'dashboard' ? 'active' : '' ?>">📊 Painel</a>
<a href="index.php?page=converter" class="<?= $page === 'converter' ? 'active' : '' ?>">🔄 Conversor</a>
<a href="cloud.php">☁️ Minha Nuvem</a>
</nav>
</aside>
<main class="main-content">
<div class="container">
<?php if ($page === 'dashboard'): ?>
<header>
<h2>Olá! 👋</h2>
<p>Aqui está o resumo da sua biblioteca de vídeos.</p>
</header>
<div class="stats-grid">
<div class="stat-card">
<h3>Total de Vídeos</h3>
<div class="value"><?= $video_stats['total'] ?></div>
</div>
<div class="stat-card">
<h3>Concluídos</h3>
<div class="value" style="color:var(--success)"><?= $video_stats['completed'] ?></div>
</div>
<div class="stat-card">
<h3>Em Processamento</h3>
<div class="value" style="color:var(--accent)"><?= $video_stats['converting'] ?></div>
</div>
</div>
<div class="card">
<h3>Atividade Recente</h3>
<div class="table-container">
<table>
<thead>
<tr>
<th>Nome do Arquivo</th>
<th>Status</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<?php
try {
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->query("SELECT filename, status, created_at FROM streams ORDER BY created_at DESC LIMIT 5");
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($rows)) {
echo "<tr><td colspan='3' style='text-align:center;padding:2rem;color:var(--text-muted)'>Nenhum vídeo encontrado.</td></tr>";
} else {
foreach ($rows as $row) {
$sc = 'status-' . strtolower($row['status']);
echo "<tr>";
echo "<td>" . htmlspecialchars($row['filename']) . "</td>";
echo "<td><span class='status-badge $sc'>" . htmlspecialchars($row['status']) . "</span></td>";
echo "<td style='color:var(--text-muted)'>" . date('d/m/Y H:i', strtotime($row['created_at'])) . "</td>";
echo "</tr>";
}
}
} catch (Exception $e) {
echo "<tr><td colspan='3'>Erro ao carregar dados: " . htmlspecialchars($e->getMessage()) . "</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
<?php elseif ($page === 'converter'): ?>
<header>
<h2>🔄 Conversor HLS</h2>
<p>Adicione um link de transmissão para converter e salvar.</p>
</header>
<div class="card">
<div class="form-grid">
<div class="input-group" style="grid-column: 1 / -1;">
<label>URL do Stream (M3U8)</label>
<input type="url" id="stream-url" placeholder="https://exemplo.com/live/playlist.m3u8" value="https://live-hls-abr-cdn.livepush.io/live/bigbuckbunnyclip/index.m3u8">
</div>
<div class="input-group">
<label>Nome do Arquivo de Saída</label>
<input type="text" id="filename" value="Video_<?= date('His') ?>">
</div>
<div class="input-group">
<label>Dropbox Token (Opcional)</label>
<input type="password" id="dropbox-token" placeholder="Seu token do Dropbox">
</div>
</div>
<div style="margin-top: 2rem; text-align: right;">
<button id="save-btn" class="btn btn-primary">🚀 Iniciar Conversão</button>
</div>
</div>
<div class="video-section card" id="preview-section" style="display:none;">
<h3>📺 Preview</h3>
<video id="preview" controls></video>
</div>
<div class="card">
<h3>Minha Biblioteca</h3>
<div class="table-container">
<table>
<thead>
<tr>
<th>Arquivo</th>
<th>Status</th>
<th>Progresso</th>
<th style="text-align:right;">Ações</th>
</tr>
</thead>
<tbody id="streams-table-body">
<?php
try {
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->query("SELECT id, filename, status, url, converted_path, progress FROM streams ORDER BY created_at DESC");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$sc = 'status-' . strtolower($row['status']);
echo "<tr data-stream-id='" . $row['id'] . "' data-status='" . htmlspecialchars($row['status']) . "'>";
echo "<td style='font-weight:600;'>" . htmlspecialchars($row['filename']) . "</td>";
echo "<td><span class='status-badge $sc'>" . htmlspecialchars($row['status']) . "</span></td>";
echo "<td>";
if ($row['status'] === 'converting') {
echo "<div class='progress-bar-container'><div class='progress-bar' style='width:" . $row['progress'] . "%'></div></div>";
}
echo "</td>";
echo "<td style='text-align:right;'>";
echo "<div style='display:flex;gap:0.5rem;justify-content:flex-end;'>";
$playUrl = ($row['status'] === 'completed' && !empty($row['converted_path'])) ? 'videos/'.$row['converted_path'] : $row['url'];
echo "<button class='btn btn-secondary' onclick=\"playVideo('" . htmlspecialchars($playUrl, ENT_QUOTES) . "')\" title='Play'>▶️</button>";
if ($row['status'] === 'completed') {
echo "<button class='btn btn-secondary' onclick='sendToDropbox(" . $row['id'] . ", this)' title='Enviar para Dropbox'>☁️</button>";
}
echo "<button class='btn btn-danger' onclick='deleteVideo(" . $row['id'] . ", this)' title='Excluir'>🗑️</button>";
echo "</div>";
echo "</td>";
echo "</tr>";
}
} catch (Exception $e) {}
?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
</div>
</main>
</div>
<div id="toast-container"></div>
<script src="assets/js/app.js?v=<?= time() ?>"></script>
</body>
</html>