Skip to content

Conversation

@kazukokawagawa
Copy link
Collaborator

No description provided.

@vercel
Copy link

vercel bot commented Dec 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
s-player Ready Ready Preview, Comment Dec 31, 2025 0:51am

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Shift_JIS 编码修复: 引入了 tryDecodeShiftJIS 工具函数,用于智能检测并修复音乐元数据中可能存在的 Shift_JIS 乱码问题,确保标题、艺术家和专辑等信息正确显示。
  • 本地文件路径处理: 对本地文件路径进行了 URL 编码处理,解决了路径中包含空格或特殊字符导致文件无法正确加载或播放的问题。
  • 扫描进度提示优化: 更新了本地音乐扫描过程中的用户提示信息,使其更加清晰和具体,提升了用户体验。
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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

本次 PR 主要修复了音乐元信息的特殊编码(Shift_JIS)乱码问题,并处理了本地文件路径中包含空格的情况,整体实现思路清晰。我发现了一些可以改进的地方:

  1. ipc-file.ts 中,元信息解码不完整,遗漏了歌词和评论字段,并且构造歌词字符串时使用了未解码的数据。
  2. helper.ts 中的解码函数存在重复逻辑,可以进行重构以提高代码可维护性。
  3. SongManager.ts 中对缓存文件路径的 URL 编码在 Windows 平台下存在缺陷,未能正确处理盘符。
    详细建议请见具体的评论。

Comment on lines 181 to 188
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 || ""),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

high

此处的编码修复不完整。歌词(common.lyrics)和评论(common.comment)等字段也可能存在乱码问题,但并未在 decodedCommon 中处理。建议在此处一并解码,以确保所有文本信息都能正确显示。

另外,请注意在 197-200 行构造 lyric 属性时,仍使用了未经处理的 common 对象,这会导致歌词乱码。在 decodedCommon 中处理完歌词解码后,应使用 decodedCommon 来构造 lyric 属性。

console.log(`🚀 [${id}] 由本地音乐缓存提供`);
return `file://${cachePath}`;
// 对路径进行 URL 编码,处理空格和特殊字符
const encodedPath = cachePath.split('/').map(encodeURIComponent).join('/');
Copy link
Contributor

Choose a reason for hiding this comment

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

high

此处的路径编码未处理 Windows 盘符(如 C:)的情况。encodeURIComponent 会将冒号编码,导致 file:// URL 在 Windows 上无效。此外,路径分隔符也应统一为 /。建议参考本文件 261-266 行的实现方式进行修正。

Comment on lines 84 to 116
// 尝试方案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 {
// 解码失败
}

Copy link
Contributor

Choose a reason for hiding this comment

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

medium

这三个 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 {
    // 解码失败,尝试下一种方案
  }
}

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