feat(player): 添加杜比全景声支持、MPV服务优化及缓存MD5校验#930
Conversation
- 添加杜比全景声音质支持,使用旧版接口并传入特殊参数 - 实现杜比音质自动降级机制,当歌曲不支持时自动切换到最高可用音质 - 添加 MPV 服务重启前的清理逻辑,确保进程正确停止避免资源占用 - 优化 MPV 进程启动参数,增加音频通道自动检测和损坏数据容错处理 - 添加 MPV 进程输出捕获用于调试,记录标准输出和错误输出 - 修改 cookie 设置添加 os=pc 参数以支持杜比音质数据获取 - 修复音质控制组件中当前音质显示的逻辑错误 - 统一新旧接口数据结构处理,兼容数组和对象格式返回值
Summary of ChangesHello @laoshuikaixue, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求主要围绕提升用户音频体验和增强播放器稳定性展开。核心改动是引入了杜比全景声音质支持,并为此设计了智能降级策略,确保在不同歌曲和设备兼容性下的最佳音质体验。同时,对 MPV 播放器服务进行了多项优化,包括启动参数调整、资源清理和调试信息捕获,显著提升了播放器的健壮性和可维护性。此外,还修复了音质显示问题并改进了数据接口的兼容性。 Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces Dolby Atmos support, optimizes MPV service management, and refines audio quality handling. Key changes include adding Dolby Atmos quality to song URL requests, implementing an automatic fallback mechanism for Dolby quality, and enhancing MPV process management by stopping it before application restarts and improving its startup parameters. Additionally, it fixes a logic error in quality display and unifies data structures for API responses. The changes improve audio quality options and application stability.
| @@ -1,11 +1,13 @@ | |||
| import { app, BrowserWindow, ipcMain } from "electron"; | |||
| import { MpvService } from "../services/MpvService"; | |||
There was a problem hiding this comment.
The MpvService import is added but not used in this file. It's good practice to remove unused imports to keep the codebase clean and avoid potential confusion.
| import { MpvService } from "../services/MpvService"; | |
| import { app, BrowserWindow, ipcMain } from "electron"; | |
| import { useStore } from "../store"; |
| import mainWindow from "../windows/main-window"; | ||
| import loadWindow from "../windows/load-window"; | ||
| import loginWindow from "../windows/login-window"; | ||
| import { processLog } from "../logger"; |
There was a problem hiding this comment.
| "--audio-channels=auto", // 自动检测音频通道 | ||
| "--demuxer-lavf-o=fflags=+discardcorrupt", // 容错处理,忽略损坏的数据 |
There was a problem hiding this comment.
The comments for --audio-channels=auto and --demuxer-lavf-o=fflags=+discardcorrupt are in Chinese. For consistency and maintainability, it's recommended to use English comments throughout the codebase, especially for technical parameters that might be understood by a broader audience.
| "--audio-channels=auto", // 自动检测音频通道 | |
| "--demuxer-lavf-o=fflags=+discardcorrupt", // 容错处理,忽略损坏的数据 | |
| "--audio-channels=auto", // Automatically detect audio channels | |
| "--demuxer-lavf-o=fflags=+discardcorrupt", // Error tolerance, ignore corrupt data |
| | "hires" | ||
| | "jyeffect" | ||
| | "sky" | ||
| | "dolby" |
There was a problem hiding this comment.
Adding 'dolby' to the level type union is correct for supporting Dolby Atmos. However, ensure that all call sites for songUrl are updated to handle this new level type appropriately, especially where level is cast to any (e.g., in SongManager.ts). It's better to refine the type inference or create specific overloads if the dolby level has distinct parameters or behavior.
| | "dolby" | |
| | "sky" | |
| | "dolby" |
| // 杜比全景声使用旧版接口,并传入特殊参数 | ||
| if (level === "dolby") { | ||
| return request({ | ||
| url: "/song/url", | ||
| params: { | ||
| id, | ||
| br: 999000, | ||
| immerseType: "c51", | ||
| timestamp: Date.now(), | ||
| }, | ||
| }); |
There was a problem hiding this comment.
The comment // 杜比全景声使用旧版接口,并传入特殊参数 is in Chinese. For consistency and maintainability, it's recommended to use English comments throughout the codebase.
| // 杜比全景声使用旧版接口,并传入特殊参数 | |
| if (level === "dolby") { | |
| return request({ | |
| url: "/song/url", | |
| params: { | |
| id, | |
| br: 999000, | |
| immerseType: "c51", | |
| timestamp: Date.now(), | |
| }, | |
| }); | |
| // Dolby Atmos uses the old interface and passes special parameters | |
| if (level === "dolby") { | |
| return request({ | |
| url: "/song/url", | |
| params: { | |
| id, | |
| br: 999000, | |
| immerseType: "c51", | |
| timestamp: Date.now(), | |
| }, | |
| }); | |
| } |
| if (level === "dolby") { | ||
| try { | ||
| const qualityRes = await songQuality(id); | ||
| const hasDb = qualityRes.data?.db && Number(qualityRes.data.db.br) > 0; | ||
| // 如果不支持杜比,降级到最高可用音质 | ||
| if (!hasDb) { | ||
| console.log(`🔽 [${id}] 歌曲不支持杜比音质,自动降级`); | ||
| // 按优先级降级:hires -> lossless -> exhigh | ||
| if (qualityRes.data?.hr && Number(qualityRes.data.hr.br) > 0) { | ||
| level = "hires"; | ||
| } else if (qualityRes.data?.sq && Number(qualityRes.data.sq.br) > 0) { | ||
| level = "lossless"; | ||
| } else { | ||
| level = "exhigh"; | ||
| } | ||
| } | ||
| } catch (e) { | ||
| console.error(`检查杜比音质支持失败,降级到极高音质:`, e); | ||
| level = "exhigh"; | ||
| } |
There was a problem hiding this comment.
The logic for Dolby Atmos fallback is well-implemented, prioritizing hires, then lossless, and finally exhigh. However, the console.log and console.error messages are in Chinese. For consistency and maintainability, it's recommended to use English messages throughout the codebase.
if (level === "dolby") {
try {
const qualityRes = await songQuality(id);
const hasDb = qualityRes.data?.db && Number(qualityRes.data.db.br) > 0;
// If Dolby is not supported, downgrade to the highest available quality
if (!hasDb) {
console.log(`🔽 [${id}] Song does not support Dolby Atmos, automatically downgrading`);
// Downgrade by priority: hires -> lossless -> exhigh
if (qualityRes.data?.hr && Number(qualityRes.data.hr.br) > 0) {
level = "hires";
} else if (qualityRes.data?.sq && Number(qualityRes.data.sq.br) > 0) {
level = "lossless";
} else {
level = "exhigh";
}
}
} catch (e) {
console.error(`Failed to check Dolby Atmos support, downgrading to exhigh quality:`, e);
level = "exhigh";
}
}| // 兼容新旧接口的数据结构 | ||
| const songData = Array.isArray(res.data) ? res.data[0] : res.data?.[0]; |
There was a problem hiding this comment.
The comment // 兼容新旧接口的数据结构 is in Chinese. For consistency and maintainability, it's recommended to use English comments throughout the codebase.
| // 兼容新旧接口的数据结构 | |
| const songData = Array.isArray(res.data) ? res.data[0] : res.data?.[0]; | |
| // Compatible with new and old interface data structures | |
| const songData = Array.isArray(res.data) ? res.data[0] : res.data?.[0]; |
| // 获取音质:如果请求的是杜比,直接使用杜比音质,否则从返回数据判断 | ||
| let quality: QualityType | undefined; | ||
| if (level === "dolby") { | ||
| // 请求的是杜比音质,直接标记为杜比 | ||
| quality = QualityType.Dolby; | ||
| } else { | ||
| // 其他音质从返回数据判断 | ||
| quality = handleSongQuality(songData, "online"); | ||
| } |
There was a problem hiding this comment.
The comments for determining song quality based on the level are in Chinese. For consistency and maintainability, it's recommended to use English comments throughout the codebase.
| // 获取音质:如果请求的是杜比,直接使用杜比音质,否则从返回数据判断 | |
| let quality: QualityType | undefined; | |
| if (level === "dolby") { | |
| // 请求的是杜比音质,直接标记为杜比 | |
| quality = QualityType.Dolby; | |
| } else { | |
| // 其他音质从返回数据判断 | |
| quality = handleSongQuality(songData, "online"); | |
| } | |
| // Get quality: if Dolby was requested, use Dolby quality directly, otherwise determine from returned data | |
| let quality: QualityType | undefined; | |
| if (level === "dolby") { | |
| // If Dolby quality was requested, directly mark as Dolby | |
| quality = QualityType.Dolby; | |
| } else { | |
| // Other qualities are determined from the returned data | |
| quality = handleSongQuality(songData, "online"); | |
| } |
|
使用旧版接口是因为新版接口获取到的数据不正确,相关功能在Windows平台测试没有问题 |
- 在music-cache-check IPC接口中新增md5参数支持 - 实现文件MD5计算方法用于缓存完整性验证 - 添加缓存文件MD5不匹配时自动删除机制 - 在SongManager中传递歌曲MD5进行缓存校验 - 优化缓存检查逻辑支持精确和模糊查找模式
Closed #875