Skip to content

Commit

Permalink
Merge pull request #41 from karaoke-dev/add-more-definition-about-exc…
Browse files Browse the repository at this point in the history
…eption-format

Parse fails when files have multiple timestamps for single line of text
  • Loading branch information
andy840119 authored Mar 8, 2023
2 parents 6542cf9 + b4e0086 commit 1e533ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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[] { })]
Expand Down
4 changes: 3 additions & 1 deletion LrcParser/Parser/Lrc/Utils/LrcTimedTextUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ internal static Tuple<string, SortedDictionary<TextIndex, int>> 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.
Expand Down

0 comments on commit 1e533ab

Please sign in to comment.