0 || !empty($url)) { $video_info = null; // 诊断数据库连接 if (!$db) { $debug_log[] = "❌ 致命错误: 数据库连接失败!"; } else { $debug_log[] = "✅ 数据库连接: 正常"; // A. 优先通过 ID 精准查询 if ($id > 0) { $res = $db->query("SELECT resource_site FROM videos WHERE id = $id LIMIT 1"); if ($res && $res->num_rows > 0) { $video_info = $res->fetch_assoc(); $debug_log[] = "✅ 查询成功 (按ID): 来源标识 = [{$video_info['resource_site']}]"; } else { $debug_log[] = "⚠️ 查询失败 (按ID): 未找到视频记录"; } } // B. 其次通过 URL 模糊反查 elseif (!empty($url)) { $path = parse_url($url, PHP_URL_PATH); $filename = basename($path); if (strlen($filename) > 5) { $safe_name = $db->real_escape_string($filename); $res = $db->query("SELECT resource_site FROM videos WHERE vod_play_url LIKE '%$safe_name%' LIMIT 1"); if ($res && $res->num_rows > 0) { $video_info = $res->fetch_assoc(); $debug_log[] = "✅ 查询成功 (按URL): 来源标识 = [{$video_info['resource_site']}]"; } else { $debug_log[] = "⚠️ 查询失败 (按URL): 未找到匹配视频"; } } else { $debug_log[] = "⚠️ 跳过URL查询: 文件名过短"; } } } // C. 查询水印规则表 if ($video_info && !empty($video_info['resource_site'])) { $source_key = $db->real_escape_string($video_info['resource_site']); $rule = $db->query("SELECT * FROM watermark_rules WHERE source_flag = '$source_key' LIMIT 1")->fetch_assoc(); if ($rule) { $debug_log[] = "✅ 规则匹配成功: 找到 [{$source_key}] 的水印规则 (ID: {$rule['id']})"; // 生成定位样式 $pos_style = ""; switch ($rule['position']) { case 'tl': $pos_style = "top: {$rule['margin_y']}; left: {$rule['margin_x']};"; break; case 'tr': $pos_style = "top: {$rule['margin_y']}; right: {$rule['margin_x']};"; break; case 'bl': $pos_style = "bottom: {$rule['margin_y']}; left: {$rule['margin_x']};"; break; case 'br': $pos_style = "bottom: {$rule['margin_y']}; right: {$rule['margin_x']};"; break; default: $pos_style = "top: 2%; right: 2%;"; } // 生成背景样式 $bg_style = ""; if ($rule['mode'] == 1) { $bg_style = "backdrop-filter: blur(12px) saturate(180%); -webkit-backdrop-filter: blur(12px) saturate(180%); background: rgba(255,255,255,0.05); box-shadow: 0 0 10px rgba(0,0,0,0.1) inset;"; } else { $bg_style = "background-image: url('{$rule['cover_img']}'); background-size: contain; background-repeat: no-repeat; background-position: center;"; } // 注入 CSS $mask_css = " #smart-mask { position: absolute; {$pos_style} width: {$rule['width']}; height: {$rule['height']}; z-index: 10; pointer-events: none; border-radius: 4px; overflow: hidden; {$bg_style} mask-image: linear-gradient(to bottom, transparent 0%, black 10%, black 90%, transparent 100%), linear-gradient(to right, transparent 0%, black 10%, black 90%, transparent 100%); -webkit-mask-image: linear-gradient(black, black); display: block !important; }"; $mask_html = '
'; } else { $debug_log[] = "❌ 规则匹配失败: 数据库有标识 [{$source_key}],但在 '水印管理' 里没找到对应规则!"; } } else { $debug_log[] = "ℹ️ 跳过规则查询: 没有有效的来源标识"; } } ?>