Skip to content

Commit b7c19d8

Browse files
committed
fix(synced-lyrics): merge consecutive empty lines and improve time parsing clarity
1 parent 9dfa1ad commit b7c19d8

File tree

1 file changed

+31
-4
lines changed
  • src/plugins/synced-lyrics/parsers

1 file changed

+31
-4
lines changed

src/plugins/synced-lyrics/parsers/lrc.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export const LRC = {
5555
const ms2 = milliseconds.padEnd(2, '0').slice(0, 2);
5656

5757
// Convert to ms (xx → xx0)
58-
const timeInMs =
59-
parseInt(minutes) * 60 * 1000 +
60-
parseInt(seconds) * 1000 +
61-
parseInt(ms2) * 10;
58+
const minutesMs = parseInt(minutes) * 60 * 1000;
59+
const secondsMs = parseInt(seconds) * 1000;
60+
const centisMs = parseInt(ms2) * 10;
61+
const timeInMs = minutesMs + secondsMs + centisMs;
6262

6363
const currentLine: LRCLine = {
6464
time: `${minutes.padStart(2, '0')}:${seconds.padStart(2, '0')}.${ms2}`,
@@ -89,6 +89,33 @@ export const LRC = {
8989
});
9090
}
9191

92+
// Merge consecutive empty lines into a single empty line
93+
{
94+
const merged: LRCLine[] = [];
95+
for (const line of lrc.lines) {
96+
const isEmpty = !line.text || !line.text.trim();
97+
if (isEmpty && merged.length > 0) {
98+
const prev = merged[merged.length - 1];
99+
const prevEmpty = !prev.text || !prev.text.trim();
100+
if (prevEmpty) {
101+
const prevEnd = Number.isFinite(prev.duration)
102+
? prev.timeInMs + prev.duration
103+
: Infinity;
104+
const thisEnd = Number.isFinite(line.duration)
105+
? line.timeInMs + line.duration
106+
: Infinity;
107+
const newEnd = Math.max(prevEnd, thisEnd);
108+
prev.duration = Number.isFinite(newEnd)
109+
? newEnd - prev.timeInMs
110+
: Infinity;
111+
continue;
112+
}
113+
}
114+
merged.push(line);
115+
}
116+
lrc.lines = merged;
117+
}
118+
92119
return lrc;
93120
},
94121
};

0 commit comments

Comments
 (0)