Skip to content

Conversation

@kazukokawagawa
Copy link
Collaborator

No description provided.

- 重构时间解析函数,使用纯数学运算替代字符串操作以提高性能
- 移除全局正则表达式,改为在函数内局部使用避免状态污染
- 在解析过程中直接计算结束时间,消除二次遍历
- 优化歌词对齐算法,使用双指针实现 O(N) 复杂度
- 改进 QRC 格式解析,提前编译正则并优化 XML 内容提取
- 统一默认单词持续时间处理逻辑
- 在 DownloadManager 中添加 removeDownload 方法,支持从队列和 store 中移除任务
- 修复下载页面中播放全部按钮的逻辑,仅对已下载歌曲生效
- 优化下载中页面的封面显示逻辑,统一使用 getCover 方法
- 将 handleRemoveDownload 的参数类型扩展为 number | string 以支持多种 ID 类型
- 使用字符串补齐替代浮点数计算,避免时间解析的精度误差
- 将 alignLyrics 改为纯函数,不再修改输入数组
- 引入 XmlNode 辅助类重构 TTML 生成逻辑,提高可读性
- 优化 QRC 内容提取的正则表达式,增强健壮性
@kazukokawagawa kazukokawagawa marked this pull request as ready for review February 7, 2026 05:05
@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!

此拉取请求对歌词解析和对齐逻辑进行了重大重构,旨在提升性能、健壮性及代码可维护性。主要改进包括优化时间计算、精简正则表达式使用、实现单次遍历确定结束时间,并将歌词对齐算法升级至 O(N) 复杂度。此外,QRC 歌词解析得到增强,TTML 生成过程也通过新的 XML 构建器进行了现代化。同时,下载管理和用户界面元素也进行了相应调整以支持这些变化。

Highlights

  • 歌词解析性能提升: 重构时间解析函数,采用纯数学运算而非字符串操作,提高毫秒解析精度和效率。
  • 正则表达式优化: 移除全局正则表达式,改为在函数内部局部使用或通过 matchAll 方法,避免状态污染,增强代码可靠性。
  • 单次遍历计算结束时间: 歌词逐字和逐行解析过程中直接计算结束时间,消除二次遍历,提高解析效率。
  • 歌词对齐算法优化: alignLyrics 函数采用双指针算法,将时间复杂度从 O(N*M) 优化至 O(N),显著提升对齐速度。
  • QRC 格式解析改进: 提前编译 QRC 相关的正则表达式,并优化了从 XML 内容中提取歌词的逻辑,使其更健壮。
  • 统一默认单词持续时间: 统一了歌词解析中默认单词持续时间的处理逻辑。
  • 下载管理功能增强: DownloadManager 新增 removeDownload 方法,提供更细致的下载任务控制。
  • TTML 生成重构: 引入 XmlNode 辅助类,重构 TTML 格式歌词的生成逻辑,提高代码可读性和可维护性。
Changelog
  • src/core/resource/DownloadManager.ts
    • 新增 removeDownload 方法,用于管理下载任务。
  • src/utils/lyric/lyricParser.ts
    • 引入 lodash-escloneDeep 方法进行深拷贝。
    • 重构 parseTimeToMs 函数,通过字符串补齐处理毫秒,提高解析精度。
    • 移除全局正则表达式 (WORD_BY_WORD_REGEX, ENHANCED_WORD_REGEX),避免状态污染。
    • 新增 QRC_LINE_PATTERN, QRC_WORD_PATTERN, DEFAULT_WORD_DURATION, ALIGN_TOLERANCE_MS 常量。
    • 移除 fixLineEndTimes 函数,将其逻辑整合到解析过程中。
    • 优化 parseWordByWordLrcparseEnhancedLrc 函数,实现单次遍历计算结束时间,并局部使用正则表达式。
    • 重构 alignLyrics 函数,采用双指针算法实现 O(N) 复杂度,并接受 Readonly 类型的输入。
    • 改进 parseQRCLyric 函数,提前编译正则表达式并优化 XML 内容提取。
    • 新增 XmlNode 辅助类,用于构建 XML 结构。
    • 使用 XmlNode 类重写 lyricLinesToTTML 函数,使 TTML 生成代码更清晰。
  • src/views/Download/downloading.vue
    • 实现 getCover 函数,用于动态获取封面图片。
    • 更新 handleRemoveDownload 方法的 id 参数类型为 number | string
    • 导入 SongTypeCustomDownloadType 类型。
  • src/views/Download/layout.vue
    • 将“全部播放”按钮的点击事件绑定到 handlePlayAll 方法。
    • 移除 currentListData 计算属性。
    • 修改 handlePlayAll 方法,使其仅播放已下载的歌曲。
Activity
  • 目前没有关于此拉取请求的评论、审查或进展活动。
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 对歌词解析部分进行了出色的重构,显著提升了性能和代码质量。例如,通过单遍处理替代二次遍历来计算结束时间、使用双指针优化歌词对齐算法,以及引入 XmlNode 构建器来生成 TTML,这些都体现了优秀的工程实践。此外,移除全局正则表达式和优化时间解析函数也增强了代码的健壮性和可维护性。整体来看,这是一次高质量的重构。我在代码中发现了一些小问题,并提出了修改建议。

const lineMatch = linePattern.exec(line);
if (!lineMatch) continue;
// 跳过元数据标签 [ti:xxx] [ar:xxx] 等
if (/^\\[[a-z]+:/i.test(line)) continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

high

用于跳过元数据标签(如 [ti:xxx])的正则表达式 ^\[[a-z]+:/i 不正确。它会匹配以 \[ 开头的行,而不是以 [ 开头的元数据标签。这可能导致元数据行被错误地解析为歌词。建议使用文件顶部已定义的 META_TAG_REGEX 常量,以保证一致性和正确性。

Suggested change
if (/^\\[[a-z]+:/i.test(line)) continue;
if (META_TAG_REGEX.test(line)) continue;

kazukokawagawa and others added 3 commits February 7, 2026 13:11
将 QRC 歌词解析中的 LyricContent 提取逻辑重构为策略模式,根据运行环境自动选择 DOM 或正则解析器,提高代码可维护性和跨环境兼容性。
@imsyy imsyy merged commit 19bee05 into dev Feb 8, 2026
4 checks passed
@kazukokawagawa kazukokawagawa deleted the dev-fix branch February 8, 2026 06:39
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