Skip to content

fix: 修复哔哩哔哩cookie失效时解析视频报错#115

Open
TokikiriNanaya wants to merge 2 commits intoZhalslar:mainfrom
TokikiriNanaya:bilibili-cookie-fix
Open

fix: 修复哔哩哔哩cookie失效时解析视频报错#115
TokikiriNanaya wants to merge 2 commits intoZhalslar:mainfrom
TokikiriNanaya:bilibili-cookie-fix

Conversation

@TokikiriNanaya
Copy link
Copy Markdown

@TokikiriNanaya TokikiriNanaya commented Apr 22, 2026

Summary by Sourcery

Bug Fixes:

  • 当缺少 Cookies、Cookies 过期,或在获取 AI 总结时抛出异常时,通过改为回退到警告提示,而不是直接失败,防止 B 站视频解析出错。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Prevent Bilibili video parsing from failing when cookies are missing, expired, or when fetching the AI summary raises an exception by falling back to a warning instead.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 22, 2026

审阅者指南(在小型 PR 上折叠)

审阅者指南

将 Bilibili AI 总结的获取过程包裹在 try/except 中,这样当 cookies 过期或无效时,不再导致整个视频解析失败,而是在 AI 总结获取失败时记录一条警告日志。

带错误处理的 Bilibili AI 总结获取时序图

sequenceDiagram
    participant Parser as BilibiliParser
    participant Login as LoginState
    participant Video as BilibiliVideo
    participant Logger as Logger

    Parser->>Login: check _credential
    alt credential exists
        Parser->>Video: get_cid(page_info.index)
        Video-->>Parser: cid
        Parser->>Video: get_ai_conclusion(cid)
        Video-->>Parser: ai_conclusion_data
        Parser->>Parser: convert(ai_conclusion_data, AIConclusion)
        Parser->>Parser: ai_summary = ai_conclusion.summary
    else credential missing
        Parser->>Parser: ai_summary = cookie_invalid_message
    end

    rect rgba(200, 200, 200, 0.1)
        note over Parser,Video: Wrapped in try block
    end

    Parser-->>Parser: Exception occurs during AI summary retrieval
    Parser->>Logger: warning 获取 AI 总结失败... e
Loading

AI 总结获取控制逻辑流程图

flowchart TD
    A[start parse_video] --> B[page_info = extract_info_with_page page_num]
    B --> C{enter try block}
    C --> D{login._credential exists}
    D -->|yes| E[get cid using page_info.index]
    E --> F[get ai_conclusion using cid]
    F --> G[convert ai_conclusion to AIConclusion]
    G --> H[set ai_summary to AIConclusion.summary]
    D -->|no| I[set ai_summary to cookie invalid or expired message]
    H --> J[end try block]
    I --> J
    C --> K[Exception raised during AI summary retrieval]
    K --> L[logger.warning 获取 AI 总结失败... e]
    L --> M[continue building video url]
    J --> M
    M --> N[end parse_video AI summary section]
Loading

文件级变更

变更 详情 文件
使 AI 总结获取过程对 Bilibili cookie 的错误配置或过期更加健壮。
  • 在凭据检查和 API 调用周围,用 try/except 块包裹 AI 总结获取逻辑。
  • 当凭据缺失或无效时,继续返回一个固定的回退消息,指示 cookies 未配置或已过期。
  • 在 CID 查询或 AI 结论获取/转换过程中发生任何异常时,记录一条带错误信息的告警日志,而不是抛出异常,从而避免导致 parse_video 失败。
core/parsers/bilibili/__init__.py

提示与命令

与 Sourcery 交互

  • 触发新的审查: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 在审查评论下回复,要求 Sourcery 从该评论创建一个 issue。你也可以在审查评论下回复 @sourcery-ai issue,从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文的任意位置写上 @sourcery-ai summary,即可在你想要的位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。如果你已经处理完所有评论并且不想再看到它们,这会很有用。
  • 撤销所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss,以撤销所有现有的 Sourcery 审查。尤其适用于你想以一次全新的审查重新开始——别忘了再评论 @sourcery-ai review 以触发新的审查!

自定义你的体验

访问你的 控制面板 以:

  • 启用或禁用诸如 Sourcery 生成的 pull request 摘要、审阅者指南等审查功能。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Wraps the Bilibili AI summary retrieval in a try/except so that expired or invalid cookies no longer cause the entire video parsing to fail, instead logging a warning when AI summary fetching fails.

Sequence diagram for Bilibili AI summary retrieval with error handling

sequenceDiagram
    participant Parser as BilibiliParser
    participant Login as LoginState
    participant Video as BilibiliVideo
    participant Logger as Logger

    Parser->>Login: check _credential
    alt credential exists
        Parser->>Video: get_cid(page_info.index)
        Video-->>Parser: cid
        Parser->>Video: get_ai_conclusion(cid)
        Video-->>Parser: ai_conclusion_data
        Parser->>Parser: convert(ai_conclusion_data, AIConclusion)
        Parser->>Parser: ai_summary = ai_conclusion.summary
    else credential missing
        Parser->>Parser: ai_summary = cookie_invalid_message
    end

    rect rgba(200, 200, 200, 0.1)
        note over Parser,Video: Wrapped in try block
    end

    Parser-->>Parser: Exception occurs during AI summary retrieval
    Parser->>Logger: warning 获取 AI 总结失败... e
Loading

Flow diagram for AI summary retrieval control logic

flowchart TD
    A[start parse_video] --> B[page_info = extract_info_with_page page_num]
    B --> C{enter try block}
    C --> D{login._credential exists}
    D -->|yes| E[get cid using page_info.index]
    E --> F[get ai_conclusion using cid]
    F --> G[convert ai_conclusion to AIConclusion]
    G --> H[set ai_summary to AIConclusion.summary]
    D -->|no| I[set ai_summary to cookie invalid or expired message]
    H --> J[end try block]
    I --> J
    C --> K[Exception raised during AI summary retrieval]
    K --> L[logger.warning 获取 AI 总结失败... e]
    L --> M[continue building video url]
    J --> M
    M --> N[end parse_video AI summary section]
Loading

File-Level Changes

Change Details Files
Make AI summary fetching resilient to Bilibili cookie misconfiguration or expiration.
  • Wrap AI summary retrieval logic in a try/except block around the credential check and API calls.
  • On missing or invalid credentials, keep returning a fixed fallback message indicating cookies are not configured or have expired.
  • On any exception during CID lookup or AI conclusion fetching/conversion, log a warning with the error instead of raising, preventing parse_video from failing.
core/parsers/bilibili/__init__.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出一些高层面的反馈:

  • 在用于获取 AI 摘要的 try/except 代码块中,如果在给 ai_summary 赋值之前发生异常,它可能会保持未定义状态;建议在 except 分支中设置一个安全的回退值,以确保后续代码总能拿到已定义的摘要。
  • 在获取 AI 摘要时捕获宽泛的 Exception 会隐藏具体失败原因;建议收窄异常类型,或者使用 logger.exception 来保留堆栈追踪,以便更容易调试。
给 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
- In the `try/except` block for fetching the AI summary, `ai_summary` may be left undefined if an exception occurs before assignment; consider setting a safe fallback value in the `except` branch to ensure downstream code always has a defined summary.
- Catching a broad `Exception` in the AI summary retrieval hides the specific failure cause; consider narrowing the exception type or using `logger.exception` to preserve the stack trace for easier debugging.

Sourcery 对开源项目是免费的——如果你觉得我们的代码审查有帮助,欢迎分享给更多人 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会用这些反馈来改进后续给你的代码审查。
Original comment in English

Hey - I've left some high level feedback:

  • In the try/except block for fetching the AI summary, ai_summary may be left undefined if an exception occurs before assignment; consider setting a safe fallback value in the except branch to ensure downstream code always has a defined summary.
  • Catching a broad Exception in the AI summary retrieval hides the specific failure cause; consider narrowing the exception type or using logger.exception to preserve the stack trace for easier debugging.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the `try/except` block for fetching the AI summary, `ai_summary` may be left undefined if an exception occurs before assignment; consider setting a safe fallback value in the `except` branch to ensure downstream code always has a defined summary.
- Catching a broad `Exception` in the AI summary retrieval hides the specific failure cause; consider narrowing the exception type or using `logger.exception` to preserve the stack trace for easier debugging.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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