@@ -104,21 +104,6 @@ class LyricManager {
104104 }
105105 }
106106
107- /**
108- * 歌词内容对齐
109- * @param lyrics 歌词数据
110- * @param otherLyrics 其他歌词数据
111- * @param key 对齐类型
112- * @returns 对齐后的歌词数据
113- */
114- private alignLyrics (
115- lyrics : LyricLine [ ] ,
116- otherLyrics : LyricLine [ ] ,
117- key : "translatedLyric" | "romanLyric" ,
118- ) : LyricLine [ ] {
119- return alignLyrics ( lyrics , otherLyrics , key ) ;
120- }
121-
122107 /**
123108 * 对齐本地歌词
124109 * @param lyricData 本地歌词数据
@@ -222,7 +207,7 @@ class LyricManager {
222207 const result : SongLyric = { lrcData : [ ] , yrcData : [ ] } ;
223208 // 解析 QRC 逐字歌词
224209 if ( data . qrc ) {
225- const qrcLines = this . parseQRCLyric ( data . qrc , data . trans , data . roma ) ;
210+ const qrcLines = parseQRCLyric ( data . qrc , data . trans , data . roma ) ;
226211 if ( qrcLines . length > 0 ) {
227212 result . yrcData = qrcLines ;
228213 }
@@ -239,14 +224,14 @@ class LyricManager {
239224 const text = line . words . map ( ( w ) => w . word ) . join ( "" ) ;
240225 return ! text . includes ( "//" ) && ! text . includes ( "作品的著作权" ) ;
241226 } ) ;
242- lrcLines = this . alignLyrics ( lrcLines , transLines , "translatedLyric" ) ;
227+ lrcLines = alignLyrics ( lrcLines , transLines , "translatedLyric" ) ;
243228 }
244229 }
245230 // 处理罗马音
246231 if ( data . roma ) {
247232 const romaLines = parseLrc ( data . roma ) ;
248233 if ( romaLines ?. length ) {
249- lrcLines = this . alignLyrics ( lrcLines , romaLines , "romanLyric" ) ;
234+ lrcLines = alignLyrics ( lrcLines , romaLines , "romanLyric" ) ;
250235 }
251236 }
252237 if ( lrcLines . length > 0 ) {
@@ -260,17 +245,6 @@ class LyricManager {
260245 return result ;
261246 }
262247
263- /**
264- * 解析 QQ 音乐 QRC 格式歌词
265- * @param qrcContent QRC 原始内容
266- * @param trans 翻译歌词
267- * @param roma 罗马音歌词(QRC 格式)
268- * @returns LyricLine 数组
269- */
270- private parseQRCLyric ( qrcContent : string , trans ?: string , roma ?: string ) : LyricLine [ ] {
271- return parseQRCLyric ( qrcContent , trans , roma ) ;
272- }
273-
274248 /**
275249 * 切换歌词源优先级
276250 * @param source 优先级标识
@@ -285,11 +259,11 @@ class LyricManager {
285259 }
286260
287261 /**
288- * 处理在线歌词 (内部实现)
289- * @param id 歌曲 ID
262+ * 处理在线歌词
263+ * @param song 歌曲对象
290264 * @returns 歌词数据和元数据
291265 */
292- private async _fetchOnlineLyric ( song : SongType ) : Promise < LyricFetchResult > {
266+ private async fetchOnlineLyric ( song : SongType ) : Promise < LyricFetchResult > {
293267 const settingStore = useSettingStore ( ) ;
294268 const id = song . type === "radio" ? song . dj ?. id : song . id ;
295269 if ( ! id )
@@ -385,20 +359,20 @@ class LyricManager {
385359 lrcLines = parseLrc ( data . lrc . lyric ) || [ ] ;
386360 // 普通歌词翻译
387361 if ( data ?. tlyric ?. lyric )
388- lrcLines = this . alignLyrics ( lrcLines , parseLrc ( data . tlyric . lyric ) , "translatedLyric" ) ;
362+ lrcLines = alignLyrics ( lrcLines , parseLrc ( data . tlyric . lyric ) , "translatedLyric" ) ;
389363 // 普通歌词音译
390364 if ( data ?. romalrc ?. lyric )
391- lrcLines = this . alignLyrics ( lrcLines , parseLrc ( data . romalrc . lyric ) , "romanLyric" ) ;
365+ lrcLines = alignLyrics ( lrcLines , parseLrc ( data . romalrc . lyric ) , "romanLyric" ) ;
392366 }
393367 // 逐字歌词
394368 if ( data ?. yrc ?. lyric ) {
395369 yrcLines = parseYrc ( data . yrc . lyric ) || [ ] ;
396370 // 逐字歌词翻译
397371 if ( data ?. ytlrc ?. lyric )
398- yrcLines = this . alignLyrics ( yrcLines , parseLrc ( data . ytlrc . lyric ) , "translatedLyric" ) ;
372+ yrcLines = alignLyrics ( yrcLines , parseLrc ( data . ytlrc . lyric ) , "translatedLyric" ) ;
399373 // 逐字歌词音译
400374 if ( data ?. yromalrc ?. lyric )
401- yrcLines = this . alignLyrics ( yrcLines , parseLrc ( data . yromalrc . lyric ) , "romanLyric" ) ;
375+ yrcLines = alignLyrics ( yrcLines , parseLrc ( data . yromalrc . lyric ) , "romanLyric" ) ;
402376 }
403377 if ( lrcLines . length ) result . lrcData = lrcLines ;
404378 // 如果没有 TTML 且没有 QM YRC,则采用 网易云 YRC
@@ -450,29 +424,27 @@ class LyricManager {
450424
451425 /**
452426 * 处理本地歌词
453- * @param path 本地歌词路径
427+ * @param song 歌曲对象
454428 * @returns 歌词数据和元数据
455429 */
456- private async _fetchLocalLyric ( path : string ) : Promise < LyricFetchResult > {
430+ private async fetchLocalLyric ( song : SongType ) : Promise < LyricFetchResult > {
457431 const defaultResult : LyricFetchResult = {
458432 data : { lrcData : [ ] , yrcData : [ ] } ,
459433 meta : { usingTTMLLyric : false , usingQRCLyric : false } ,
460434 } ;
435+ if ( ! song . path ) return defaultResult ;
461436
462437 try {
463- const musicStore = useMusicStore ( ) ;
464438 const settingStore = useSettingStore ( ) ;
465439 const { lyric, format } : { lyric ?: string ; format ?: "lrc" | "ttml" | "yrc" } =
466- await window . electron . ipcRenderer . invoke ( "get-music-lyric" , path ) ;
467-
440+ await window . electron . ipcRenderer . invoke ( "get-music-lyric" , song . path ) ;
468441 if ( ! lyric ) return defaultResult ;
469-
470442 // YRC 直接解析
471443 if ( format === "yrc" ) {
472444 let lines : LyricLine [ ] = [ ] ;
473445 // 检测是否为 XML 格式 (QRC)
474446 if ( lyric . trim ( ) . startsWith ( "<" ) || lyric . includes ( "<QrcInfos>" ) ) {
475- lines = this . parseQRCLyric ( lyric ) ;
447+ lines = parseQRCLyric ( lyric ) ;
476448 } else {
477449 lines = parseYrc ( lyric ) || [ ] ;
478450 }
@@ -481,7 +453,6 @@ class LyricManager {
481453 meta : { usingTTMLLyric : false , usingQRCLyric : false } ,
482454 } ;
483455 }
484-
485456 // TTML 直接返回
486457 if ( format === "ttml" ) {
487458 const sorted = this . cleanTTMLTranslations ( lyric ) ;
@@ -492,26 +463,21 @@ class LyricManager {
492463 meta : { usingTTMLLyric : true , usingQRCLyric : false } ,
493464 } ;
494465 }
495-
496- // 解析本地歌词(智能识别格式)
466+ // 解析本地歌词
497467 const { format : lrcFormat , lines : parsedLines } = parseSmartLrc ( lyric ) ;
498-
499468 // 如果是逐字格式,直接作为 yrcData
500469 if ( isWordLevelFormat ( lrcFormat ) ) {
501470 return {
502471 data : { lrcData : [ ] , yrcData : parsedLines } ,
503472 meta : { usingTTMLLyric : false , usingQRCLyric : false } ,
504473 } ;
505474 }
506-
507- // 普通格式,继续原有逻辑
475+ // 普通格式
508476 let aligned = this . alignLocalLyrics ( { lrcData : parsedLines , yrcData : [ ] } ) ;
509477 let usingQRCLyric = false ;
510-
511478 // 如果开启了本地歌曲 QQ 音乐匹配,尝试获取逐字歌词
512- if ( settingStore . localLyricQQMusicMatch && musicStore . playSong ) {
513- // 注意:这里可能会产生递归调用风险,但 fetchQQMusicLyric 是独立的
514- const qqLyric = await this . fetchQQMusicLyric ( musicStore . playSong ) ;
479+ if ( settingStore . localLyricQQMusicMatch && song ) {
480+ const qqLyric = await this . fetchQQMusicLyric ( song ) ;
515481 if ( qqLyric && qqLyric . yrcData . length > 0 ) {
516482 // 使用 QQ 音乐的逐字歌词,但保留本地歌词作为 lrcData
517483 aligned = {
@@ -521,7 +487,6 @@ class LyricManager {
521487 usingQRCLyric = true ;
522488 }
523489 }
524-
525490 return {
526491 data : aligned ,
527492 meta : { usingTTMLLyric : false , usingQRCLyric } ,
@@ -607,7 +572,7 @@ class LyricManager {
607572 * @param id 歌曲 ID
608573 * @returns 歌词数据和元数据
609574 */
610- private async _fetchLocalOverrideLyric ( id : number ) : Promise < LyricFetchResult > {
575+ private async fetchLocalOverrideLyric ( id : number ) : Promise < LyricFetchResult > {
611576 const settingStore = useSettingStore ( ) ;
612577 const { localLyricPath } = settingStore ;
613578 const defaultResult : LyricFetchResult = {
@@ -881,14 +846,9 @@ class LyricManager {
881846 /**
882847 * 处理流媒体歌词
883848 * @param song 歌曲对象
884- * @returns 歌词数据
885- */
886- /**
887- * 处理流媒体歌词 (内部实现)
888- * @param song 歌曲对象
889849 * @returns 歌词数据和元数据
890850 */
891- private async _fetchStreamingLyric ( song : SongType ) : Promise < LyricFetchResult > {
851+ private async fetchStreamingLyric ( song : SongType ) : Promise < LyricFetchResult > {
892852 const result : SongLyric = { lrcData : [ ] , yrcData : [ ] } ;
893853 const defaultMeta = { usingTTMLLyric : false , usingQRCLyric : false } ;
894854
@@ -977,25 +937,25 @@ class LyricManager {
977937
978938 try {
979939 if ( isStreaming ) {
980- fetchResult = await this . _fetchStreamingLyric ( song ) ;
940+ fetchResult = await this . fetchStreamingLyric ( song ) ;
981941 } else {
982942 // 检查本地覆盖
983- const overrideResult = await this . _fetchLocalOverrideLyric ( song . id ) ;
943+ const overrideResult = await this . fetchLocalOverrideLyric ( song . id ) ;
984944 if ( ! isEmpty ( overrideResult . data . lrcData ) || ! isEmpty ( overrideResult . data . yrcData ) ) {
985945 // 对齐
986946 overrideResult . data = this . alignLocalLyrics ( overrideResult . data ) ;
987947 fetchResult = overrideResult ;
988948 } else if ( song . path ) {
989949 // 本地文件
990- fetchResult = await this . _fetchLocalLyric ( song . path ) ;
950+ fetchResult = await this . fetchLocalLyric ( song ) ;
991951 } else {
992952 // 在线获取 (已包含排除和变体处理)
993- fetchResult = await this . _fetchOnlineLyric ( song ) ;
953+ fetchResult = await this . fetchOnlineLyric ( song ) ;
994954 return fetchResult ;
995955 }
996956 }
997957
998- // 对于非 _fetchOnlineLyric 的结果,需要统一处理排除和变体
958+ // 对于非 fetchOnlineLyric 的结果,需要统一处理排除和变体
999959 if ( settingStore . enableExcludeLyricsLocal ) {
1000960 fetchResult . data = this . handleLyricExclude ( fetchResult . data , song ) ;
1001961 }
0 commit comments