Widevine / EME(DRM)
主动启用 Widevine CDM,即可播放受 DRM 保护的视频(并与真实 Chrome 的 EME 表面保持一致)——CDM 在运行时获取,获取方式与原版 Chrome 完全相同。
为什么需要主动开启
Clearcote 编译时已内置 EME/Widevine 的底层管线(enable_widevine),但不包含 Google 的专有 CDM——Clearcote 不会再分发它,开源构建也不可能附带它。没有 CDM 时,navigator.requestMediaKeySystemAccess('com.widevine.alpha') 会被拒绝(reject),这既是 DRM 无法使用的问题,也是一致性上的破绽(真实 Chrome 会正常 resolve)。所以由你来触发下载——Clearcote 从不分发 CDM。
启用方法
传入 widevine 即可。SDK 会从 Google 自己的组件服务器下载一次 CDM,校验其 SHA-256,写入 profile 并启用——之后 DRM 页面即可播放。它适用于 launch_persistent_context;自 SDK 0.23 起,也适用于 Python 的 launch(),后者现在运行在一次性 profile 上,而不是无痕模式。在 Node 中请使用 launchPersistentContext(launch() 的 TypeScript 类型尚未声明 widevine)。支持 Python 和 Node;.NET SDK 暂无 Widevine 选项。
python
from clearcote import launch_persistent_context
ctx = launch_persistent_context("./profile-drm", widevine=True) # fetch + seed + enable the CDM
page = ctx.pages[0] if ctx.pages else ctx.new_page()
page.goto("https://your-drm-site.example")
# navigator.requestMediaKeySystemAccess('com.widevine.alpha') now resolvesjavascript
import { launchPersistentContext, fetchWidevine } from "clearcote";
// optional: pre-fetch the CDM ahead of time (cached under ~/.clearcote/WidevineCdm)
await fetchWidevine();
const ctx = await launchPersistentContext("./profile-drm", { widevine: true });工作原理与限制
- 主动开启,由用户触发——CDM 从 Google 的组件服务器下载一次,经过 SHA-256 校验(缺少哈希值时会拒绝使用——它是一个原生 DLL),并缓存在
~/.clearcote/WidevineCdm下(可用CLEARCOTE_WIDEVINE_DIR更改位置)。可通过fetch_widevine()/fetchWidevine()预先获取。每次带widevine启动时,还会向 Google 的更新服务器发起一次版本检查,该请求直接从本机发出,不经过你的代理。 - 必须有 profile——CDM 存放在 profile 中,因此它适用于同步版
launch()和launch_persistent_context,但不适用于无痕模式的启动方式(ephemeral_profile=False、异步版launch())。SDK 会解除对组件更新器的屏蔽(在 Windows 上还会强制执行一次快速更新扫描),以便引擎注册 CDM。支持 Windows 和 Linux。 - Docker——官方镜像在 Windows 身份画像(persona)下默认开启此功能(设置
CC_WIDEVINE=0可关闭)。 - 支持软件级安全(L3)播放;硬件级安全(L1)不在支持范围内。
- 尽力而为——如果无法获取 CDM 或版本检查失败(例如处于离线状态),启动会在没有 DRM 的情况下继续进行,而不会失败。
DRM 支持也是一致身份的组成部分:真实的 Chrome 能响应 Widevine 查询,所以无法响应的身份画像就是一个破绽——而默认身份画像呈现为 Google Chrome,它在所有桌面平台上都自带 CDM。参见检测原理。