Skip to content

Commit

Permalink
fix qq music verbatim lyric last timestamp lost bugs #155
Browse files Browse the repository at this point in the history
  • Loading branch information
jitwxs committed Feb 26, 2023
1 parent 6b2f98d commit 3920567
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions MusicLyricApp/Bean/MusicLyricsVO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ public LyricTimestamp(long millisecond)
TimeOffset = millisecond;
}

public LyricTimestamp Add(long millisecond)
{
return new LyricTimestamp(TimeOffset + millisecond);
}

/// <summary>
/// 初始化 LyricTimestamp
/// </summary>
Expand Down
23 changes: 16 additions & 7 deletions MusicLyricApp/Utils/LyricUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,32 @@ public static string DealVerbatimLyric(string originLrc, SearchSourceEnum search
int leftParenthesesIndex = group.Index, parenthesesLength = group.Length;

// (404,202)
var timestamp = line.Substring(leftParenthesesIndex, parenthesesLength);
var timeStr = line.Substring(leftParenthesesIndex, parenthesesLength);
// 404
timestamp = timestamp.Split(',')[0].Trim().Substring(1);
// format
timestamp = new LyricTimestamp(long.Parse(timestamp))
.PrintTimestamp(defaultParam.LrcTimestampFormat, defaultParam.DotType);
var timestamp = long.Parse(timeStr.Split(',')[0].Trim().Substring(1));
var lyricTimestamp = new LyricTimestamp(timestamp);

var content = line.Substring(contentStartIndex, leftParenthesesIndex - contentStartIndex);
// 去除全行时间戳
// 首次执行,去除全行时间戳
if (i == 0)
{
content = new LyricLineVo(content).Content;
}

contentStartIndex = leftParenthesesIndex + parenthesesLength;

sb.Append(timestamp).Append(content);
sb.Append(lyricTimestamp.PrintTimestamp(defaultParam.LrcTimestampFormat, defaultParam.DotType)).Append(content);

// 最后一次执行,增加行结束时间戳
if (i == matches.Count - 1)
{
// 202
var timeCostStr = timeStr.Split(',')[1].Trim();
var timeCost = long.Parse(timeCostStr.Substring(0, timeCostStr.Length - 1));

sb.Append(lyricTimestamp.Add(timeCost)
.PrintTimestamp(defaultParam.LrcTimestampFormat, defaultParam.DotType));
}
} while (++i < matches.Count);
}
else
Expand Down
2 changes: 1 addition & 1 deletion MusicLyricAppTest/Utils/LyricUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void TestDealVerbatimLyric()
const string line = "[11562,5703]こ(11562,356)こ(11918,646)ろ(12564,270)を(12834,798) (13632,10)隠(13642,592)し(14234,356)て(14590,248)ひ(14838,260)と(15098,428)り(15526,396)で(15922,1343)";
var output = LyricUtils.DealVerbatimLyric(line, SearchSourceEnum.QQ_MUSIC);

Assert.AreEqual("[00:11.562]こ[00:11.918]こ[00:12.564]ろ[00:12.834]を[00:13.632] [00:13.642]隠[00:14.234]し[00:14.590]て[00:14.838]ひ[00:15.098]と[00:15.526]り[00:15.922]で" + Environment.NewLine, output);
Assert.AreEqual("[00:11.562]こ[00:11.918]こ[00:12.564]ろ[00:12.834]を[00:13.632] [00:13.642]隠[00:14.234]し[00:14.590]て[00:14.838]ひ[00:15.098]と[00:15.526]り[00:15.922]で[00:17.265]" + Environment.NewLine, output);
}

/// <summary>
Expand Down

0 comments on commit 3920567

Please sign in to comment.