Skip to content

Commit

Permalink
Merge pull request #97 from jitwxs/dev
Browse files Browse the repository at this point in the history
Release v4.4
  • Loading branch information
jitwxs authored May 28, 2022
2 parents ddbfdaf + 53844d1 commit 96c42d4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 19 deletions.
2 changes: 1 addition & 1 deletion MusicLyricApp/Bean/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace MusicLyricApp.Bean
{
public static class Constants
{
public const string Version = "v4.3";
public const string Version = "v4.4";

public static readonly string SettingPath = Environment.CurrentDirectory + "\\MusicLyricAppSetting.json";

Expand Down
53 changes: 47 additions & 6 deletions MusicLyricApp/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ private void TrySetHighDPIFont(string fontName)
/// </summary>
private void ReloadConfig()
{
var ids = Search_Text.Text.Trim().Split(',');
_globalSearchInfo.InputIds = new string[ids.Length];
for (var i = 0; i < ids.Length; i++)
{
_globalSearchInfo.InputIds[i] = ids[i].Trim();
}
ReloadInputIdText();

_globalSearchInfo.SongIds.Clear();

Expand All @@ -150,6 +145,52 @@ private void ReloadConfig()
}
}

private void ReloadInputIdText()
{
var inputText = Search_Text.Text.Trim();

// 判断是否是目录
if (Directory.Exists(inputText))
{
var subFileNameList = new List<string>();

var directoryInfo = new DirectoryInfo(inputText);
foreach (var info in directoryInfo.GetFileSystemInfos())
{
if (info is DirectoryInfo)
{
// 文件夹,跳过处理,不做递归
continue;
}
else
{
var name = info.Name;

if (!string.IsNullOrWhiteSpace(info.Extension) && name.EndsWith(info.Extension))
{
name = name.Remove(name.Length - info.Extension.Length);
}

name = name.Trim();

subFileNameList.Add(name);
}
}

_globalSearchInfo.InputIds = subFileNameList.ToArray();
}
else
{
// 不是目录,认为是实际的 ID
var ids = Search_Text.Text.Trim().Split(',');
_globalSearchInfo.InputIds = new string[ids.Length];
for (var i = 0; i < ids.Length; i++)
{
_globalSearchInfo.InputIds[i] = ids[i].Trim();
}
}
}

/// <summary>
/// 根据歌曲ID查询
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion MusicLyricApp/Utils/SrtUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void AddLine(LyricTimestamp start, LyricTimestamp end, string content)
}
}

if (i < inputList.Count - 1)
if (i < inputList.Count)
{
var lastVo = inputList[inputList.Count - 1];
AddLine(lastVo.Timestamp, durationTimestamp, lastVo.Content);
Expand Down
12 changes: 6 additions & 6 deletions MusicLyricAppTest/Utils/LyricUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ public void TestSetTimeStamp2Dot()

LyricUtils.SetMillisecondScale(scenario1, DotTypeEnum.HALF_UP, 2);

Assert.AreEqual("[00:12.53]", scenario1.Timestamp.ToString());
Assert.AreEqual("[00:12.53]", scenario1.Timestamp.ToString(OutputFormatEnum.LRC));

var scenario2 = new LyricLineVo("[00:12.526]綺麗な嘘ごと自分を騙し続けて");

LyricUtils.SetMillisecondScale(scenario2, DotTypeEnum.DOWN, 2);

Assert.AreEqual("[00:12.52]", scenario2.Timestamp.ToString());
Assert.AreEqual("[00:12.52]", scenario2.Timestamp.ToString(OutputFormatEnum.LRC));

var scenario3 = new LyricLineVo("[00:12.526]綺麗な嘘ごと自分を騙し続けて");

LyricUtils.SetMillisecondScale(scenario3, DotTypeEnum.DISABLE, 2);

Assert.AreEqual("[00:12.526]", scenario3.Timestamp.ToString());
Assert.AreEqual("[00:12.526]", scenario3.Timestamp.ToString(OutputFormatEnum.LRC));

var scenario4 = new LyricLineVo("[00:12.523]綺麗な嘘ごと自分を騙し続けて");

LyricUtils.SetMillisecondScale(scenario4, DotTypeEnum.HALF_UP, 2);

Assert.AreEqual("[00:12.52]", scenario4.Timestamp.ToString());
Assert.AreEqual("[00:12.52]", scenario4.Timestamp.ToString(OutputFormatEnum.LRC));

var scenario5 = new LyricLineVo("[00:00.000] 作词 : Kirara Magic");

LyricUtils.SetMillisecondScale(scenario5, DotTypeEnum.HALF_UP, 2);

Assert.AreEqual("[00:00.00]", scenario5.Timestamp.ToString());
Assert.AreEqual("[00:00.00]", scenario5.Timestamp.ToString(OutputFormatEnum.LRC));

var scenario6 = new LyricLineVo("[01:10.050] 作词 : Kirara Magic");

LyricUtils.SetMillisecondScale(scenario6, DotTypeEnum.HALF_UP, 2);

Assert.AreEqual("[01:10.50]", scenario6.Timestamp.ToString());
Assert.AreEqual("[01:10.50]", scenario6.Timestamp.ToString(OutputFormatEnum.LRC));
}
}
}
11 changes: 6 additions & 5 deletions MusicLyricAppTest/Utils/SrtUtilsTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Kawazu;
using NUnit.Framework;

Expand All @@ -12,18 +11,20 @@ public class SrtUtilsTest
[Test]
public void TestJapaneseLanguageJudge()
{
Main("ああだのこうだの知ったもんか 幸先の空は悪天候");
DoTest("ああだのこうだの知ったもんか 幸先の空は悪天候");

Main("[00:29.720]いつもどおりの通り独り こんな日々もはや懲り懲り");
DoTest("[00:29.720]いつもどおりの通り独り こんな日々もはや懲り懲り");

Thread.Sleep(1000);
}

private static async Task Main(string content)
private static void DoTest(string content)
{
var converter = new KawazuConverter();

Console.WriteLine(await converter.Convert(content, To.Romaji, Mode.Spaced, RomajiSystem.Hepburn, "(", ")"));
var task = converter.Convert(content, To.Romaji, Mode.Spaced, RomajiSystem.Hepburn, "(", ")");

Console.WriteLine(task.Result);
}
}
}

0 comments on commit 96c42d4

Please sign in to comment.