Skip to content

fix(youtube): 支持 Shorts 链接#381

Open
Loker-Choi wants to merge 1 commit into
JefferyHcool:developfrom
Loker-Choi:fix/youtube-shorts-url
Open

fix(youtube): 支持 Shorts 链接#381
Loker-Choi wants to merge 1 commit into
JefferyHcool:developfrom
Loker-Choi:fix/youtube-shorts-url

Conversation

@Loker-Choi
Copy link
Copy Markdown

@Loker-Choi Loker-Choi commented May 26, 2026

改动概述

支持后端识别 YouTube Shorts 链接,并从 Shorts URL 中提取视频 ID。

为什么

BiliNote 已支持 YouTube 视频链接,但后端当前只识别 watch?v=youtu.be/ 两种链接形态。现在 YouTube Shorts 链接非常常见,例如 https://www.youtube.com/shorts/<id>,这类链接可能会在 URL 校验阶段被拒绝,或在后续字幕 / 视频处理链路中无法提取 video id。

做了什么

  • is_supported_video_url 中允许 youtube.com/shorts/<id> 链接
  • extract_video_id 中支持从 Shorts URL 提取 YouTube video id
  • 新增单元测试,覆盖 watch?v=youtu.be/shorts/ 三种 YouTube URL 形态

测试方式

  • python -m py_compile backend/app/utils/url_parser.py backend/app/validators/video_url_validator.py backend/tests/test_video_url_support.py
  • python -m unittest backend.tests.test_video_url_support
  • python -m unittest backend.tests.test_video_url_support backend.tests.test_note_helper

手动验证过以下输入会通过后端 URL 校验,并提取出正确的 video id:

https://www.youtube.com/shorts/dQw4w9WgXcQ
  supported: True
  video_id : dQw4w9WgXcQ

https://youtube.com/shorts/dQw4w9WgXcQ?feature=share
  supported: True
  video_id : dQw4w9WgXcQ

补充说明:本地执行 python -m unittest discover backend/tests 时,当前有一个与本次改动无关的既有失败:test_task_serial_executor。本次没有完成完整「生成笔记」端到端验证,因为本地缺少完整后端运行依赖 / 模型与供应商配置。

回归风险

风险较低。本次改动只扩展 YouTube URL 的接受范围和 video id 提取正则;已有的 watch?v=youtu.be/ 链接形态已通过测试覆盖。

@Loker-Choi Loker-Choi changed the title fix(youtube): support shorts urls fix(youtube): 支持 Shorts 链接 May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant