Skip to content

Commit

Permalink
"<mm:dd.ss>" in the lyric store the absolute time, not the relative t…
Browse files Browse the repository at this point in the history
…ime.
  • Loading branch information
andy840119 committed Jul 28, 2024
1 parent 85cc166 commit a7c6aed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions LrcParser.Tests/Parser/Lrc/LrcParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void TestDecode()
{
var lrcText = new[]
{
"[00:17.00] <00:00.00>帰<00:01.00>り<00:02.00>道<00:03.00>は<00:04.00>",
"[00:17.00] <00:17.00>帰<00:18.00>り<00:19.00>道<00:20.00>は<00:21.00>",
};

var song = new Song
Expand Down Expand Up @@ -65,7 +65,7 @@ public void TestEncode()

var lrcText = new[]
{
"[00:17.00] <00:00.00>帰<00:01.00>り<00:02.00>道<00:03.00>は<00:04.00>",
"[00:17.00] <00:17.00>帰<00:18.00>り<00:19.00>道<00:20.00>は<00:21.00>",
};

checkEncode(song, lrcText);
Expand Down
12 changes: 6 additions & 6 deletions LrcParser/Parser/Lrc/LrcParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ static IEnumerable<Lyric> convertLyric(LrcLyric lrcLyric)
{
Text = lrcLyric.Text,
StartTime = startTime,
TimeTags = getTimeTags(lrcLyric.TimeTags, startTime),
TimeTags = getTimeTags(lrcLyric.TimeTags),
};
}
}

static SortedDictionary<TextIndex, int?> getTimeTags(SortedDictionary<TextIndex, int> timeTags, int offsetTime)
=> new(timeTags.ToDictionary(k => k.Key, v => v.Value + offsetTime as int?));
static SortedDictionary<TextIndex, int?> getTimeTags(SortedDictionary<TextIndex, int> timeTags)
=> new(timeTags.ToDictionary(k => k.Key, v => v.Value as int?));
}

protected override IEnumerable<object> PreProcess(Song song)
Expand All @@ -58,7 +58,7 @@ protected override IEnumerable<object> PreProcess(Song song)
{
Text = lyric.Text,
StartTimes = [lyric.StartTime],
TimeTags = getTimeTags(lyric.TimeTags, -lyric.StartTime),
TimeTags = getTimeTags(lyric.TimeTags),
};
}

Expand All @@ -72,7 +72,7 @@ protected override IEnumerable<object> PreProcess(Song song)

yield break;

static SortedDictionary<TextIndex, int> getTimeTags(SortedDictionary<TextIndex, int?> timeTags, int offsetTime = 0)
=> new(timeTags.Where(x => x.Value.HasValue).ToDictionary(k => k.Key, v => v.Value!.Value + offsetTime));
static SortedDictionary<TextIndex, int> getTimeTags(SortedDictionary<TextIndex, int?> timeTags)
=> new(timeTags.Where(x => x.Value.HasValue).ToDictionary(k => k.Key, v => v.Value!.Value));
}
}
2 changes: 1 addition & 1 deletion LrcParser/Parser/Lrc/Metadata/LrcLyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LrcLyric()

/// <summary>
/// Time tags.
/// It's the relative time from the start time.
/// It's the absolute time.
/// </summary>
public SortedDictionary<TextIndex, int> TimeTags { get; set; } = new();

Expand Down

0 comments on commit a7c6aed

Please sign in to comment.