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 '
' . htmlspecialchars($metadata->getName()) . '
';
} 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 '