138 lines
6.6 KiB
PHP
138 lines
6.6 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>My Video Cloud</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
background-color: #f8f9fa;
|
|
}
|
|
.video-list-item {
|
|
cursor: pointer;
|
|
}
|
|
.video-list-item:hover {
|
|
background-color: #e9ecef;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container mt-5">
|
|
<a href="/" class="btn btn-secondary mb-4">Back to Dashboard</a>
|
|
<h1 class="mb-4">My Video Cloud</h1>
|
|
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<div class="mb-3">
|
|
<video id="videoPlayer" width="100%" controls autoplay>
|
|
<source src="" type="video/mp4">
|
|
Your browser does not support the video tag.
|
|
</video>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<h4>Playlist</h4>
|
|
<ul class="list-group" id="videoList">
|
|
<?php
|
|
require_once 'vendor/autoload.php';
|
|
require_once 'db/config.php';
|
|
|
|
use Dropbox\Client;
|
|
use Dropbox\App;
|
|
use Dropbox\Exception;
|
|
|
|
// 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());
|
|
}
|
|
|
|
if ($token) {
|
|
try {
|
|
$app = new App("", "", $token);
|
|
$dropbox = new Client($app);
|
|
|
|
$files = $dropbox->listFolder('/');
|
|
$items = $files->getItems();
|
|
|
|
if (count($items) > 0) {
|
|
foreach ($items as $item) {
|
|
$metadata = $item->getMetadata();
|
|
if ($metadata instanceof \Dropbox\Models\FileMetadata) {
|
|
// Check if it's a video file based on extension
|
|
$videoExtensions = ['.mp4', '.mov', '.avi', '.mkv', '.webm'];
|
|
$filename = strtolower($metadata->getName());
|
|
$shouldDisplay = false;
|
|
foreach($videoExtensions as $ext) {
|
|
if (str_ends_with($filename, $ext)) {
|
|
$shouldDisplay = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($shouldDisplay) {
|
|
try {
|
|
// Get a temporary link for the file
|
|
$temporaryLink = $dropbox->getTemporaryLink($metadata->getPathLower());
|
|
$link = $temporaryLink->getLink();
|
|
echo '<li class="list-group-item video-list-item" data-video-src="' . htmlspecialchars($link) . '">' . htmlspecialchars($metadata->getName()) . '</li>';
|
|
} catch (Exception $e) {
|
|
// Could not get a temporary link for some reason
|
|
error_log("Dropbox API error getting temporary link: " . $e->getMessage());
|
|
// Optionally, display an error for this specific file
|
|
echo '<li class="list-group-item disabled" title="Could not load this video.">' . htmlspecialchars($metadata->getName()) . ' (Error)</li>';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
echo '<li class="list-group-item">No videos found in your Dropbox.</li>';
|
|
}
|
|
} catch (Exception $e) {
|
|
error_log("Dropbox API error: " . $e->getMessage());
|
|
if(str_contains($e->getMessage(), 'invalid_access_token')) {
|
|
echo '<li class="list-group-item">Error connecting to Dropbox: The access token is invalid. Please go to the converter page and re-enter a valid token.</li>';
|
|
} else {
|
|
echo '<li class="list-group-item">Error connecting to Dropbox.</li>';
|
|
}
|
|
}
|
|
} else {
|
|
echo '<li class="list-group-item">Dropbox is not configured. Please go to the converter page, provide a token, and upload a video first.</li>';
|
|
}
|
|
?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const videoPlayer = document.getElementById('videoPlayer');
|
|
const videoListItems = document.querySelectorAll('.video-list-item');
|
|
const videoSource = videoPlayer.querySelector('source');
|
|
|
|
if (videoListItems.length > 0) {
|
|
const firstVideoSrc = videoListItems[0].getAttribute('data-video-src');
|
|
videoSource.setAttribute('src', firstVideoSrc);
|
|
videoPlayer.load();
|
|
}
|
|
|
|
videoListItems.forEach(item => {
|
|
item.addEventListener('click', function() {
|
|
const videoSrc = this.getAttribute('data-video-src');
|
|
videoSource.setAttribute('src', videoSrc);
|
|
videoPlayer.load();
|
|
videoPlayer.play();
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|