fix: 规范化含 BV 号的任意 B 站链接(稍后再看/收藏夹/追踪参数)#421
Open
pumpkinperson996 wants to merge 1 commit into
Open
Conversation
从"稍后再看"(/list/watchlater/?bvid=BV...)、收藏夹播放页等场景 复制的链接会被判为无效链接,尽管其中包含完整 BV 号;校验通过的 链接也会带着追踪参数原样传给 yt-dlp。 在请求入口新增 normalize_video_url():提取 BV 号重建标准 /video/BVxxx 链接,保留分 P 参数(?p=N),丢弃其余查询参数。 b23.tv 短链与其他平台行为不变,无 BV 号链接仍按原逻辑拒绝。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
问题
从 B 站"稍后再看"(
bilibili.com/list/watchlater/?bvid=BV...)、收藏夹播放页(/list/mlXXX?bvid=BV...)等场景复制的链接会被提示"暂不支持该视频平台或链接格式无效",尽管链接中包含完整的 BV 号。校验器只匹配/video/BVxxx路径格式;且校验通过的链接会带着spm_id_from、vd_source等追踪参数原样传给 yt-dlp。修复
在请求入口新增
normalize_video_url()(app/utils/url_parser.py):https://www.bilibili.com/video/BVxxx链接?p=N,复用已有的extract_bilibili_p_number()),丢弃追踪参数b23.tv短链原样返回(保持现有下游解析逻辑,校验器内不发起网络请求)note.py与video_url_validator.py的VideoRequest均通过model_validator(mode="before")在校验前规范化(仅platform == "bilibili"时生效,YouTube/抖音/快手不受影响)。测试
新增
backend/tests/test_url_normalize.py,10 个用例覆盖:稍后再看、收藏夹播放页、追踪参数清理、分 P 保留、无 BV 号拒绝、b23.tv 与 YouTube 不受影响。已在 Docker 镜像环境全部通过,并用真实稍后再看链接端到端验证笔记生成成功。🤖 Generated with Claude Code