From 2b0b14cd7a501cb09ef4bd7ea14f5b2a04271cc3 Mon Sep 17 00:00:00 2001 From: real-zony Date: Fri, 18 Mar 2022 19:51:08 +0800 Subject: [PATCH] Use YAML as configuration file; fix a download failure issue with QQ Music. (Reason: QQ Music API changed) --- .../Commands/SubCommand/DownloadCommand.cs | 4 +- src/ZonyLrcTools.Cli/Config/ProviderOption.cs | 17 ++++++ src/ZonyLrcTools.Cli/Config/ToolOptions.cs | 24 ++------- .../ServiceCollectionExtensions.cs | 8 +-- .../Lyric/ILyricItemCollectionFactory.cs | 3 +- .../Lyric/LyricItemCollection.cs | 5 +- .../Lyric/LyricItemCollectionFactory.cs | 4 +- .../Lyric/LyricItemCollectionOption.cs | 17 ------ .../Infrastructure/Lyric/LyricOption.cs | 28 ++++++++++ ...loaderOption.cs => LyricProviderOption.cs} | 2 +- .../Lyric/NetEase/NetEaseLyricDownloader.cs | 5 +- .../QQMusic/JsonModel/SongSearchRequest.cs | 38 -------------- .../QQMusic/JsonModel/SongSearchResponse.cs | 7 +-- .../Lyric/QQMusic/QQLyricDownloader.cs | 2 +- .../Infrastructure/Network/NetworkOptions.cs | 6 +-- .../Infrastructure/Tag/BlockWordDictionary.cs | 2 +- .../Infrastructure/Tag/BlockWordOption.cs | 2 +- .../Infrastructure/Tag/DefaultTagLoader.cs | 2 +- .../Tag/FileNameTagInfoProvider.cs | 4 +- .../Tag/TagInfoProviderOptions.cs | 13 ++++- src/ZonyLrcTools.Cli/Program.cs | 2 +- src/ZonyLrcTools.Cli/ZonyLrcTools.Cli.csproj | 8 +-- src/ZonyLrcTools.Cli/appsettings.json | 52 ------------------- src/ZonyLrcTools.Cli/config.yaml | 34 ++++++++++++ tests/ZonyLrcTools.Tests/FileScannerTests.cs | 3 +- .../Exceptions/ErrorCodeHelperTests.cs | 2 +- .../Lyric/LyricCollectionTests.cs | 4 +- .../Lyric/QQLyricDownloaderTests.cs | 2 +- .../Infrastructure/Network/WarpClientTests.cs | 4 +- .../Infrastructure/Tag/TagLoaderTests.cs | 3 +- 30 files changed, 136 insertions(+), 171 deletions(-) create mode 100644 src/ZonyLrcTools.Cli/Config/ProviderOption.cs delete mode 100644 src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollectionOption.cs create mode 100644 src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricOption.cs rename src/ZonyLrcTools.Cli/Infrastructure/Lyric/{LyricDownloaderOption.cs => LyricProviderOption.cs} (90%) delete mode 100644 src/ZonyLrcTools.Cli/appsettings.json create mode 100644 src/ZonyLrcTools.Cli/config.yaml diff --git a/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs b/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs index 740d8b6..b9bb05b 100644 --- a/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs +++ b/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs @@ -82,7 +82,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand private async Task> ScanMusicFilesAsync() { - var files = (await _fileScanner.ScanAsync(Directory, _options.SupportFileExtensions.Split(';'))) + var files = (await _fileScanner.ScanAsync(Directory, _options.SupportFileExtensions)) .SelectMany(t => t.FilePaths) .ToList(); @@ -112,7 +112,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand private IEnumerable GetLyricDownloaderList() { - var downloader = _options.LyricDownloaderOptions + var downloader = _options.Provider.Lyric.Plugin .Where(op => op.Priority != -1) .OrderBy(op => op.Priority) .Join(_lyricDownloaderList, diff --git a/src/ZonyLrcTools.Cli/Config/ProviderOption.cs b/src/ZonyLrcTools.Cli/Config/ProviderOption.cs new file mode 100644 index 0000000..87ad51c --- /dev/null +++ b/src/ZonyLrcTools.Cli/Config/ProviderOption.cs @@ -0,0 +1,17 @@ +using ZonyLrcTools.Cli.Infrastructure.Lyric; +using ZonyLrcTools.Cli.Infrastructure.Tag; + +namespace ZonyLrcTools.Cli.Config; + +public class ProviderOption +{ + /// + /// 标签加载器相关的配置属性。 + /// + public TagOption Tag { get; set; } + + /// + /// 歌词下载相关的配置信息。 + /// + public LyricOption Lyric { get; set; } +} \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Config/ToolOptions.cs b/src/ZonyLrcTools.Cli/Config/ToolOptions.cs index 22857ea..8c4b623 100644 --- a/src/ZonyLrcTools.Cli/Config/ToolOptions.cs +++ b/src/ZonyLrcTools.Cli/Config/ToolOptions.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using YamlDotNet.Serialization; using ZonyLrcTools.Cli.Infrastructure.Lyric; using ZonyLrcTools.Cli.Infrastructure.Network; using ZonyLrcTools.Cli.Infrastructure.Tag; @@ -8,19 +9,9 @@ namespace ZonyLrcTools.Cli.Config public class ToolOptions { /// - /// 支持的音乐文件后缀集合,以 ; 进行分隔。 + /// 支持的音乐文件后缀集合。 /// - public string SupportFileExtensions { get; set; } - - /// - /// 歌词下载相关的配置信息。 - /// - public LyricItemCollectionOption LyricOption { get; set; } - - /// - /// 标签加载器相关的配置属性。 - /// - public IEnumerable TagInfoProviderOptions { get; set; } + public List SupportFileExtensions { get; set; } /// /// 网络代理相关的配置信息。 @@ -28,13 +19,8 @@ namespace ZonyLrcTools.Cli.Config public NetworkOptions NetworkOptions { get; set; } /// - /// 歌词下载器相关的配置属性。 + /// 定义下载器的相关配置信息。 /// - public IEnumerable LyricDownloaderOptions { get; set; } - - /// - /// 屏蔽词功能相关配置。 - /// - public BlockWordOption BlockWordOptions { get; set; } + public ProviderOption Provider { get; set; } } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/DependencyInject/ServiceCollectionExtensions.cs b/src/ZonyLrcTools.Cli/Infrastructure/DependencyInject/ServiceCollectionExtensions.cs index 03e7bcb..b066df5 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/DependencyInject/ServiceCollectionExtensions.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/DependencyInject/ServiceCollectionExtensions.cs @@ -31,8 +31,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.DependencyInject return new HttpClientHandler { - UseProxy = option.NetworkOptions.Enable, - Proxy = new WebProxy($"{option.NetworkOptions.ProxyIp}:{option.NetworkOptions.ProxyPort}") + UseProxy = option.NetworkOptions.IsEnable, + Proxy = new WebProxy($"{option.NetworkOptions.Ip}:{option.NetworkOptions.Port}") }; }); @@ -46,10 +46,10 @@ namespace ZonyLrcTools.Cli.Infrastructure.DependencyInject { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") + .AddYamlFile("config.yaml") .Build(); - services.Configure(configuration.GetSection("ToolOption")); + services.Configure(configuration.GetSection("globalOption")); return services; } diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/ILyricItemCollectionFactory.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/ILyricItemCollectionFactory.cs index 91a7c0c..8177ba8 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/ILyricItemCollectionFactory.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/ILyricItemCollectionFactory.cs @@ -9,8 +9,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric /// 根据指定的歌曲数据构建新的 实例。 /// /// 原始歌词数据。 - /// 翻译歌词数据。 /// 构建完成的 对象。 - LyricItemCollection Build(string sourceLyric, string translateLyric = null); + LyricItemCollection Build(string sourceLyric); } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs index d6fdc27..2923854 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs @@ -16,9 +16,9 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric /// public bool IsPruneMusic => Count == 0; - public LyricItemCollectionOption Option { get; private set; } + public LyricConfigOption Option { get; private set; } - public LyricItemCollection(LyricItemCollectionOption option) + public LyricItemCollection(LyricConfigOption option) { Option = option; } @@ -33,7 +33,6 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric var option = left.Option; var newCollection = new LyricItemCollection(option); var indexDiff = left.Count - right.Count; - if (!option.IsOneLine) { left.ForEach(item => newCollection.Add(item)); diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollectionFactory.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollectionFactory.cs index 8ebe651..1bfabb0 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollectionFactory.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollectionFactory.cs @@ -17,9 +17,9 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric _options = options.Value; } - public LyricItemCollection Build(string sourceLyric, string translateLyric = null) + public LyricItemCollection Build(string sourceLyric) { - var items = new LyricItemCollection(_options.LyricOption); + var items = new LyricItemCollection(_options.Provider.Lyric.Config); if (string.IsNullOrEmpty(sourceLyric)) { return items; diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollectionOption.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollectionOption.cs deleted file mode 100644 index 8953543..0000000 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollectionOption.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace ZonyLrcTools.Cli.Infrastructure.Lyric -{ - public class LyricItemCollectionOption - { - /// - /// 双语歌词是否合并为一行。 - /// - public bool IsOneLine { get; set; } = false; - - /// - /// 换行符格式,取值来自 常量类。 - /// - public string LineBreak { get; set; } = LineBreakType.Windows; - - public static readonly LyricItemCollectionOption NullInstance = new(); - } -} \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricOption.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricOption.cs new file mode 100644 index 0000000..f5c622c --- /dev/null +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricOption.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; + +namespace ZonyLrcTools.Cli.Infrastructure.Lyric; + +public class LyricOption +{ + public IEnumerable Plugin { get; set; } + + public LyricConfigOption Config { get; set; } +} + +public class LyricConfigOption +{ + /// + /// 双语歌词是否合并为一行。 + /// + public bool IsOneLine { get; set; } = false; + + /// + /// 换行符格式,取值来自 常量类。 + /// + public string LineBreak { get; set; } = LineBreakType.Windows; + + /// + /// 是否启用歌词翻译功能。 + /// + public bool IsEnableTranslation { get; set; } = false; +} \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricDownloaderOption.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricProviderOption.cs similarity index 90% rename from src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricDownloaderOption.cs rename to src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricProviderOption.cs index 0dd72de..af1e680 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricDownloaderOption.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricProviderOption.cs @@ -1,6 +1,6 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric { - public class LyricDownloaderOption + public class LyricProviderOption { /// /// 歌词下载器的唯一标识。 diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/NetEaseLyricDownloader.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/NetEaseLyricDownloader.cs index 1bc167c..0f64890 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/NetEaseLyricDownloader.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/NetEaseLyricDownloader.cs @@ -61,7 +61,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase var json = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data)); if (json?.OriginalLyric == null) { - return new LyricItemCollection(LyricItemCollectionOption.NullInstance); + return new LyricItemCollection(null); } if (json.OriginalLyric.Text.Contains("纯音乐,请欣赏")) @@ -70,8 +70,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase } return _lyricItemCollectionFactory.Build( - json.OriginalLyric.Text, - json.TranslationLyric?.Text); + json.OriginalLyric.Text); } protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricDownloaderArgs args) diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/JsonModel/SongSearchRequest.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/JsonModel/SongSearchRequest.cs index 4345614..aae1411 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/JsonModel/SongSearchRequest.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/JsonModel/SongSearchRequest.cs @@ -6,70 +6,32 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic.JsonModel { public class SongSearchRequest { - [JsonProperty("ct")] public int UnknownParameter1 { get; set; } - - [JsonProperty("qqmusic_ver")] public int ClientVersion { get; set; } - - [JsonProperty("new_json")] public int UnknownParameter2 { get; set; } - [JsonProperty("remoteplace")] public string RemotePlace { get; set; } - [JsonProperty("t")] public int UnknownParameter3 { get; set; } - - [JsonProperty("aggr")] public int UnknownParameter4 { get; set; } - - [JsonProperty("cr")] public int UnknownParameter5 { get; set; } - - [JsonProperty("catZhida")] public int UnknownParameter6 { get; set; } - - [JsonProperty("lossless")] public int LossLess { get; set; } - - [JsonProperty("flag_qc")] public int UnknownParameter7 { get; set; } - [JsonProperty("p")] public int Page { get; set; } [JsonProperty("n")] public int Limit { get; set; } [JsonProperty("w")] public string Keyword { get; set; } - [JsonProperty("g_tk")] public int UnknownParameter8 { get; set; } - - [JsonProperty("hostUin")] public int UnknownParameter9 { get; set; } - [JsonProperty("format")] public string ResultFormat { get; set; } [JsonProperty("inCharset")] public string InCharset { get; set; } [JsonProperty("outCharset")] public string OutCharset { get; set; } - [JsonProperty("notice")] public int UnknownParameter10 { get; set; } - [JsonProperty("platform")] public string Platform { get; set; } - [JsonProperty("needNewCode")] public int UnknownParameter11 { get; set; } protected SongSearchRequest() { - UnknownParameter1 = 24; - ClientVersion = 1298; - UnknownParameter2 = 1; RemotePlace = "txt.yqq.song"; - UnknownParameter3 = 0; - UnknownParameter4 = 1; - UnknownParameter5 = 1; - UnknownParameter6 = 1; - LossLess = 0; - UnknownParameter7 = 0; Page = 1; Limit = 5; - UnknownParameter8 = 5381; - UnknownParameter9 = 0; ResultFormat = "json"; InCharset = "utf8"; OutCharset = "utf8"; - UnknownParameter10 = 0; Platform = "yqq"; - UnknownParameter11 = 0; } public SongSearchRequest(string musicName, string artistName) : this() diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/JsonModel/SongSearchResponse.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/JsonModel/SongSearchResponse.cs index b0d0663..ad759cc 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/JsonModel/SongSearchResponse.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/JsonModel/SongSearchResponse.cs @@ -22,11 +22,6 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic.JsonModel public class QQMusicInnerSongItem { - [JsonProperty("mid")] public string SongId { get; set; } - } - - public class AlbumInfo - { - [JsonProperty("id")] public long Id { get; set; } + [JsonProperty("songmid")] public string SongId { get; set; } } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/QQLyricDownloader.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/QQLyricDownloader.cs index 1cac4a6..e2a2365 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/QQLyricDownloader.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/QQLyricDownloader.cs @@ -65,7 +65,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic var sourceLyric = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(lyricJsonObj.SelectToken("$.lyric").Value())); var translateLyric = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(lyricJsonObj.SelectToken("$.trans").Value())); - return _lyricItemCollectionFactory.Build(sourceLyric, translateLyric); + return _lyricItemCollectionFactory.Build(sourceLyric); } protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricDownloaderArgs args) diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Network/NetworkOptions.cs b/src/ZonyLrcTools.Cli/Infrastructure/Network/NetworkOptions.cs index e7a39ca..af6ec83 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Network/NetworkOptions.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Network/NetworkOptions.cs @@ -8,16 +8,16 @@ namespace ZonyLrcTools.Cli.Infrastructure.Network /// /// 是否启用了网络代理功能。 /// - public bool Enable { get; set; } + public bool IsEnable { get; set; } /// /// 代理服务器的 Ip。 /// - public string ProxyIp { get; set; } + public string Ip { get; set; } /// /// 代理服务器的 端口。 /// - public int ProxyPort { get; set; } + public int Port { get; set; } } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordDictionary.cs b/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordDictionary.cs index 5d93000..af56d48 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordDictionary.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordDictionary.cs @@ -21,7 +21,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag _wordsDictionary = new Lazy>(() => { - var jsonData = File.ReadAllText(_options.BlockWordOptions.BlockWordDictionaryFile); + var jsonData = File.ReadAllText(_options.Provider.Tag.BlockWord.FilePath); return JsonConvert.DeserializeObject>(jsonData); }); } diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordOption.cs b/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordOption.cs index 19e61b1..5904523 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordOption.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordOption.cs @@ -13,6 +13,6 @@ /// /// 屏蔽词字典文件,用于替换歌曲名或者歌手名称。 /// - public string BlockWordDictionaryFile { get; set; } + public string FilePath { get; set; } } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Tag/DefaultTagLoader.cs b/src/ZonyLrcTools.Cli/Infrastructure/Tag/DefaultTagLoader.cs index 7403448..bf5b699 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Tag/DefaultTagLoader.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Tag/DefaultTagLoader.cs @@ -48,7 +48,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag protected void HandleBlockWord(MusicInfo info) { - if (Options.BlockWordOptions.IsEnable) + if (Options.Provider.Tag.BlockWord.IsEnable) { info.Name = BlockWordDictionary.GetValue(info.Name) ?? info.Name; info.Artist = BlockWordDictionary.GetValue(info.Name) ?? info.Artist; diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Tag/FileNameTagInfoProvider.cs b/src/ZonyLrcTools.Cli/Infrastructure/Tag/FileNameTagInfoProvider.cs index e81cd2e..f73ce1c 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Tag/FileNameTagInfoProvider.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Tag/FileNameTagInfoProvider.cs @@ -15,7 +15,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag { public string Name => ConstantName; public const string ConstantName = "FileName"; - public const string RegularExpressionsOption = "RegularExpressions"; + public const string RegularExpressionsOption = "regularExpressions"; private readonly ToolOptions _options; @@ -28,7 +28,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag { await ValueTask.CompletedTask; - var regex = _options.TagInfoProviderOptions + var regex = _options.Provider.Tag.Plugin .First(t => t.Name == ConstantName) .Extensions[RegularExpressionsOption]; diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Tag/TagInfoProviderOptions.cs b/src/ZonyLrcTools.Cli/Infrastructure/Tag/TagInfoProviderOptions.cs index 3d16cb0..74ae686 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Tag/TagInfoProviderOptions.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Tag/TagInfoProviderOptions.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; +using YamlDotNet.Serialization; namespace ZonyLrcTools.Cli.Infrastructure.Tag { - public class TagInfoProviderInstance + public class TagInfoProviderOption { public string Name { get; set; } @@ -10,4 +11,14 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag public Dictionary Extensions { get; set; } } + + public class TagOption + { + public IEnumerable Plugin { get; set; } + + /// + /// 屏蔽词功能相关配置。 + /// + public BlockWordOption BlockWord { get; set; } + } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Program.cs b/src/ZonyLrcTools.Cli/Program.cs index 75c85ad..6e64efa 100644 --- a/src/ZonyLrcTools.Cli/Program.cs +++ b/src/ZonyLrcTools.Cli/Program.cs @@ -75,7 +75,7 @@ namespace ZonyLrcTools.Cli { builder .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json"); + .AddYamlFile("config.yaml"); }) .ConfigureServices((_, services) => { diff --git a/src/ZonyLrcTools.Cli/ZonyLrcTools.Cli.csproj b/src/ZonyLrcTools.Cli/ZonyLrcTools.Cli.csproj index 5c59f97..823bd87 100644 --- a/src/ZonyLrcTools.Cli/ZonyLrcTools.Cli.csproj +++ b/src/ZonyLrcTools.Cli/ZonyLrcTools.Cli.csproj @@ -10,6 +10,7 @@ + @@ -23,9 +24,6 @@ - - Always - Always @@ -34,6 +32,10 @@ Always + + + Always + diff --git a/src/ZonyLrcTools.Cli/appsettings.json b/src/ZonyLrcTools.Cli/appsettings.json deleted file mode 100644 index c7a2db7..0000000 --- a/src/ZonyLrcTools.Cli/appsettings.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - }, - "ToolOption": { - "SupportFileExtensions": "*.mp3;*.flac;*.wav", - "NetworkOptions": { - "Enable": false, - "ProxyIp": "127.0.0.1", - "ProxyPort": 4780 - }, - "TagInfoProviderOptions": [ - { - "Name": "Taglib", - "Priority": 1 - }, - { - "Name": "FileName", - "Priority": 2, - "Extensions": { - "RegularExpressions": "(?'artist'.+)\\s-\\s(?'name'.+)" - } - } - ], - "LyricDownloaderOptions": [ - { - "Name": "NetEase", - "Priority": 1 - }, - { - "Name": "QQ", - "Priority": 2 - }, - { - "Name": "KuGou", - "Priority": 3 - } - ], - "LyricOption": { - "IsOneLine": true, - "LineBreak": "\n" - }, - "BlockWordOptions": { - "IsEnable": false, - "BlockWordDictionaryFile": "BlockWords.json" - } - } -} \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/config.yaml b/src/ZonyLrcTools.Cli/config.yaml new file mode 100644 index 0000000..8a0aa29 --- /dev/null +++ b/src/ZonyLrcTools.Cli/config.yaml @@ -0,0 +1,34 @@ +globalOption: + supportFileExtensions: + - '*.mp3' + - '*.flac' + - '*.wav' + networkOptions: + isEnable: false + ip: 127.0.0.1 + port: 4780 + + provider: + tag: + plugin: + - name: Taglib + priority: 1 + - name: FileName + priority: 2 + extensions: + regularExpressions: "(?'artist'.+)\\s-\\s(?'name'.+)" + blockWord: + isEnable: false + filePath: 'BlockWords.json' + lyric: + plugin: + - name: NetEase + priority: 1 + - name: QQ + priority: 2 + - name: KuGou + priority: 3 + config: + isOneLine: true + lineBreak: '\n' + isEnableTranslation: false \ No newline at end of file diff --git a/tests/ZonyLrcTools.Tests/FileScannerTests.cs b/tests/ZonyLrcTools.Tests/FileScannerTests.cs index 3a71de4..748b9a7 100644 --- a/tests/ZonyLrcTools.Tests/FileScannerTests.cs +++ b/tests/ZonyLrcTools.Tests/FileScannerTests.cs @@ -15,7 +15,8 @@ namespace ZonyLrcTools.Tests public async Task ScanAsync_Test() { var tempMusicFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Temp.mp3"); - File.Create(tempMusicFilePath); + var fs = File.Create(tempMusicFilePath); + fs.Close(); var fileScanner = ServiceProvider.GetRequiredService(); var result = await fileScanner.ScanAsync( diff --git a/tests/ZonyLrcTools.Tests/Infrastructure/Exceptions/ErrorCodeHelperTests.cs b/tests/ZonyLrcTools.Tests/Infrastructure/Exceptions/ErrorCodeHelperTests.cs index 3b26c6a..1bbe225 100644 --- a/tests/ZonyLrcTools.Tests/Infrastructure/Exceptions/ErrorCodeHelperTests.cs +++ b/tests/ZonyLrcTools.Tests/Infrastructure/Exceptions/ErrorCodeHelperTests.cs @@ -12,7 +12,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Exceptions ErrorCodeHelper.LoadErrorMessage(); ErrorCodeHelper.ErrorMessages.ShouldNotBeNull(); - ErrorCodeHelper.ErrorMessages.Count.ShouldBe(11); + ErrorCodeHelper.ErrorMessages.Count.ShouldBe(15); } [Fact] diff --git a/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/LyricCollectionTests.cs b/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/LyricCollectionTests.cs index 19a3c10..1fb17e9 100644 --- a/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/LyricCollectionTests.cs +++ b/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/LyricCollectionTests.cs @@ -9,7 +9,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyric [Fact] public void LyricCollectionLineBreak_Test() { - var lyricObject = new LyricItemCollection(new LyricItemCollectionOption + var lyricObject = new LyricItemCollection(new LyricConfigOption { IsOneLine = false, LineBreak = LineBreakType.MacOs @@ -18,7 +18,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyric new(0, 20, "你好世界!"), new(0, 22, "Hello World!") }; - + lyricObject.ToString().ShouldContain(LineBreakType.MacOs); } } diff --git a/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/QQLyricDownloaderTests.cs b/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/QQLyricDownloaderTests.cs index de5f1b5..64f8669 100644 --- a/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/QQLyricDownloaderTests.cs +++ b/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/QQLyricDownloaderTests.cs @@ -21,7 +21,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyric [Fact] public async Task DownloadAsync_Test() { - var lyric = await _lyricDownloader.DownloadAsync("Hollow", "Janet Leon"); + var lyric = await _lyricDownloader.DownloadAsync("东风破", "胡歌"); lyric.ShouldNotBeNull(); lyric.IsPruneMusic.ShouldBe(false); } diff --git a/tests/ZonyLrcTools.Tests/Infrastructure/Network/WarpClientTests.cs b/tests/ZonyLrcTools.Tests/Infrastructure/Network/WarpClientTests.cs index a90b634..6dcd8db 100644 --- a/tests/ZonyLrcTools.Tests/Infrastructure/Network/WarpClientTests.cs +++ b/tests/ZonyLrcTools.Tests/Infrastructure/Network/WarpClientTests.cs @@ -34,8 +34,8 @@ namespace ZonyLrcTools.Tests.Infrastructure.Network public async Task GetAsyncWithProxy_Test() { var option = ServiceProvider.GetRequiredService>(); - option.Value.NetworkOptions.ProxyIp = "127.0.0.1"; - option.Value.NetworkOptions.ProxyPort = 4780; + option.Value.NetworkOptions.Ip = "127.0.0.1"; + option.Value.NetworkOptions.Port = 4780; var client = ServiceProvider.GetRequiredService(); diff --git a/tests/ZonyLrcTools.Tests/Infrastructure/Tag/TagLoaderTests.cs b/tests/ZonyLrcTools.Tests/Infrastructure/Tag/TagLoaderTests.cs index d8387b8..c42ea55 100644 --- a/tests/ZonyLrcTools.Tests/Infrastructure/Tag/TagLoaderTests.cs +++ b/tests/ZonyLrcTools.Tests/Infrastructure/Tag/TagLoaderTests.cs @@ -1,3 +1,4 @@ +using System.IO; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Shouldly; @@ -14,7 +15,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Tag var tagLoader = ServiceProvider.GetRequiredService(); tagLoader.ShouldNotBeNull(); - var info = await tagLoader.LoadTagAsync(@"D:\はるまきごはん 煮ル果実 くらげP 蜂屋ななし じん かいりきベア - ダンスロボットダンス (アレンジメドレー (キメラver) はるまきごはん×煮ル果実×和田たけあき×栗山夕璃(蜂屋.flac"); + var info = await tagLoader.LoadTagAsync(Path.Combine(Directory.GetCurrentDirectory(), "MusicFiles", "曾经艺也 - 荀彧(纯音乐版).mp3")); info.ShouldNotBeNull(); info.Name.ShouldBe("荀彧(纯音乐版)"); info.Artist.ShouldBe("曾经艺也");