From 625f24ccbfc79a2d48fb51a2f3219f6b0f10b72c Mon Sep 17 00:00:00 2001 From: real-zony Date: Fri, 4 Jun 2021 23:16:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B1=8F=E8=94=BD=E8=AF=8D=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=90=8C=E6=A0=87=E7=AD=BE=E8=AF=BB=E5=8F=96=E5=99=A8?= =?UTF-8?q?=E9=9B=86=E6=88=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/UtilityCommand.cs | 2 ++ .../Infrastructure/MusicInfo.cs | 4 ++-- .../Infrastructure/Tag/DefaultTagLoader.cs | 20 ++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ZonyLrcTools.Cli/Commands/UtilityCommand.cs b/src/ZonyLrcTools.Cli/Commands/UtilityCommand.cs index c3b0996..1a38ee4 100644 --- a/src/ZonyLrcTools.Cli/Commands/UtilityCommand.cs +++ b/src/ZonyLrcTools.Cli/Commands/UtilityCommand.cs @@ -87,10 +87,12 @@ namespace ZonyLrcTools.Cli.Commands var buffer = new Memory(new byte[2048]); while (await file.ReadAsync(buffer) > 0) { + // TODO: Large Object Issue!!!!! await memoryStream.WriteAsync(buffer); } } + // TODO: Large Object Issue!!!!! var result = await _musicDecryptor.ConvertMusic(memoryStream.ToArray()); var newFileName = Path.Combine(Path.GetDirectoryName(filePath), $"{Path.GetFileNameWithoutExtension(filePath)}.{((JObject) result.ExtensionObjects["JSON"]).SelectToken("$.format").Value()}"); diff --git a/src/ZonyLrcTools.Cli/Infrastructure/MusicInfo.cs b/src/ZonyLrcTools.Cli/Infrastructure/MusicInfo.cs index 04a9bd7..12cf680 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/MusicInfo.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/MusicInfo.cs @@ -13,12 +13,12 @@ namespace ZonyLrcTools.Cli.Infrastructure /// /// 歌曲的名称。 /// - public string Name { get; } + public string Name { get; set; } /// /// 歌曲的作者。 /// - public string Artist { get; } + public string Artist { get; set; } /// /// 构建一个新的 对象。 diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Tag/DefaultTagLoader.cs b/src/ZonyLrcTools.Cli/Infrastructure/Tag/DefaultTagLoader.cs index ee7466f..bf3ce61 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Tag/DefaultTagLoader.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Tag/DefaultTagLoader.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using ZonyLrcTools.Cli.Config; using ZonyLrcTools.Cli.Infrastructure.DependencyInject; using ZonyLrcTools.Cli.Infrastructure.Exceptions; @@ -12,10 +14,16 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag public class DefaultTagLoader : ITagLoader, ITransientDependency { protected readonly IEnumerable TagInfoProviders; + protected readonly IBlockWordDictionary BlockWordDictionary; + protected ToolOptions Options; - public DefaultTagLoader(IEnumerable tagInfoProviders) + public DefaultTagLoader(IEnumerable tagInfoProviders, + IBlockWordDictionary blockWordDictionary, + IOptions options) { TagInfoProviders = tagInfoProviders; + BlockWordDictionary = blockWordDictionary; + Options = options.Value; } public virtual async ValueTask LoadTagAsync(string filePath) @@ -30,11 +38,21 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag var info = await provider.LoadAsync(filePath); if (info != null) { + HandleBlockWord(info); return info; } } return null; } + + protected void HandleBlockWord(MusicInfo info) + { + if (Options.BlockWordOptions.IsEnable) + { + info.Name = BlockWordDictionary.GetValue(info.Name) ?? info.Name; + info.Artist = BlockWordDictionary.GetValue(info.Name) ?? info.Artist; + } + } } } \ No newline at end of file