@@ -6,12 +6,22 @@ import { getFileID, getFileMD5, metaDataLyricsArrayToLrc } from "../utils/helper
66import { File , Picture , Id3v2Settings } from "node-taglib-sharp" ;
77import { ipcLog } from "../logger" ;
88import { download } from "electron-dl" ;
9+ import { Options as GlobOptions } from "fast-glob/out/settings" ;
910import FastGlob from "fast-glob" ;
1011
1112/**
1213 * 文件相关 IPC
1314 */
1415const initFileIpc = ( ) : void => {
16+ /**
17+ * 获取全局搜索配置
18+ * @param cwd 当前工作目录
19+ */
20+ const globOpt = ( cwd ?: string ) : GlobOptions => ( {
21+ cwd,
22+ caseSensitiveMatch : false ,
23+ } ) ;
24+
1525 // 默认文件夹
1626 ipcMain . handle (
1727 "get-default-dir" ,
@@ -27,7 +37,7 @@ const initFileIpc = (): void => {
2737 const filePath = resolve ( dirPath ) . replace ( / \\ / g, "/" ) ;
2838 console . info ( `📂 Fetching music files from: ${ filePath } ` ) ;
2939 // 查找指定目录下的所有音乐文件
30- const musicFiles = await FastGlob ( "**/*.{mp3,wav,flac,aac,webm}" , { cwd : filePath } ) ;
40+ const musicFiles = await FastGlob ( "**/*.{mp3,wav,flac,aac,webm}" , globOpt ( filePath ) ) ;
3141 // 解析元信息
3242 const metadataPromises = musicFiles . map ( async ( file ) => {
3343 const filePath = join ( dirPath , file ) ;
@@ -127,23 +137,25 @@ const initFileIpc = (): void => {
127137 } > => {
128138 try {
129139 const filePath = resolve ( path ) . replace ( / \\ / g, "/" ) ;
130- const { common } = await parseFile ( filePath ) ;
131140
132141 // 尝试获取同名的歌词文件
133142 const filePathWithoutExt = filePath . replace ( / \. [ ^ . ] + $ / , "" ) ;
134143 for ( const ext of [ "ttml" , "lrc" ] as const ) {
135144 const lyricPath = `${ filePathWithoutExt } .${ ext } ` ;
136- ipcLog . info ( "lyricPath" , lyricPath ) ;
137- try {
138- await access ( lyricPath ) ;
139- const lyric = await readFile ( lyricPath , "utf-8" ) ;
140- if ( lyric && lyric != "" ) return { lyric, format : ext } ;
141- } catch {
142- /* 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+ }
143154 }
144155 }
145156
146157 // 尝试获取元数据
158+ const { common } = await parseFile ( filePath ) ;
147159 const lyric = common ?. lyrics ?. [ 0 ] ?. syncText ;
148160 if ( lyric && lyric . length > 0 ) {
149161 return { lyric : metaDataLyricsArrayToLrc ( lyric ) , format : "lrc" } ;
@@ -207,7 +219,7 @@ const initFileIpc = (): void => {
207219 try {
208220 // 查找 ttml
209221 if ( ! result . ttml ) {
210- const ttmlFiles = await FastGlob ( patterns . ttml , { cwd : dir } ) ;
222+ const ttmlFiles = await FastGlob ( patterns . ttml , globOpt ( dir ) ) ;
211223 if ( ttmlFiles . length > 0 ) {
212224 const filePath = join ( dir , ttmlFiles [ 0 ] ) ;
213225 await access ( filePath ) ;
@@ -217,7 +229,7 @@ const initFileIpc = (): void => {
217229
218230 // 查找 lrc
219231 if ( ! result . lrc ) {
220- const lrcFiles = await FastGlob ( patterns . lrc , { cwd : dir } ) ;
232+ const lrcFiles = await FastGlob ( patterns . lrc , globOpt ( dir ) ) ;
221233 if ( lrcFiles . length > 0 ) {
222234 const filePath = join ( dir , lrcFiles [ 0 ] ) ;
223235 await access ( filePath ) ;
0 commit comments