Skip to content

Commit

Permalink
Merge pull request #153 from jitwxs/dev
Browse files Browse the repository at this point in the history
Release v5.8
  • Loading branch information
jitwxs committed Jan 8, 2023
2 parents c726378 + e4d6270 commit 78c3b7c
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 8 deletions.
8 changes: 7 additions & 1 deletion MusicLyricApp/Bean/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace MusicLyricApp.Bean
{
public static class Constants
{
public const string Version = "v5.7";
public const string Version = "v5.8";

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

Expand Down Expand Up @@ -68,6 +68,12 @@ public static string GetContent(TypeEnum typeEnum)
list.Add("${singer} -> 歌手名");
list.Add("${album} -> 专辑名");
list.Add("-----");
list.Add("系统预设函数:");
list.Add("$fillLength(content,symbol,length)");
list.Add("长度填充,其中 content 表示操作的内容,symbol 表示填充的内容,length 表示填充的长度。" +
"例如 $fillLength(${index},0,3) 表示对于 ${index} 的结果,长度填充到 3 位,使用 0 填充" +
"【即 1 -> 001, 12 -> 012, 123 -> 123, 1234 -> 1234】");
list.Add("-----");
list.Add("您可自行决定输出哪些歌词类型,通过勾选复选框进行启用和关闭");
list.Add("拖拽最左侧的箭头可以调整输出的顺序");
list.Add("罗马音功能需要安装罗马音插件,非原始译文类型需要指定翻译 API");
Expand Down
4 changes: 2 additions & 2 deletions MusicLyricApp/Bean/MusicLyricsVO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,12 @@ public class LyricVo
/// <summary>
/// 歌词内容
/// </summary>
public string Lyric;
public string Lyric = "";

/// <summary>
/// 译文歌词内容
/// </summary>
public string TranslateLyric;
public string TranslateLyric = "";

/// <summary>
/// 歌曲时长 ms
Expand Down
49 changes: 49 additions & 0 deletions MusicLyricApp/Utils/GlobalUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,58 @@ public static string GetOutputName(SaveVo saveVo, string format)
.Replace("${singer}", songVo.Singer)
.Replace("${album}", songVo.Album);

outputName = ResolveCustomFunction(outputName);

return GetSafeFilename(outputName);
}

public static string ResolveCustomFunction(string content)
{
var sourceContent = content;

try
{
foreach (Match match in new Regex(@"\$fillLength\([^\)]*\)").Matches(content))
{
var raw = match.Value;

var leftQuote = raw.IndexOf("(", StringComparison.Ordinal) + 1;
var rightQuote = raw.IndexOf(")", StringComparison.Ordinal);

var split = raw.Substring(leftQuote, rightQuote - leftQuote).Split(',');
// 三个参数
if (split.Length != 3)
{
continue;
}

string res = split[0], keyword = split[1];

// 重复长度
if (!int.TryParse(split[2], out var targetLength))
{
continue;
}

while (res.Length < targetLength)
{
var diff = targetLength - res.Length;

res = (diff < keyword.Length ? keyword.Substring(0, diff) : keyword) + res;
}

content = content.Replace(raw, res);
}

return content;
}
catch (System.Exception e)
{
Logger.Error("ResolveCustomFunction error, content: " + sourceContent + ", stack: " + e);
return sourceContent;
}
}

private static string GetSafeFilename(string arbitraryString)
{
if (arbitraryString == null)
Expand Down
2 changes: 1 addition & 1 deletion MusicLyricApp/Utils/LyricUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private static async Task<List<LyricLineVo>> FormatLyric(string originLrc, strin
private static string[] SplitLrc(string lrc)
{
// 换行符统一
return lrc
return (lrc ?? "")
.Replace("\r\n", "\n")
.Replace("\r", "")
.Split('\n');
Expand Down
15 changes: 15 additions & 0 deletions MusicLyricAppTest/Utils/GlobalUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ public void TestCheckInputIdWithQQMusic()
Assert.Throws(typeof(MusicLyricException), () => CheckInputId("https://y.qq.com/n/ryqq/singer/004cyCLc1ByKPx", paramBean));
}

[Test]
public void ResolveCustomFunctionTest()
{
// 方法未找到
Assert.AreEqual("2$fillLength(${index},0,322", ResolveCustomFunction("2$fillLength(${index},0,322"));
// 参数数量不匹配
Assert.AreEqual("2$fillLength(${index},32)2", ResolveCustomFunction("2$fillLength(${index},32)2"));
// 不需要补齐
Assert.AreEqual("2${index}2", ResolveCustomFunction("2$fillLength(${index},0,2)2"));
// 补齐成功
Assert.AreEqual("20${index}2", ResolveCustomFunction("2$fillLength(${index},0,9)2"));
// 截位补齐
Assert.AreEqual("22${index}2", ResolveCustomFunction("2$fillLength(${index},20,9)2"));
}

[Test]
public void GetOutputNameTest()
{
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ the project, such as you are willing to contribute power, you can:
If this project brings you convenience, welcome to star to let more people discover and use it. This project is a
personal maintenance project. If you are willing to ask the author to drink a bottle of cola, welcome to donate.

| username | donate |
|:---------|:-------|
| DJKill | 3 CNY |
| username | donate | platform | date |
|:---------|:-------|:-------|:-------|
| *| 3 CNY | wechat | 2023-01-04 |
| **| 1.11 CNY | alipay | 2022-12-27 |
| DJKill | 3 CNY | wechat | 2022-12-20 |
| **| 5 CNY | alipay | 2022-12-05 |
| **| 3.5 CNY | alipay | 2022-11-05 |

> 如您选择打赏,记得备注您的昵称,我将为您登记到本页面中。
>
Expand All @@ -89,4 +93,10 @@ personal maintenance project. If you are willing to ask the author to drink a bo
<div align="center">
<img src="https://cdn.jsdelivr.net/gh/jitwxs/cdn/blog/configuration/alipay_donate_full.jpg" height="200" style="float:left;margin-right:20px;margin-left: 310px">
<img src="https://cdn.jsdelivr.net/gh/jitwxs/cdn/blog/configuration/wechat_donate_full.jpg" height="200" style="float:left">
</div>
</div>

最后,感谢 JetBrains 为本项目提供 IDE 赞助。

Finally, thanks to JetBrains for sponsoring the IDE for this project.

![Rider logo](https://resources.jetbrains.com/storage/products/company/brand/logos/Rider_icon.svg)
Binary file modified images/3_x_basic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/3_x_batch_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/5_6_version.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 78c3b7c

Please sign in to comment.