mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-11-22 12:15:54 +08:00
fix(utils/lyrics): do not preserve the empty lyric
This commit is contained in:
parent
3ddfe9c3bb
commit
9ae5e4f059
|
@ -9,19 +9,18 @@ export function lyricParser(lrc) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const extractTimeRegex = /^(?<rawTime>\[(?<min>\d+):(?<sec>\d+)(?:\.|:)(?<ms>\d+)\])\s*(?<content>(.+|))$/;
|
const extractTimeRegex = /^(?<rawTime>\[(?<min>\d+):(?<sec>\d+)(?:\.|:)(?<ms>\d+)\])\s*(?<content>.+)$/;
|
||||||
|
|
||||||
function parseLyric(lrc) {
|
function parseLyric(lrc) {
|
||||||
const lyrics = lrc.trim().split('\n');
|
const lyrics = lrc.trim().split('\n');
|
||||||
|
|
||||||
const parsedLyrics = lyrics
|
const parsedLyrics = lyrics
|
||||||
.filter(lyric => lyric.length) // filter the lyric line which is empty
|
|
||||||
.map((/** @type {string} */ line) => {
|
.map((/** @type {string} */ line) => {
|
||||||
try {
|
try {
|
||||||
const extractedLyric = extractTimeRegex.exec(line);
|
const extractedLyric = extractTimeRegex.exec(line);
|
||||||
|
|
||||||
// If this line is not a lyric.
|
// If this line is not a lyric.
|
||||||
if (!extractedLyric) throw 'This line is not a lyric.';
|
if (!extractedLyric) throw 'This line is not a valid lyric.';
|
||||||
|
|
||||||
// Otherwise, we extract the lyric part.
|
// Otherwise, we extract the lyric part.
|
||||||
const { rawTime, min, sec, ms, content } = extractedLyric.groups;
|
const { rawTime, min, sec, ms, content } = extractedLyric.groups;
|
||||||
|
@ -33,7 +32,7 @@ function parseLyric(lrc) {
|
||||||
content: trimContent(content),
|
content: trimContent(content),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`Failed to extract "${line}". ${e}`);
|
console.debug(`lyrics.js: Failed to extract "${line}". ${e}`);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(response => !!response) // remove "undefined" entries
|
.filter(response => !!response) // remove "undefined" entries
|
||||||
|
|
Loading…
Reference in New Issue
Block a user