@@ -6,16 +6,20 @@ 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 FastGlob from "fast-glob" ;
109import { Options as GlobOptions } from "fast-glob/out/settings" ;
10+ import FastGlob from "fast-glob" ;
1111
1212/**
1313 * 文件相关 IPC
1414 */
1515const 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