diff --git a/app/components/Player/Fullscreen.vue b/app/components/Player/Fullscreen.vue index 40600f8..af0ddca 100644 --- a/app/components/Player/Fullscreen.vue +++ b/app/components/Player/Fullscreen.vue @@ -1,4 +1,6 @@ + + + + diff --git a/app/utils/parseLyrics.ts b/app/utils/parseLyrics.ts new file mode 100644 index 0000000..0da10f6 --- /dev/null +++ b/app/utils/parseLyrics.ts @@ -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 +}