-
Notifications
You must be signed in to change notification settings - Fork 1k
🐞 fix: 部分特殊编码处理 & 本地文件携带空格处理 #696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Summary of ChangesHello @kazukokawagawa, 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! 此拉取请求旨在解决两个关键问题:一是由于编码不当(特别是 Shift_JIS)导致的音乐元数据乱码显示,二是本地音乐文件路径中包含空格或特殊字符时无法正确加载的问题。通过引入强大的编码检测和修复逻辑,并对文件路径进行适当的 URL 编码,显著提升了应用程序对多样化本地音乐库的兼容性和用户体验。 Highlights
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
本次 PR 主要修复了音乐元信息的特殊编码(Shift_JIS)乱码问题,并处理了本地文件路径中包含空格的情况,整体实现思路清晰。我发现了一些可以改进的地方:
- 在
ipc-file.ts中,元信息解码不完整,遗漏了歌词和评论字段,并且构造歌词字符串时使用了未解码的数据。 helper.ts中的解码函数存在重复逻辑,可以进行重构以提高代码可维护性。SongManager.ts中对缓存文件路径的 URL 编码在 Windows 平台下存在缺陷,未能正确处理盘符。
详细建议请见具体的评论。
| const decodedCommon = { | ||
| ...common, | ||
| title: tryDecodeShiftJIS(common.title || ""), | ||
| artist: tryDecodeShiftJIS(common.artist || ""), | ||
| album: tryDecodeShiftJIS(common.album || ""), | ||
| artists: common.artists?.map((a) => tryDecodeShiftJIS(a)), | ||
| albumartist: tryDecodeShiftJIS(common.albumartist || ""), | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/core/player/SongManager.ts
Outdated
| console.log(`🚀 [${id}] 由本地音乐缓存提供`); | ||
| return `file://${cachePath}`; | ||
| // 对路径进行 URL 编码,处理空格和特殊字符 | ||
| const encodedPath = cachePath.split('/').map(encodeURIComponent).join('/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
electron/main/utils/helper.ts
Outdated
| // 尝试方案1:Latin-1 → Shift_JIS | ||
| try { | ||
| const buffer = Buffer.from(text, "latin1"); | ||
| const decoded = iconv.decode(buffer, "Shift_JIS"); | ||
| if (isValidDecodedJapanese(decoded) && !hasJapaneseMojibakeChars(decoded)) { | ||
| return decoded; | ||
| } | ||
| } catch { | ||
| // 解码失败,尝试下一种方案 | ||
| } | ||
|
|
||
| // 尝试方案2:UTF-8 → Shift_JIS(某些工具会错误地将 Shift_JIS 当作 UTF-8 解码) | ||
| try { | ||
| const buffer = Buffer.from(text, "utf8"); | ||
| const decoded = iconv.decode(buffer, "Shift_JIS"); | ||
| if (isValidDecodedJapanese(decoded) && !hasJapaneseMojibakeChars(decoded)) { | ||
| return decoded; | ||
| } | ||
| } catch { | ||
| // 解码失败 | ||
| } | ||
|
|
||
| // 尝试方案3:CP932(Windows 日文扩展) | ||
| try { | ||
| const buffer = Buffer.from(text, "latin1"); | ||
| const decoded = iconv.decode(buffer, "CP932"); | ||
| if (isValidDecodedJapanese(decoded) && !hasJapaneseMojibakeChars(decoded)) { | ||
| return decoded; | ||
| } | ||
| } catch { | ||
| // 解码失败 | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这三个 try...catch 块的逻辑非常相似,可以重构为一个循环来处理不同的解码策略,以减少代码重复并提高可维护性。
const strategies: { from: BufferEncoding; to: string }[] = [
{ from: "latin1", to: "Shift_JIS" },
{ from: "utf8", to: "Shift_JIS" }, // 某些工具会错误地将 Shift_JIS 当作 UTF-8 解码
{ from: "latin1", to: "CP932" }, // Windows 日文扩展
];
for (const { from, to } of strategies) {
try {
const buffer = Buffer.from(text, from);
const decoded = iconv.decode(buffer, to);
if (isValidDecodedJapanese(decoded) && !hasJapaneseMojibakeChars(decoded)) {
return decoded;
}
} catch {
// 解码失败,尝试下一种方案
}
}
No description provided.