Got synced lyrics working
This commit is contained in:
1 parent
ddef57b802
commit
22d6150290
3 files changed
+159
No files matched your search
@@ -0,0 +1,27 @@
|
||||
export const parseLyrics = (lrc: string) => {
|
||||
const regex = /^\[(\d{2}:\d{2}(.\d{2,3})?)\](.*)/
|
||||
const lines = lrc.split("\n")
|
||||
const output: { time: number; text: any }[] = []
|
||||
|
||||
const parseTime = (time: any) => {
|
||||
const minsec = time.split(":")
|
||||
const min = parseInt(minsec[0]) * 60
|
||||
const sec = parseFloat(minsec[1])
|
||||
return min + sec
|
||||
}
|
||||
|
||||
lines.forEach((line: any) => {
|
||||
const match = line.match(regex)
|
||||
if (match == null) return
|
||||
|
||||
const time = match[1]
|
||||
const text = match[3]
|
||||
|
||||
output.push({
|
||||
time: parseTime(time),
|
||||
text: text.trim(),
|
||||
})
|
||||
})
|
||||
|
||||
return output
|
||||
}
|
||||
Reference in new issue
Block a user