fix(bilibili): 注入 dm_img 风控参数修复 wbi/playurl 412 错误#399
Draft
Copilot wants to merge 2 commits into
Draft
Conversation
2 tasks
… wbi/playurl requests
Copilot
AI
changed the title
[WIP] Fix Bilibili note generation 412 error
fix(bilibili): 注入 dm_img 风控参数修复 wbi/playurl 412 错误
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动概述
在 yt-dlp 的
BilibiliBaseIE._download_playinfo上打 monkey-patch,注入 B 站wbi/playurl网关新要求的dm_img_*风控参数,消除 HTTP 412 错误。为什么
B 站
wbi/playurl网关新增了dm_img_list/dm_img_str/dm_cover_img_str/dm_img_inter+web_location参数校验,缺失时一律返回 412。yt-dlp 2025.3.31 的_download_playinfo不带这些参数,导致网页未内嵌playinfo的视频(必须走 API)全部下载失败。做了什么
backend/app/downloaders/bilibili_downloader.py_patch_bilibili_extractor(),在模块加载时 wrapBilibiliBaseIE._download_playinfo,向每次 wbi 签名请求前注入随机化的 dummy 风控指纹:参数格式(
string.printable+[:-2]base64 截断)与 yt-dlp 自身在BiliBiliSpaceIE频道搜索端点的实现完全一致。_bili_dm_patchedflag 保证幂等,多次 import / 重载不会链式叠加 wrapper。query参数优先级高于 dummy 值,不破坏现有扩展点。测试方式
pnpm typecheck && pnpm build(前端 / 插件)通过python -m py_compile backend/app/downloaders/bilibili_downloader.py通过使用网页未内嵌 playinfo 的 B 站视频(如 BV1X9L16oEgB)配合有效 Cookie 生成笔记,确认不再返回 412。
回归风险
仅影响 Bilibili 下载链路。patch 在模块级别全局生效,适用于所有经过
BilibiliBaseIE._download_playinfo的调用(音频下载、视频下载、字幕 yt-dlp fallback 路径)。无需前后端同步部署,无配置变更。Checklist
feature/*/fix/*/release/*/hotfix/*)develop;线上紧急 →master;发版 → 见 §4.3)type(scope): subject格式(CONTRIBUTING.md §5.1)README.md/CHANGELOG.md/CLAUDE.md/ 模块 README,如适用).env/ 大型二进制