Skip to content

Commit c995ae0

Browse files
committed
🐞 fix: 修复 QM 翻译及对齐问题
1 parent 8a930d5 commit c995ae0

1 file changed

Lines changed: 10 additions & 20 deletions

File tree

src/core/player/LyricManager.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class LyricManager {
9595
if (lyricsData.length && otherLyrics.length) {
9696
lyricsData.forEach((v: LyricLine) => {
9797
otherLyrics.forEach((x: LyricLine) => {
98-
if (v.startTime === x.startTime || Math.abs(v.startTime - x.startTime) < 0.6) {
98+
if (v.startTime === x.startTime || Math.abs(v.startTime - x.startTime) < 600) {
9999
v[key] = x.words.map((word) => word.word).join("");
100100
}
101101
});
@@ -155,8 +155,6 @@ class LyricManager {
155155
*/
156156
private parseQRCLyric(qrcContent: string, trans?: string, roma?: string): LyricLine[] {
157157
const lines: LyricLine[] = [];
158-
// 感觉 QQ 音乐歌词时间全部有些慢,所以时间偏移一下
159-
const QRC_TIME_OFFSET = -200;
160158

161159
// 从 XML 中提取歌词内容
162160
const contentMatch = /<Lyric_1[^>]*LyricContent="([^"]*)"[^>]*\/>/.exec(qrcContent);
@@ -177,7 +175,7 @@ class LyricManager {
177175
const lineMatch = linePattern.exec(line);
178176
if (!lineMatch) continue;
179177

180-
const lineStart = parseInt(lineMatch[1], 10) + QRC_TIME_OFFSET;
178+
const lineStart = parseInt(lineMatch[1], 10);
181179
const lineDuration = parseInt(lineMatch[2], 10);
182180
const lineContent = lineMatch[3];
183181

@@ -188,7 +186,7 @@ class LyricManager {
188186

189187
while ((wordMatch = wordRegex.exec(lineContent)) !== null) {
190188
const wordText = wordMatch[1];
191-
const wordStart = parseInt(wordMatch[2], 10) + QRC_TIME_OFFSET;
189+
const wordStart = parseInt(wordMatch[2], 10);
192190
const wordDuration = parseInt(wordMatch[3], 10);
193191

194192
if (wordText) {
@@ -213,23 +211,22 @@ class LyricManager {
213211
}
214212
}
215213

216-
// 处理翻译歌词
214+
// 处理翻译
215+
let result = lines;
217216
if (trans) {
218217
const transLines = parseLrc(trans);
219218
if (transLines?.length) {
220-
return this.alignLyrics(lines, transLines, "translatedLyric");
219+
result = this.alignLyrics(result, transLines, "translatedLyric");
221220
}
222221
}
223-
224-
// 处理罗马音歌词
222+
// 处理罗马音
225223
if (roma) {
226224
const romaLines = parseLrc(roma);
227225
if (romaLines?.length) {
228-
return this.alignLyrics(lines, romaLines, "romanLyric");
226+
result = this.alignLyrics(result, romaLines, "romanLyric");
229227
}
230228
}
231-
232-
return lines;
229+
return result;
233230
}
234231

235232
/**
@@ -333,8 +330,6 @@ class LyricManager {
333330
// 处理 TTML 歌词
334331
const adoptTTML = async () => {
335332
if (!settingStore.enableOnlineTTMLLyric) return;
336-
// 如果已经有 QQ 音乐歌词,跳过 TTML
337-
if (qqMusicAdopted) return;
338333
let ttmlContent: string | null = await this.getRawLyricCache(id, "ttml");
339334
if (!ttmlContent) {
340335
ttmlContent = await songLyricTTML(id);
@@ -402,17 +397,12 @@ class LyricManager {
402397
const lyricData = this.handleLyricExclude(result);
403398
this.setFinalLyric(lyricData, req);
404399
};
405-
406400
// 优先获取 QQ 音乐歌词
407401
if (settingStore.preferQQMusicLyric) {
408402
await adoptQQMusic();
409403
}
410-
if (qqMusicAdopted) {
411-
statusStore.usingTTMLLyric = false;
412-
return result;
413-
}
414-
// 否则使用原有逻辑
415404
await Promise.allSettled([adoptTTML(), adoptLRC()]);
405+
// 优先使用 TTML
416406
statusStore.usingTTMLLyric = ttmlAdopted;
417407
return result;
418408
}

0 commit comments

Comments
 (0)