From ba3dd5f1bc41f82ddf338f69faeaca51ff3b82ea Mon Sep 17 00:00:00 2001 From: real-zony Date: Thu, 3 Feb 2022 18:10:53 +0800 Subject: [PATCH] refactor: reformat source code. --- src/ZonyLrcTools.Cli/Commands/ToolCommand.cs | 1 - src/ZonyLrcTools.Cli/Commands/ToolCommandBase.cs | 1 - src/ZonyLrcTools.Cli/Commands/UtilityCommand.cs | 4 ++-- .../Album/NetEase/NetEaseAlbumDownloader.cs | 2 +- .../Album/QQMusic/QQMusicAlbumDownloader.cs | 2 +- .../KuGou/JsonModel/GetLyricAccessKeyRequest.cs | 14 +++++--------- .../KuGou/JsonModel/GetLyricAccessKeyResponse.cs | 15 +++++---------- .../Lyric/KuGou/JsonModel/SongSearchRequest.cs | 9 +++------ .../Lyric/KuGou/JsonModel/SongSearchResponse.cs | 15 +++++---------- .../Infrastructure/Lyric/LyricItem.cs | 4 ++-- .../Infrastructure/Lyric/LyricItemCollection.cs | 2 +- .../Lyric/QQMusic/QQLyricDownloader.cs | 2 +- .../MusicDecryption/NcmMusicDecryptor.cs | 14 +++++++------- .../Network/DefaultWarpHttpClient.cs | 4 ++-- .../Infrastructure/Tag/BlockWordOption.cs | 2 +- .../Infrastructure/Tag/FileNameTagInfoProvider.cs | 2 +- 16 files changed, 37 insertions(+), 56 deletions(-) diff --git a/src/ZonyLrcTools.Cli/Commands/ToolCommand.cs b/src/ZonyLrcTools.Cli/Commands/ToolCommand.cs index 80ec0ae..64a64fe 100644 --- a/src/ZonyLrcTools.Cli/Commands/ToolCommand.cs +++ b/src/ZonyLrcTools.Cli/Commands/ToolCommand.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using McMaster.Extensions.CommandLineUtils; diff --git a/src/ZonyLrcTools.Cli/Commands/ToolCommandBase.cs b/src/ZonyLrcTools.Cli/Commands/ToolCommandBase.cs index d5a175b..a31885b 100644 --- a/src/ZonyLrcTools.Cli/Commands/ToolCommandBase.cs +++ b/src/ZonyLrcTools.Cli/Commands/ToolCommandBase.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Threading.Tasks; using McMaster.Extensions.CommandLineUtils; diff --git a/src/ZonyLrcTools.Cli/Commands/UtilityCommand.cs b/src/ZonyLrcTools.Cli/Commands/UtilityCommand.cs index 1a38ee4..ddc06f6 100644 --- a/src/ZonyLrcTools.Cli/Commands/UtilityCommand.cs +++ b/src/ZonyLrcTools.Cli/Commands/UtilityCommand.cs @@ -53,7 +53,7 @@ namespace ZonyLrcTools.Cli.Commands { _logger.LogInformation("开始扫描文件夹,请稍等..."); - var files = (await _fileScanner.ScanAsync(FilePath, new[] {"*.ncm"})) + var files = (await _fileScanner.ScanAsync(FilePath, new[] { "*.ncm" })) .SelectMany(f => f.FilePaths) .ToList(); @@ -95,7 +95,7 @@ namespace ZonyLrcTools.Cli.Commands // 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()}"); + $"{Path.GetFileNameWithoutExtension(filePath)}.{((JObject)result.ExtensionObjects["JSON"]).SelectToken("$.format").Value()}"); await using var musicFileStream = File.Create(newFileName); await musicFileStream.WriteAsync(result.Data); diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Album/NetEase/NetEaseAlbumDownloader.cs b/src/ZonyLrcTools.Cli/Infrastructure/Album/NetEase/NetEaseAlbumDownloader.cs index 5675749..f1e6583 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Album/NetEase/NetEaseAlbumDownloader.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Album/NetEase/NetEaseAlbumDownloader.cs @@ -44,7 +44,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Album.NetEase true, _defaultOption); - if (searchResult is not {StatusCode: 200} || searchResult.Items?.SongCount <= 0) + if (searchResult is not { StatusCode: 200 } || searchResult.Items?.SongCount <= 0) { throw new ErrorCodeException(ErrorCodes.NoMatchingSong); } diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Album/QQMusic/QQMusicAlbumDownloader.cs b/src/ZonyLrcTools.Cli/Infrastructure/Album/QQMusic/QQMusicAlbumDownloader.cs index 81c4c16..3236768 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Album/QQMusic/QQMusicAlbumDownloader.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Album/QQMusic/QQMusicAlbumDownloader.cs @@ -39,7 +39,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Album.QQMusic SearchApi, requestParameter, _defaultOption); - return new byte[] {0x1, 0x2}; + return new byte[] { 0x1, 0x2 }; } } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/GetLyricAccessKeyRequest.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/GetLyricAccessKeyRequest.cs index c325ca4..113cbba 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/GetLyricAccessKeyRequest.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/GetLyricAccessKeyRequest.cs @@ -4,17 +4,13 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel { public class GetLyricAccessKeyRequest { - [JsonProperty("ver")] - public int UnknownParameters1 { get; } + [JsonProperty("ver")] public int UnknownParameters1 { get; } - [JsonProperty("man")] - public string UnknownParameters2 { get; } - - [JsonProperty("client")] - public string UnknownParameters3 { get; } + [JsonProperty("man")] public string UnknownParameters2 { get; } - [JsonProperty("hash")] - public string FileHash { get; } + [JsonProperty("client")] public string UnknownParameters3 { get; } + + [JsonProperty("hash")] public string FileHash { get; } public GetLyricAccessKeyRequest(string fileHash) { diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/GetLyricAccessKeyResponse.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/GetLyricAccessKeyResponse.cs index 92dc775..400f4c1 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/GetLyricAccessKeyResponse.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/GetLyricAccessKeyResponse.cs @@ -5,22 +5,17 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel { public class GetLyricAccessKeyResponse { - [JsonProperty("status")] - public int Status { get; set; } + [JsonProperty("status")] public int Status { get; set; } - [JsonProperty("errcode")] - public int ErrorCode { get; set; } + [JsonProperty("errcode")] public int ErrorCode { get; set; } - [JsonProperty("candidates")] - public List AccessKeyDataObjects { get; set; } + [JsonProperty("candidates")] public List AccessKeyDataObjects { get; set; } } public class GetLyricAccessKeyDataObject { - [JsonProperty("accesskey")] - public string AccessKey { get; set; } + [JsonProperty("accesskey")] public string AccessKey { get; set; } - [JsonProperty("id")] - public string Id { get; set; } + [JsonProperty("id")] public string Id { get; set; } } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchRequest.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchRequest.cs index a5e629e..c8981e9 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchRequest.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchRequest.cs @@ -6,14 +6,11 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel { public class SongSearchRequest { - [JsonProperty("filter")] - public int Filter { get; } + [JsonProperty("filter")] public int Filter { get; } - [JsonProperty("platform")] - public string Platform { get; } + [JsonProperty("platform")] public string Platform { get; } - [JsonProperty("keyword")] - public string Keyword { get; } + [JsonProperty("keyword")] public string Keyword { get; } public SongSearchRequest(string musicName, string artistName) { diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchResponse.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchResponse.cs index 661d3b8..26ed934 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchResponse.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchResponse.cs @@ -5,23 +5,18 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel { public class SongSearchResponse { - [JsonProperty("status")] - public int Status { get; set; } + [JsonProperty("status")] public int Status { get; set; } - [JsonProperty("data")] - public SongSearchResponseInnerData Data { get; set; } + [JsonProperty("data")] public SongSearchResponseInnerData Data { get; set; } - [JsonProperty("error_code")] - public int ErrorCode { get; set; } + [JsonProperty("error_code")] public int ErrorCode { get; set; } - [JsonProperty("error_msg")] - public string ErrorMessage { get; set; } + [JsonProperty("error_msg")] public string ErrorMessage { get; set; } } public class SongSearchResponseInnerData { - [JsonProperty("lists")] - public List List { get; set; } + [JsonProperty("lists")] public List List { get; set; } } public class SongSearchResponseSongDetail diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItem.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItem.cs index 693a7d1..2eb7483 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItem.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItem.cs @@ -90,7 +90,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric public static bool operator ==(LyricItem left, LyricItem right) { - return (int?) left?.SortScore == (int?) right?.SortScore; + return (int?)left?.SortScore == (int?)right?.SortScore; } public static bool operator !=(LyricItem item1, LyricItem item2) @@ -113,7 +113,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != this.GetType()) return false; - return Equals((LyricItem) obj); + return Equals((LyricItem)obj); } public override int GetHashCode() diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs index f604dab..d6fdc27 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollection.cs @@ -97,7 +97,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric private static Dictionary BuildMarkDictionary(LyricItemCollection items) { return items - .Select((item, index) => new {index, item}) + .Select((item, index) => new { index, item }) .ToDictionary(item => item.index, item => false); } diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/QQLyricDownloader.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/QQLyricDownloader.cs index 210a128..1cac4a6 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/QQLyricDownloader.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/QQMusic/QQLyricDownloader.cs @@ -70,7 +70,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricDownloaderArgs args) { - if (response is not {StatusCode: 0} || response.Data.Song.SongItems == null) + if (response is not { StatusCode: 0 } || response.Data.Song.SongItems == null) { throw new ErrorCodeException(ErrorCodes.TheReturnValueIsIllegal, attachObj: args); } diff --git a/src/ZonyLrcTools.Cli/Infrastructure/MusicDecryption/NcmMusicDecryptor.cs b/src/ZonyLrcTools.Cli/Infrastructure/MusicDecryption/NcmMusicDecryptor.cs index ae15209..8317eba 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/MusicDecryption/NcmMusicDecryptor.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/MusicDecryption/NcmMusicDecryptor.cs @@ -14,8 +14,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption /// public class NcmMusicDecryptor : IMusicDecryptor, ITransientDependency { - protected readonly byte[] AesCoreKey = {0x68, 0x7A, 0x48, 0x52, 0x41, 0x6D, 0x73, 0x6F, 0x35, 0x6B, 0x49, 0x6E, 0x62, 0x61, 0x78, 0x57}; - protected readonly byte[] AesModifyKey = {0x23, 0x31, 0x34, 0x6C, 0x6A, 0x6B, 0x5F, 0x21, 0x5C, 0x5D, 0x26, 0x30, 0x55, 0x3C, 0x27, 0x28}; + protected readonly byte[] AesCoreKey = { 0x68, 0x7A, 0x48, 0x52, 0x41, 0x6D, 0x73, 0x6F, 0x35, 0x6B, 0x49, 0x6E, 0x62, 0x61, 0x78, 0x57 }; + protected readonly byte[] AesModifyKey = { 0x23, 0x31, 0x34, 0x6C, 0x6A, 0x6B, 0x5F, 0x21, 0x5C, 0x5D, 0x26, 0x30, 0x55, 0x3C, 0x27, 0x28 }; public async Task ConvertMusic(byte[] sourceBytes) { @@ -72,7 +72,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption { ExtensionObjects = new Dictionary { - {"JSON", musicInfoJson} + { "JSON", musicInfoJson } } }; } @@ -105,10 +105,10 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption byte[] box = new byte[256]; for (int i = 0; i < 256; ++i) { - box[i] = (byte) i; + box[i] = (byte)i; } - byte keyLength = (byte) key.Length; + byte keyLength = (byte)key.Length; byte c; byte lastByte = 0; byte keyOffset = 0; @@ -117,7 +117,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption for (int i = 0; i < 256; ++i) { swap = box[i]; - c = (byte) ((swap + lastByte + key[keyOffset++]) & 0xff); + c = (byte)((swap + lastByte + key[keyOffset++]) & 0xff); if (keyOffset >= keyLength) { @@ -169,7 +169,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption for (int i = 0; i < n; i++) { - var j = (byte) ((i + 1) & 0xff); + var j = (byte)((i + 1) & 0xff); tb[i] ^= sBox[sBox[j] + sBox[(sBox[j] + j) & 0xff] & 0xff]; } diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Network/DefaultWarpHttpClient.cs b/src/ZonyLrcTools.Cli/Infrastructure/Network/DefaultWarpHttpClient.cs index d6d2825..1cf0768 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Network/DefaultWarpHttpClient.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Network/DefaultWarpHttpClient.cs @@ -123,7 +123,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Network { HttpStatusCode.OK => responseString, HttpStatusCode.ServiceUnavailable => throw new ErrorCodeException(ErrorCodes.ServiceUnavailable), - _ => throw new ErrorCodeException(ErrorCodes.HttpRequestFailed, attachObj: new {requestParameters, responseString}) + _ => throw new ErrorCodeException(ErrorCodes.HttpRequestFailed, attachObj: new { requestParameters, responseString }) }; } @@ -136,7 +136,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Network /// 如果反序列化失败,则可能抛出本异常。 private TResponse ConvertHttpResponseToObject(object requestParameters, string responseString) { - var throwException = new ErrorCodeException(ErrorCodes.HttpResponseConvertJsonFailed, attachObj: new {requestParameters, responseString}); + var throwException = new ErrorCodeException(ErrorCodes.HttpResponseConvertJsonFailed, attachObj: new { requestParameters, responseString }); try { diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordOption.cs b/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordOption.cs index 6805b76..19e61b1 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordOption.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Tag/BlockWordOption.cs @@ -9,7 +9,7 @@ /// 是否启用本功能。 /// public bool IsEnable { get; set; } - + /// /// 屏蔽词字典文件,用于替换歌曲名或者歌手名称。 /// diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Tag/FileNameTagInfoProvider.cs b/src/ZonyLrcTools.Cli/Infrastructure/Tag/FileNameTagInfoProvider.cs index efe9e69..e81cd2e 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Tag/FileNameTagInfoProvider.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Tag/FileNameTagInfoProvider.cs @@ -27,7 +27,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag public async ValueTask LoadAsync(string filePath) { await ValueTask.CompletedTask; - + var regex = _options.TagInfoProviderOptions .First(t => t.Name == ConstantName) .Extensions[RegularExpressionsOption];