192 lines
8.0 KiB
PHP
192 lines
8.0 KiB
PHP
<?php
|
|
require_once 'vendor/autoload.php';
|
|
require_once 'db/config.php';
|
|
|
|
use Kunnu\Dropbox\Dropbox;
|
|
use Kunnu\Dropbox\DropboxApp;
|
|
use Kunnu\Dropbox\Models\FileMetadata;
|
|
|
|
// Fetch the latest dropbox token from the database
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT dropbox_token FROM streams WHERE dropbox_token IS NOT NULL AND dropbox_token != '' ORDER BY created_at DESC LIMIT 1");
|
|
$result = $stmt->fetch();
|
|
$token = $result ? $result['dropbox_token'] : null;
|
|
} catch (PDOException $e) {
|
|
$token = null;
|
|
error_log("Database error fetching token: " . $e->getMessage());
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="pt-BR">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Minha Nuvem - CloudStream</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/app.css?v=<?php echo time(); ?>">
|
|
<style>
|
|
.video-list-item {
|
|
cursor: pointer;
|
|
transition: all 0.2s ease;
|
|
border-radius: 12px;
|
|
margin-bottom: 0.5rem;
|
|
padding: 1rem;
|
|
background: white;
|
|
border: 1px solid var(--glass-border);
|
|
list-style: none;
|
|
font-weight: 500;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
}
|
|
.video-list-item:hover {
|
|
transform: translateX(5px);
|
|
border-color: var(--primary);
|
|
color: var(--primary);
|
|
box-shadow: var(--shadow);
|
|
}
|
|
.video-list-item.active {
|
|
background: var(--primary);
|
|
color: white;
|
|
border-color: var(--primary);
|
|
}
|
|
.cloud-grid {
|
|
display: grid;
|
|
grid-template-columns: 1.5fr 1fr;
|
|
gap: 2rem;
|
|
}
|
|
@media (max-width: 992px) {
|
|
.cloud-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|
|
</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">📊 Painel</a>
|
|
<a href="index.php?page=converter">🔄 Conversor</a>
|
|
<a href="cloud.php" class="active">☁️ Minha Nuvem</a>
|
|
</nav>
|
|
</aside>
|
|
|
|
<main class="main-content">
|
|
<div class="container">
|
|
<header>
|
|
<h2>Minha Nuvem Dropbox</h2>
|
|
<p>Gerencie e assista seus vídeos salvos diretamente da nuvem.</p>
|
|
</header>
|
|
|
|
<div class="cloud-grid">
|
|
<div class="video-player-section">
|
|
<div class="card" style="padding: 1rem;">
|
|
<video id="videoPlayer" controls autoplay style="width: 100%; border-radius: 16px; aspect-ratio: 16/9; background: #000;">
|
|
<source src="" type="video/mp4">
|
|
Seu navegador não suporta a tag de vídeo.
|
|
</video>
|
|
<div id="videoTitle" style="margin-top: 1rem; font-weight: 700; font-size: 1.25rem; color: var(--text-main);">Selecione um vídeo</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="playlist-section">
|
|
<div class="card">
|
|
<h3 style="margin-bottom: 1.5rem; font-weight: 700;">Playlist na Nuvem</h3>
|
|
<ul id="videoList" style="padding: 0;">
|
|
<?php
|
|
if ($token) {
|
|
try {
|
|
$app = new DropboxApp("", "", $token);
|
|
$dropbox = new Dropbox($app);
|
|
|
|
$listFolderContents = $dropbox->listFolder('/');
|
|
$items = $listFolderContents->getItems();
|
|
|
|
$foundVideos = 0;
|
|
foreach ($items as $item) {
|
|
if ($item instanceof FileMetadata) {
|
|
$filename = strtolower($item->getName());
|
|
$videoExtensions = ['.mp4', '.mov', '.avi', '.mkv', '.webm'];
|
|
$is_video = false;
|
|
foreach($videoExtensions as $ext) {
|
|
if (str_ends_with($filename, $ext)) {
|
|
$is_video = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($is_video) {
|
|
try {
|
|
$temporaryLink = $dropbox->getTemporaryLink($item->getPathLower());
|
|
$link = $temporaryLink->getLink();
|
|
echo '<li class="video-list-item" data-video-src="' . htmlspecialchars($link) . '" data-video-name="' . htmlspecialchars($item->getName()) . '">
|
|
<span>🎥</span> ' . htmlspecialchars($item->getName()) . '
|
|
</li>';
|
|
$foundVideos++;
|
|
} catch (Exception $e) {}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($foundVideos === 0) {
|
|
echo '<li style="list-style:none; color: var(--text-muted); text-align: center; padding: 2rem;">Nenhum vídeo encontrado no Dropbox.</li>';
|
|
}
|
|
} catch (Exception $e) {
|
|
echo '<li style="list-style:none; color: var(--error); padding: 1rem; background: #fee2e2; border-radius: 12px;">Erro ao conectar com Dropbox. Verifique o token no conversor.</li>';
|
|
}
|
|
} else {
|
|
echo '<li style="list-style:none; color: var(--text-muted); text-align: center; padding: 2rem;">Dropbox não configurado. Adicione um token no conversor primeiro.</li>';
|
|
}
|
|
?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const videoPlayer = document.getElementById('videoPlayer');
|
|
const videoListItems = document.querySelectorAll('.video-list-item');
|
|
const videoSource = videoPlayer.querySelector('source');
|
|
const videoTitle = document.getElementById('videoTitle');
|
|
|
|
function playSelectedVideo(item) {
|
|
const videoSrc = item.getAttribute('data-video-src');
|
|
const name = item.getAttribute('data-video-name');
|
|
|
|
videoListItems.forEach(i => i.classList.remove('active'));
|
|
item.classList.add('active');
|
|
|
|
videoTitle.textContent = name;
|
|
videoSource.setAttribute('src', videoSrc);
|
|
videoPlayer.load();
|
|
videoPlayer.play().catch(e => console.log("Autoplay blocked"));
|
|
}
|
|
|
|
if (videoListItems.length > 0) {
|
|
playSelectedVideo(videoListItems[0]);
|
|
}
|
|
|
|
videoListItems.forEach(item => {
|
|
item.addEventListener('click', function() {
|
|
playSelectedVideo(this);
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|