<?php
require_once 'config.php';

echo "清理无效视频记录...\n\n";

// 查询所有视频记录
$stmt = $pdo->query("SELECT id, video_id, video_name, storage_path, file_name FROM video_assets");
$deletedCount = 0;

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $fullPath = __DIR__ . '/' . $row['storage_path'] . $row['file_name'];
    if (!file_exists($fullPath)) {
        echo "删除无效记录: {$row['video_id']} - {$row['video_name']}\n";
        $pdo->exec("DELETE FROM video_assets WHERE id = " . $row['id']);
        $deletedCount++;
    }
}

echo "\n已删除 $deletedCount 条无效记录\n\n";

// 查询剩余记录
$stmt = $pdo->query("SELECT video_id, video_name, video_type, storage_path, file_name FROM video_assets");
echo "当前有效视频记录:\n";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    echo "ID: {$row['video_id']} | 名称: {$row['video_name']} | 类型: {$row['video_type']}\n";
}
?>