feat: 屏蔽词功能同标签读取器集成。

This commit is contained in:
real-zony 2021-06-04 23:16:41 +08:00
parent e917f6ee80
commit 625f24ccbf
3 changed files with 23 additions and 3 deletions

View File

@ -87,10 +87,12 @@ namespace ZonyLrcTools.Cli.Commands
var buffer = new Memory<byte>(new byte[2048]); var buffer = new Memory<byte>(new byte[2048]);
while (await file.ReadAsync(buffer) > 0) while (await file.ReadAsync(buffer) > 0)
{ {
// TODO: Large Object Issue!!!!!
await memoryStream.WriteAsync(buffer); await memoryStream.WriteAsync(buffer);
} }
} }
// TODO: Large Object Issue!!!!!
var result = await _musicDecryptor.ConvertMusic(memoryStream.ToArray()); var result = await _musicDecryptor.ConvertMusic(memoryStream.ToArray());
var newFileName = Path.Combine(Path.GetDirectoryName(filePath), var newFileName = Path.Combine(Path.GetDirectoryName(filePath),
$"{Path.GetFileNameWithoutExtension(filePath)}.{((JObject) result.ExtensionObjects["JSON"]).SelectToken("$.format").Value<string>()}"); $"{Path.GetFileNameWithoutExtension(filePath)}.{((JObject) result.ExtensionObjects["JSON"]).SelectToken("$.format").Value<string>()}");

View File

@ -13,12 +13,12 @@ namespace ZonyLrcTools.Cli.Infrastructure
/// <summary> /// <summary>
/// 歌曲的名称。 /// 歌曲的名称。
/// </summary> /// </summary>
public string Name { get; } public string Name { get; set; }
/// <summary> /// <summary>
/// 歌曲的作者。 /// 歌曲的作者。
/// </summary> /// </summary>
public string Artist { get; } public string Artist { get; set; }
/// <summary> /// <summary>
/// 构建一个新的 <see cref="MusicInfo"/> 对象。 /// 构建一个新的 <see cref="MusicInfo"/> 对象。

View File

@ -1,6 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using ZonyLrcTools.Cli.Config;
using ZonyLrcTools.Cli.Infrastructure.DependencyInject; using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
using ZonyLrcTools.Cli.Infrastructure.Exceptions; using ZonyLrcTools.Cli.Infrastructure.Exceptions;
@ -12,10 +14,16 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
public class DefaultTagLoader : ITagLoader, ITransientDependency public class DefaultTagLoader : ITagLoader, ITransientDependency
{ {
protected readonly IEnumerable<ITagInfoProvider> TagInfoProviders; protected readonly IEnumerable<ITagInfoProvider> TagInfoProviders;
protected readonly IBlockWordDictionary BlockWordDictionary;
protected ToolOptions Options;
public DefaultTagLoader(IEnumerable<ITagInfoProvider> tagInfoProviders) public DefaultTagLoader(IEnumerable<ITagInfoProvider> tagInfoProviders,
IBlockWordDictionary blockWordDictionary,
IOptions<ToolOptions> options)
{ {
TagInfoProviders = tagInfoProviders; TagInfoProviders = tagInfoProviders;
BlockWordDictionary = blockWordDictionary;
Options = options.Value;
} }
public virtual async ValueTask<MusicInfo> LoadTagAsync(string filePath) public virtual async ValueTask<MusicInfo> LoadTagAsync(string filePath)
@ -30,11 +38,21 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
var info = await provider.LoadAsync(filePath); var info = await provider.LoadAsync(filePath);
if (info != null) if (info != null)
{ {
HandleBlockWord(info);
return info; return info;
} }
} }
return null; 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;
}
}
} }
} }