Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"<mm:dd.ss>" in the lyric store the absolute time, not the relative time. #72

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 2024.0728
## 2024.0728.2
* "<mm:dd.ss>" in the `.lrc` file is absolute time, not the relative time.

## 2024.0728.1
* Add `StartTime` property in the `Model.Lyric` class. This property is used to store the start time of the lyric.~~
* `LrcParse` is re-written. Now it can follow the [LRC and Enhanced LRC format](https://en.wikipedia.org/wiki/LRC_(file_format) to decode/encode the lyric correctly.
* Create the `KarParser`, which is~~~~ u~~~~sed to parse the Karaoke file with format like `[00:51.00]ka[01:29.99]ra[01:48.29]o[02:31.00]ke[02:41.99]`.
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
Loading