Skip to content

bilibili解析器增加回退机制#113

Open
qihang518887 wants to merge 1 commit intoZhalslar:mainfrom
qihang518887:main
Open

bilibili解析器增加回退机制#113
qihang518887 wants to merge 1 commit intoZhalslar:mainfrom
qihang518887:main

Conversation

@qihang518887
Copy link
Copy Markdown

@qihang518887 qihang518887 commented Apr 22, 2026

加了一个优先级列表,最先的是自选的编码格式,然后按照av1-hevc-avc的顺序进行一次去重
这样首选的编码格式没有的话,会自动回退到其他的编码

由 Sourcery 提供的摘要

新功能:

  • 在 Bilibili 解析器中引入优先级编解码器列表,当首选编解码器不可用时,可按需自动回退至 AV1、HEVC,再到 AVC。
Original summary in English

Summary by Sourcery

New Features:

  • Introduce a prioritized codec list in the Bilibili parser to automatically fall back from the preferred codec to AV1, HEVC, then AVC as needed.

@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)直播流选择实现编解码器回退优先级列表:当用户偏好的编解码器不可用时,解析器会自动按 AV1、HEVC、AVC 的顺序回退,并在此过程中去重偏好选项。

extract_download_urls 中哔哩哔哩编解码器回退流程的时序图

sequenceDiagram
    participant Parser as BilibiliParser
    participant BVideo as BilibiliVideo
    participant Detecter as VideoDownloadURLDataDetecter

    Parser->>BVideo: get_download_url(page_index)
    BVideo-->>Parser: download_url_data

    Parser->>Detecter: new VideoDownloadURLDataDetecter(download_url_data)

    Parser->>Parser: build codec_candidates [user_codec, AV1, HEV, AVC]
    Parser->>Parser: deduplicate into codec_priority

    Parser->>Detecter: detect_best_streams(video_max_quality,
    Parser->>Detecter:  codecs=codec_priority,
    Parser->>Detecter:  no_dolby_video=True, no_hdr=True)
    Detecter-->>Parser: streams
Loading

哔哩哔哩解析器编解码器选择变更的类图

classDiagram
    class BilibiliParser {
        +VideoCodecs video_codecs
        +int video_quality
        +extract_download_urls(page_index)
    }

    class VideoDownloadURLDataDetecter {
        +VideoDownloadURLDataDetecter(download_url_data)
        +detect_best_streams(video_max_quality, codecs, no_dolby_video, no_hdr)
    }

    class VideoCodecs {
        <<enumeration>>
        AV1
        HEV
        AVC
    }

    class BilibiliVideo {
        +get_download_url(page_index)
    }

    BilibiliParser --> BilibiliVideo : uses
    BilibiliParser --> VideoDownloadURLDataDetecter : creates
    BilibiliParser --> VideoCodecs : uses
    VideoDownloadURLDataDetecter --> VideoCodecs : uses
    VideoDownloadURLDataDetecter ..> BilibiliVideo : analyzes URLs from
Loading

带回退机制的编解码器优先级列表流程图

flowchart TD
    A[start] --> B[Read user preferred codec self.video_codecs]
    B --> C[Initialize codec_candidates with self.video_codecs, AV1, HEV, AVC]
    C --> D[Initialize empty codec_priority]
    D --> E[For each codec c in codec_candidates]
    E --> F{c already in codec_priority?}
    F -- yes --> G[Skip c]
    F -- no --> H[Append c to codec_priority]
    G --> I{More codecs?}
    H --> I{More codecs?}
    I -- yes --> E
    I -- no --> J[Call detect_best_streams with codecs=codec_priority]
    J --> K[end]
Loading

文件级改动

变更 详情 文件
在从 Bilibili 检测最佳流时,添加带自动回退和去重功能的编解码器优先级列表。
  • 创建一个有序的编解码器候选列表,以用户配置的编解码器开头,后面依次为 AV1、HEVC 和 AVC。
  • 遍历候选项并仅追加未出现过的编解码器,构建去重后的 codec_priority 列表。
  • codec_priority 列表传给 detect_best_streams,而不是只传入仅包含首选编解码器的单元素列表。
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

Implements a codec fallback priority list for Bilibili stream selection so that if the user-preferred codec is unavailable, the parser automatically falls back to AV1, HEVC, then AVC while de-duplicating preferences.

Sequence diagram for Bilibili codec fallback in extract_download_urls

sequenceDiagram
    participant Parser as BilibiliParser
    participant BVideo as BilibiliVideo
    participant Detecter as VideoDownloadURLDataDetecter

    Parser->>BVideo: get_download_url(page_index)
    BVideo-->>Parser: download_url_data

    Parser->>Detecter: new VideoDownloadURLDataDetecter(download_url_data)

    Parser->>Parser: build codec_candidates [user_codec, AV1, HEV, AVC]
    Parser->>Parser: deduplicate into codec_priority

    Parser->>Detecter: detect_best_streams(video_max_quality,
    Parser->>Detecter:  codecs=codec_priority,
    Parser->>Detecter:  no_dolby_video=True, no_hdr=True)
    Detecter-->>Parser: streams
Loading

Class diagram for Bilibili parser codec selection changes

classDiagram
    class BilibiliParser {
        +VideoCodecs video_codecs
        +int video_quality
        +extract_download_urls(page_index)
    }

    class VideoDownloadURLDataDetecter {
        +VideoDownloadURLDataDetecter(download_url_data)
        +detect_best_streams(video_max_quality, codecs, no_dolby_video, no_hdr)
    }

    class VideoCodecs {
        <<enumeration>>
        AV1
        HEV
        AVC
    }

    class BilibiliVideo {
        +get_download_url(page_index)
    }

    BilibiliParser --> BilibiliVideo : uses
    BilibiliParser --> VideoDownloadURLDataDetecter : creates
    BilibiliParser --> VideoCodecs : uses
    VideoDownloadURLDataDetecter --> VideoCodecs : uses
    VideoDownloadURLDataDetecter ..> BilibiliVideo : analyzes URLs from
Loading

Flow diagram for codec priority list with fallback

flowchart TD
    A[start] --> B[Read user preferred codec self.video_codecs]
    B --> C[Initialize codec_candidates with self.video_codecs, AV1, HEV, AVC]
    C --> D[Initialize empty codec_priority]
    D --> E[For each codec c in codec_candidates]
    E --> F{c already in codec_priority?}
    F -- yes --> G[Skip c]
    F -- no --> H[Append c to codec_priority]
    G --> I{More codecs?}
    H --> I{More codecs?}
    I -- yes --> E
    I -- no --> J[Call detect_best_streams with codecs=codec_priority]
    J --> K[end]
Loading

File-Level Changes

Change Details Files
Add codec priority list with automatic fallback and de-duplication when detecting best streams from Bilibili.
  • Create an ordered list of codec candidates starting with the user-configured codec followed by AV1, HEVC, and AVC.
  • Build a de-duplicated codec_priority list by iterating over candidates and appending only unseen codecs.
  • Pass the codec_priority list to detect_best_streams instead of a single-element list containing only the preferred codec.
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 - 我在这里给出了一些整体性的反馈:

  • 请考虑处理 self.video_codecs 可能为 None 或其他无效值的情况,这样可以避免 codec_priority 把一个不可用的值作为首选项。
  • 请再次确认枚举/常量名 VideoCodecs.HEV —— 描述中提到的是 hevc,如果枚举实际是 HEVC,这里在运行时会报错,需要更新为正确的枚举成员。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- Consider handling the case where `self.video_codecs` may be `None` or otherwise invalid, so that `codec_priority` does not end up containing an unusable value as the first choice.
- Double-check the enum/constant name `VideoCodecs.HEV` – the description mentions `hevc`, so if the enum is actually `HEVC` this will raise at runtime and should be updated to the correct member.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,请考虑分享给更多人 ✨
帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进之后的评审。
Original comment in English

Hey - I've left some high level feedback:

  • Consider handling the case where self.video_codecs may be None or otherwise invalid, so that codec_priority does not end up containing an unusable value as the first choice.
  • Double-check the enum/constant name VideoCodecs.HEV – the description mentions hevc, so if the enum is actually HEVC this will raise at runtime and should be updated to the correct member.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider handling the case where `self.video_codecs` may be `None` or otherwise invalid, so that `codec_priority` does not end up containing an unusable value as the first choice.
- Double-check the enum/constant name `VideoCodecs.HEV` – the description mentions `hevc`, so if the enum is actually `HEVC` this will raise at runtime and should be updated to the correct member.

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