From 9ae5e4f059c8e58942ca6af46874f7bce853e839 Mon Sep 17 00:00:00 2001 From: pan93412 Date: Thu, 27 Jan 2022 00:07:09 +0800 Subject: [PATCH] fix(utils/lyrics): do not preserve the empty lyric --- src/utils/lyrics.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/utils/lyrics.js b/src/utils/lyrics.js index 32aa8f0..a73dc7e 100644 --- a/src/utils/lyrics.js +++ b/src/utils/lyrics.js @@ -9,19 +9,18 @@ export function lyricParser(lrc) { }; } -const extractTimeRegex = /^(?\[(?\d+):(?\d+)(?:\.|:)(?\d+)\])\s*(?(.+|))$/; +const extractTimeRegex = /^(?\[(?\d+):(?\d+)(?:\.|:)(?\d+)\])\s*(?.+)$/; function parseLyric(lrc) { const lyrics = lrc.trim().split('\n'); const parsedLyrics = lyrics - .filter(lyric => lyric.length) // filter the lyric line which is empty .map((/** @type {string} */ line) => { try { const extractedLyric = extractTimeRegex.exec(line); // 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. const { rawTime, min, sec, ms, content } = extractedLyric.groups; @@ -33,7 +32,7 @@ function parseLyric(lrc) { content: trimContent(content), }; } catch (e) { - console.warn(`Failed to extract "${line}". ${e}`); + console.debug(`lyrics.js: Failed to extract "${line}". ${e}`); } }) .filter(response => !!response) // remove "undefined" entries