Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Commit 5a5b049

Browse files
committed
fix:lrc
1 parent 66801f7 commit 5a5b049

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/util.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ const trimLyric = (lyric) => {
3333
const result = []
3434
const lines = lyric.split('\n')
3535
for (const line of lines) {
36-
const match = line.match(/^\[(\d{2}):(\d{2}\.\d*)\](.*)$/)
36+
// 匹配两种格式:[mm:ss.xxx] 或 [hh:mm:ss]
37+
const match = line.match(/^\[(?:(\d{2}):)?(\d{2}):(\d{2})(?:\.(\d+))?\](.*)$/)
3738
if (match) {
39+
const hours = match[1] ? parseInt(match[1], 10) : 0
40+
const minutes = parseInt(match[2], 10)
41+
const seconds = parseInt(match[3], 10)
42+
const milliseconds = match[4] ? parseInt(match[4].padEnd(3, '0').slice(0, 3), 10) : 0
3843
result.push({
39-
time: parseInt(parseInt(match[1], 10) * 60 * 1000 + parseFloat(match[2]) * 1000),
40-
text: match[3]
44+
time: hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds,
45+
text: match[5]
4146
})
4247
}
4348
}

0 commit comments

Comments
 (0)