From b4e008667e713f0b216014ac7875398a36bcfbd6 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 8 Mar 2023 09:58:24 +0800 Subject: [PATCH] Will only save the first time-tag in the modal if got the duplicated time-tag in the lyric. --- LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs | 1 + LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs b/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs index cfb217f..6111bc3 100644 --- a/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs +++ b/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs @@ -15,6 +15,7 @@ public class LrcTimedTextUtilsTest [TestCase("[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22] ", "帰り道は ", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" })] [TestCase("帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", "帰り道は", new[] { "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" })] [TestCase("[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は", "帰り道は", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940" })] + [TestCase("[00:51.00][01:29.99][01:48.29][02:31.00][02:41.99]You gotta fight !", "You gotta fight !", new string[] { "[0,start]:51000" })] // decode with invalid format. [TestCase("帰り道は", "帰り道は", new string[] { })] [TestCase("", "", new string[] { })] [TestCase(null, "", new string[] { })] diff --git a/LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs b/LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs index cfa1694..2531d3d 100644 --- a/LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs +++ b/LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs @@ -44,7 +44,9 @@ internal static Tuple> TimedTextToObjec var state = hasText && !isEmptyStringNext ? IndexState.Start : IndexState.End; var textIndex = text.Length - (state == IndexState.Start ? 0 : 1); var time = TimeTagUtils.TimeTagToMillionSecond(match.Value); - timeTags.Add(new TextIndex(textIndex, state), time); + + // using try add because it might be possible with duplicated time-tag position in the lyric. + timeTags.TryAdd(new TextIndex(textIndex, state), time); } // should add remaining text at the right of the end time-tag.