Skip to content

更换网易云请求api - #147

Open
soloxiaoye2022 wants to merge 1 commit into
sokoko-org:mainfrom
soloxiaoye2022:master
Open

更换网易云请求api#147
soloxiaoye2022 wants to merge 1 commit into
sokoko-org:mainfrom
soloxiaoye2022:master

Conversation

@soloxiaoye2022

@soloxiaoye2022 soloxiaoye2022 commented Jun 19, 2026

Copy link
Copy Markdown

Summary by Sourcery

改进网易云音乐歌曲解析,以支持多种音质等级,并在结果中提供更丰富的元数据。

错误修复:

  • 当无损音频 URL 获取失败时回退到标准音质,以减少部分歌曲的解析错误。

功能增强:

  • 在回退到标准音质之前先尝试获取更高音质(无损)音频,并从 URL 中推导音频格式。
  • 在歌曲 ID 提取、元数据获取、URL 获取以及生成文件名等环节增加详细日志,便于调试。
  • 在显示的信息中包含音质、上报的大小和格式,并在返回的额外载荷中将歌词与元数据一起封装,同时附带明确的媒体类型标签。
Original summary in English

Summary by Sourcery

Improve NetEase Cloud Music song parsing to support multiple quality levels and richer metadata in the result.

Bug Fixes:

  • Fallback to standard quality when lossless audio URL retrieval fails to reduce parse errors for some songs.

Enhancements:

  • Attempt to fetch higher quality (lossless) audio before falling back to standard quality and derive audio format from the URL.
  • Add detailed logging around song ID extraction, metadata, URL retrieval, and generated file names for easier debugging.
  • Include audio quality, reported size, and format in the displayed info and wrap lyrics together with metadata in the returned extra payload, along with explicit media type tags.

@sourcery-ai

sourcery-ai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

更新 NetEase Cloud Music 解析器,以优先选择更高音质的音频、丰富元数据和日志,并更改歌词与额外信息在结果中的封装方式。

更新后的 NetEase 音乐解析流程时序图

sequenceDiagram
    participant Parser as NeteaseParser
    participant NeteaseAPI as NeteaseAPI

    Parser->>NeteaseAPI: fetch(getSongInfo, id)
    NeteaseAPI-->>Parser: song
    Parser->>NeteaseAPI: fetch(getSongLyric, id)
    NeteaseAPI-->>Parser: lyric

    loop try_audio_levels
        Parser->>NeteaseAPI: fetch(getSongUrl, id, level=lossless|standard)
        alt url_available
            NeteaseAPI-->>Parser: url_data(url, size)
            Parser-->>Parser: set audio_url, audio_level, audio_size, audio_type
            Parser-->>Parser: break
        else error_or_no_url
            NeteaseAPI-->>Parser: error_or_empty
            Parser-->>Parser: log warning
        end
    end

    alt audio_url_missing
        Parser-->>Parser: raise ParseException
    else audio_url_found
        Parser-->>Parser: create_audio(audio_url, duration, title, artist)
        Parser-->>Parser: create_image(cover_url)
        Parser-->>Parser: build audio_info(audio_level, audio_size, audio_type)
        Parser-->>Parser: build lyric_text(audio_info, lyric)
        Parser-->>Parser: result(contents, extra_info)
    end
Loading

File-Level Changes

Change Details Files
增强 NetEase 歌曲解析,尝试多种音质并推断音频元数据。
  • 记录提取出的歌曲 ID 和基础歌曲信息,以便追踪。
  • 在请求歌曲 URL 时遍历 lossless 和 standard 音质等级,选择第一个请求成功的结果。
  • 捕获并存储音质等级、返回的文件大小,并通过 URL 后缀在受限白名单中推断文件类型。
  • 如果在尝试所有可用音质后仍无法获取音频 URL,则抛出解析异常。
src/nonebot_plugin_parser_lite/parsers/netease.py
改进构造出的媒体响应负载,使其包含更丰富的文本、日志和类型元数据。
  • 记录用于媒体内容的生成音频文件名。
  • 将音频信息字符串修改为包含音质等级和原始大小(raw size),而不是格式化后的显示大小。
  • 将音频信息与歌词合并为单一文本字段,存储在 lyric 键下。
  • 在额外元数据中新增 type、type_tag 和 type_icon 字段,便于下游使用。
src/nonebot_plugin_parser_lite/parsers/netease.py

Tips and commands

Interacting with 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 来(重新)生成摘要。
  • 生成 Reviewer's Guide: 在 Pull Request 中评论 @sourcery-ai guide,即可随时(重新)生成 Reviewer's Guide。
  • 一次性解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。适用于你已经处理完所有评论且不希望再看到它们的情况。
  • 一次性忽略所有 Sourcery 评审: 在 Pull Request 中评论 @sourcery-ai dismiss,即可忽略所有现有 Sourcery 评审。特别适用于你希望从头开始一次全新评审的场景——别忘了再评论 @sourcery-ai review 来触发新评审!

Customizing Your Experience

前往你的 dashboard 来:

  • 启用或禁用评审功能,例如 Sourcery 自动生成的 Pull Request 摘要、Reviewer's Guide 等。
  • 更改评审语言。
  • 添加、删除或编辑自定义评审指令。
  • 调整其他评审设置。

Getting Help

Original review guide in English

Reviewer's Guide

Updates the NetEase Cloud Music parser to prefer higher quality audio, enrich metadata and logging, and change how lyric and extra info are packaged in the result.

Sequence diagram for updated NetEase music parsing flow

sequenceDiagram
    participant Parser as NeteaseParser
    participant NeteaseAPI as NeteaseAPI

    Parser->>NeteaseAPI: fetch(getSongInfo, id)
    NeteaseAPI-->>Parser: song
    Parser->>NeteaseAPI: fetch(getSongLyric, id)
    NeteaseAPI-->>Parser: lyric

    loop try_audio_levels
        Parser->>NeteaseAPI: fetch(getSongUrl, id, level=lossless|standard)
        alt url_available
            NeteaseAPI-->>Parser: url_data(url, size)
            Parser-->>Parser: set audio_url, audio_level, audio_size, audio_type
            Parser-->>Parser: break
        else error_or_no_url
            NeteaseAPI-->>Parser: error_or_empty
            Parser-->>Parser: log warning
        end
    end

    alt audio_url_missing
        Parser-->>Parser: raise ParseException
    else audio_url_found
        Parser-->>Parser: create_audio(audio_url, duration, title, artist)
        Parser-->>Parser: create_image(cover_url)
        Parser-->>Parser: build audio_info(audio_level, audio_size, audio_type)
        Parser-->>Parser: build lyric_text(audio_info, lyric)
        Parser-->>Parser: result(contents, extra_info)
    end
Loading

File-Level Changes

Change Details Files
Enhance NetEase song parsing to try multiple audio qualities and infer audio metadata.
  • Log extracted song ID and basic song info for traceability.
  • Iterate over lossless and standard quality levels when requesting the song URL, selecting the first successful one.
  • Capture and store audio quality level, reported file size, and infer file type from the URL extension with a constrained whitelist.
  • Raise a parse exception if no audio URL can be retrieved after trying available levels.
src/nonebot_plugin_parser_lite/parsers/netease.py
Improve the constructed media response payload with richer text, logging, and type metadata.
  • Log the generated audio file name used for the media content.
  • Change the audio info string to include audio quality level and the raw size instead of a formatted display size.
  • Combine audio info and lyrics into a single text field stored under the lyric key.
  • Add type, type_tag, and type_icon fields to the extra metadata for downstream consumers.
src/nonebot_plugin_parser_lite/parsers/netease.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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - 我发现了 1 个问题,并给出了一些整体反馈:

  • 现在 extra["lyric"] 负载中包含了音频信息和格式化内容,而不再只是原始歌词字符串,这可能会破坏那些只期望纯歌词文本的使用方;建议为格式化文本新增一个字段,并将 lyric 保持为原始内容。
  • 新增的 audio_info 中的 audio_size 直接来自 url_data.get("size"),这很可能是字节数或未格式化的值;建议将其规范化为一个易读的大小(类似之前的 audio.get_display_size()),以保持展示形式一致。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `extra["lyric"]` payload now includes audio info and formatting instead of just the raw lyrics string, which may break any consumer that expects only plain lyrics; consider adding a new field for the formatted text and keeping `lyric` as the original content.
- The new `audio_size` in `audio_info` is taken directly from `url_data.get("size")`, which is likely bytes or an unformatted value; consider normalizing this to a human-readable size (similar to the previous `audio.get_display_size()`) to keep the display consistent.

## Individual Comments

### Comment 1
<location path="src/nonebot_plugin_parser_lite/parsers/netease.py" line_range="182" />
<code_context>
         extra = {
             "info": audio_info,
-            "lyric": lyric,
+            "lyric": text,
+            "type": "audio",
+            "type_tag": "音乐",
</code_context>
<issue_to_address>
**issue (bug_risk):** Reusing the `lyric` field for mixed metadata and lyrics may break consumers expecting plain lyric text.

`extra["lyric"]` used to be raw lyrics, but now holds formatted text mixing `audio_info` and lyrics. Any callers or UIs assuming plain lyrics may misbehave. If you need a combined text field, add a new key (e.g. `"description"` / `"full_text"`) and keep `"lyric"` as lyrics-only, unless you’ve confirmed all consumers can handle the new format.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进之后的代码审查。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • The extra["lyric"] payload now includes audio info and formatting instead of just the raw lyrics string, which may break any consumer that expects only plain lyrics; consider adding a new field for the formatted text and keeping lyric as the original content.
  • The new audio_size in audio_info is taken directly from url_data.get("size"), which is likely bytes or an unformatted value; consider normalizing this to a human-readable size (similar to the previous audio.get_display_size()) to keep the display consistent.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `extra["lyric"]` payload now includes audio info and formatting instead of just the raw lyrics string, which may break any consumer that expects only plain lyrics; consider adding a new field for the formatted text and keeping `lyric` as the original content.
- The new `audio_size` in `audio_info` is taken directly from `url_data.get("size")`, which is likely bytes or an unformatted value; consider normalizing this to a human-readable size (similar to the previous `audio.get_display_size()`) to keep the display consistent.

## Individual Comments

### Comment 1
<location path="src/nonebot_plugin_parser_lite/parsers/netease.py" line_range="182" />
<code_context>
         extra = {
             "info": audio_info,
-            "lyric": lyric,
+            "lyric": text,
+            "type": "audio",
+            "type_tag": "音乐",
</code_context>
<issue_to_address>
**issue (bug_risk):** Reusing the `lyric` field for mixed metadata and lyrics may break consumers expecting plain lyric text.

`extra["lyric"]` used to be raw lyrics, but now holds formatted text mixing `audio_info` and lyrics. Any callers or UIs assuming plain lyrics may misbehave. If you need a combined text field, add a new key (e.g. `"description"` / `"full_text"`) and keep `"lyric"` as lyrics-only, unless you’ve confirmed all consumers can handle the new format.
</issue_to_address>

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.

extra = {
"info": audio_info,
"lyric": lyric,
"lyric": text,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk):lyric 字段重复用于混合的元数据和歌词,可能会破坏那些期望获得纯歌词文本的使用方。

extra["lyric"] 之前是原始歌词,现在则变成了把 audio_info 和歌词混在一起的格式化文本。任何假定 extra["lyric"] 为纯歌词的调用方或 UI 都可能行为异常。如果你需要一个合并后的文本字段,建议新增一个键(例如 "description" / "full_text"),并保持 "lyric" 只包含歌词,除非你已经确认所有使用方都能处理这种新格式。

Original comment in English

issue (bug_risk): Reusing the lyric field for mixed metadata and lyrics may break consumers expecting plain lyric text.

extra["lyric"] used to be raw lyrics, but now holds formatted text mixing audio_info and lyrics. Any callers or UIs assuming plain lyrics may misbehave. If you need a combined text field, add a new key (e.g. "description" / "full_text") and keep "lyric" as lyrics-only, unless you’ve confirmed all consumers can handle the new format.

@molanp molanp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

感谢你的提交,我发现了一些问题请看一下。

lyric = (await self.fetch("getSongLyric", {"id": ncm_id})).get("lrc")
url_data = await self.fetch("getSongUrl", {"id": ncm_id, "level": "standard"})
if not (audio_url := url_data.get("url")):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这里逻辑建议和当前代码规范对齐。在当前的基础上加个for即可

extra = {
"info": audio_info,
"lyric": lyric,
"lyric": text,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

当前extra参数是预期的,不需要修改了

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.

3 participants