Skip to content

Commit c6f0d0b

Browse files
committed
✨ feat: 歌词文件不区分大小写
1 parent 880fc88 commit c6f0d0b

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

electron/main/ipc/ipc-file.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ import { getFileID, getFileMD5, metaDataLyricsArrayToLrc } from "../utils/helper
66
import { File, Picture, Id3v2Settings } from "node-taglib-sharp";
77
import { ipcLog } from "../logger";
88
import { download } from "electron-dl";
9-
import FastGlob from "fast-glob";
109
import { Options as GlobOptions } from "fast-glob/out/settings";
10+
import FastGlob from "fast-glob";
1111

1212
/**
1313
* 文件相关 IPC
1414
*/
1515
const initFileIpc = (): void => {
16+
/**
17+
* 获取全局搜索配置
18+
* @param cwd 当前工作目录
19+
*/
1620
const globOpt = (cwd?: string): GlobOptions => ({
1721
cwd,
18-
caseSensitiveMatch: false
22+
caseSensitiveMatch: false,
1923
});
2024

2125
// 默认文件夹
@@ -133,23 +137,25 @@ const initFileIpc = (): void => {
133137
}> => {
134138
try {
135139
const filePath = resolve(path).replace(/\\/g, "/");
136-
const { common } = await parseFile(filePath);
137140

138141
// 尝试获取同名的歌词文件
139142
const filePathWithoutExt = filePath.replace(/\.[^.]+$/, "");
140143
for (const ext of ["ttml", "lrc"] as const) {
141144
const lyricPath = `${filePathWithoutExt}.${ext}`;
142-
ipcLog.info("lyricPath", lyricPath);
143-
try {
144-
await access(lyricPath);
145-
const lyric = await readFile(lyricPath, "utf-8");
146-
if (lyric && lyric != "") return { lyric, format: ext };
147-
} catch {
148-
/* empty */
145+
const matches = await FastGlob(lyricPath, globOpt());
146+
ipcLog.info("lyric matches", matches);
147+
if (matches.length > 0) {
148+
try {
149+
const lyric = await readFile(matches[0], "utf-8");
150+
if (lyric && lyric !== "") return { lyric, format: ext };
151+
} catch {
152+
/* empty */
153+
}
149154
}
150155
}
151156

152157
// 尝试获取元数据
158+
const { common } = await parseFile(filePath);
153159
const lyric = common?.lyrics?.[0]?.syncText;
154160
if (lyric && lyric.length > 0) {
155161
return { lyric: metaDataLyricsArrayToLrc(lyric), format: "lrc" };

0 commit comments

Comments
 (0)