mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-11-22 10:56:23 +08:00
fix(utils/lyrics): [min:sec] timestamp lyrics parse (#1277)
* fix(utils/lyrics): [min:sec] timestamp lyrics parse * refactor(utils/lyrics): simplify time expression * style(utils/lyrics): remove duplicate space Co-authored-by: pan93412 <pan93412@gmail.com>
This commit is contained in:
parent
8a6c13e62f
commit
769ba47a1d
|
@ -9,7 +9,7 @@ export function lyricParser(lrc) {
|
||||||
|
|
||||||
// regexr.com/6e52n
|
// regexr.com/6e52n
|
||||||
const extractLrcRegex = /^(?<lyricTimestamps>(?:\[.+?\])+)(?!\[)(?<content>.+)$/gm;
|
const extractLrcRegex = /^(?<lyricTimestamps>(?:\[.+?\])+)(?!\[)(?<content>.+)$/gm;
|
||||||
const extractTimestampRegex = /\[(?<min>\d+):(?<sec>\d+)(?:\.|:)(?<ms>\d+)\]/g;
|
const extractTimestampRegex = /\[(?<min>\d+):(?<sec>\d+)(?:\.|:)*(?<ms>\d+)*\]/g;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{time: number, rawTime: string, content: string}} ParsedLyric
|
* @typedef {{time: number, rawTime: string, content: string}} ParsedLyric
|
||||||
|
@ -62,7 +62,8 @@ function parseLyric(lrc) {
|
||||||
for (const timestamp of lyricTimestamps.matchAll(extractTimestampRegex)) {
|
for (const timestamp of lyricTimestamps.matchAll(extractTimestampRegex)) {
|
||||||
const { min, sec, ms } = timestamp.groups;
|
const { min, sec, ms } = timestamp.groups;
|
||||||
const rawTime = timestamp[0];
|
const rawTime = timestamp[0];
|
||||||
const time = Number(min) * 60 + Number(sec) + 0.001 * Number(ms);
|
const time =
|
||||||
|
Number(min) * 60 + Number(sec) + Number(ms ?? 0) * 0.001;
|
||||||
|
|
||||||
/** @type {ParsedLyric} */
|
/** @type {ParsedLyric} */
|
||||||
const parsedLyric = { rawTime, time, content: trimContent(content) };
|
const parsedLyric = { rawTime, time, content: trimContent(content) };
|
||||||
|
|
Loading…
Reference in New Issue
Block a user