Skip to content

feat(lyric): 添加云盘音乐歌词支持#1022

Open
577fkj wants to merge 1 commit intoimsyy:devfrom
577fkj:dev
Open

feat(lyric): 添加云盘音乐歌词支持#1022
577fkj wants to merge 1 commit intoimsyy:devfrom
577fkj:dev

Conversation

@577fkj
Copy link
Copy Markdown
Contributor

@577fkj 577fkj commented Apr 2, 2026

  • 添加云盘音乐歌词支持

效果
image

Copilot AI review requested due to automatic review settings April 2, 2026 07:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

该 PR 为“云盘歌曲(pc)”补充在线歌词获取能力:优先从云盘歌词接口拉取,并在 Electron 缓存开启时按“用户维度”隔离缓存,避免不同账号间歌词串用。

Changes:

  • 新增云盘歌词 API:/cloud/lyric/get
  • 在线歌词获取逻辑中:云盘歌曲优先走云盘歌词接口,并引入 cloud_${userId}_${id} 缓存 key
  • 增强歌词字段兼容:支持歌词字段为 string 或 { lyric: string } 两种形态

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/core/player/LyricManager.ts 云盘歌词优先获取 + 用户隔离缓存 key + 更健壮的歌词字段读取
src/api/cloud.ts 新增云盘歌词请求封装 cloudSongLyric

Comment on lines 333 to 344
if (!data) {
data = await songLyric(id);
if (song.pc && userId) {
data = await cloudSongLyric(id, userId);
}
if (!data) {
data = await songLyric(id);
}
if (data && data.code === 200) {
this.saveRawLyricCache(id, "lrc", JSON.stringify(data));
this.saveRawLyricCache(lyricCacheKey, "lrc", JSON.stringify(data));
}
}
if (!data || data.code !== 200) return;
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

当 song.pc && userId 时会先请求 cloudSongLyric,但当前逻辑只有在 data 为 falsy 时才回退到 songLyric。若 cloudSongLyric 返回了一个非 200 的响应对象(例如 { code: 4xx }),这里会直接 return 导致整首歌没有歌词;建议在 cloudSongLyric 结果为空“或 code !== 200”时都回退到 songLyric,再统一做 code 校验与缓存写入。

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +50
export const cloudSongLyric = (sid: number, uid: number) => {
return request({
url: "/cloud/lyric/get",
params: {
sid,
uid,
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

cloudSongLyric 的参数顺序是 (sid, uid),但同文件的 matchCloudSong 是 (uid, sid, asid)。这种不一致很容易在后续调用时传参写反;建议统一为 (uid, sid) 或改为接收一个对象参数(如 { uid, sid })以提升可读性并减少误用风险。

Suggested change
export const cloudSongLyric = (sid: number, uid: number) => {
return request({
url: "/cloud/lyric/get",
params: {
sid,
uid,
export const cloudSongLyric = (uid: number, sid: number) => {
return request({
url: "/cloud/lyric/get",
params: {
uid,
sid,

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for fetching and caching cloud song lyrics by adding a new API endpoint and updating the LyricManager. Key changes include the implementation of a user-specific cache key for cloud songs and a helper function to standardize lyric text extraction from various data formats. A bug was identified in the lyric fetching logic where a non-200 response from the cloud API would incorrectly block the fallback to standard lyrics; a suggestion has been provided to ensure the fallback occurs whenever a successful cloud lyric response is not received.

Comment on lines 333 to 343
if (!data) {
data = await songLyric(id);
if (song.pc && userId) {
data = await cloudSongLyric(id, userId);
}
if (!data) {
data = await songLyric(id);
}
if (data && data.code === 200) {
this.saveRawLyricCache(id, "lrc", JSON.stringify(data));
this.saveRawLyricCache(lyricCacheKey, "lrc", JSON.stringify(data));
}
}
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.

high

The fallback logic for cloud song lyrics is incorrect. If cloudSongLyric returns a response object with a non-200 code (e.g., 404), the current implementation will skip the call to songLyric(id) because data is already truthy. This prevents the application from falling back to standard lyrics for cloud songs that might be matched in the library but don't have cloud-specific lyrics available in the cloud API.

Suggested change
if (!data) {
data = await songLyric(id);
if (song.pc && userId) {
data = await cloudSongLyric(id, userId);
}
if (!data) {
data = await songLyric(id);
}
if (data && data.code === 200) {
this.saveRawLyricCache(id, "lrc", JSON.stringify(data));
this.saveRawLyricCache(lyricCacheKey, "lrc", JSON.stringify(data));
}
}
if (!data) {
if (song.pc && userId) {
data = await cloudSongLyric(id, userId);
}
if (!data || data.code !== 200) {
data = await songLyric(id);
}
if (data && data.code === 200) {
this.saveRawLyricCache(lyricCacheKey, "lrc", JSON.stringify(data));
}
}

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.

2 participants