refactor: reformat source code.

This commit is contained in:
real-zony 2022-02-03 18:10:53 +08:00
parent 089559d058
commit ba3dd5f1bc
16 changed files with 37 additions and 56 deletions

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils; using McMaster.Extensions.CommandLineUtils;

View File

@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils; using McMaster.Extensions.CommandLineUtils;

View File

@ -53,7 +53,7 @@ namespace ZonyLrcTools.Cli.Commands
{ {
_logger.LogInformation("开始扫描文件夹,请稍等..."); _logger.LogInformation("开始扫描文件夹,请稍等...");
var files = (await _fileScanner.ScanAsync(FilePath, new[] {"*.ncm"})) var files = (await _fileScanner.ScanAsync(FilePath, new[] { "*.ncm" }))
.SelectMany(f => f.FilePaths) .SelectMany(f => f.FilePaths)
.ToList(); .ToList();
@ -95,7 +95,7 @@ namespace ZonyLrcTools.Cli.Commands
// TODO: Large Object Issue!!!!! // 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>()}");
await using var musicFileStream = File.Create(newFileName); await using var musicFileStream = File.Create(newFileName);
await musicFileStream.WriteAsync(result.Data); await musicFileStream.WriteAsync(result.Data);

View File

@ -44,7 +44,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Album.NetEase
true, true,
_defaultOption); _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); throw new ErrorCodeException(ErrorCodes.NoMatchingSong);
} }

View File

@ -39,7 +39,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Album.QQMusic
SearchApi, SearchApi,
requestParameter, _defaultOption); requestParameter, _defaultOption);
return new byte[] {0x1, 0x2}; return new byte[] { 0x1, 0x2 };
} }
} }
} }

View File

@ -4,17 +4,13 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel
{ {
public class GetLyricAccessKeyRequest public class GetLyricAccessKeyRequest
{ {
[JsonProperty("ver")] [JsonProperty("ver")] public int UnknownParameters1 { get; }
public int UnknownParameters1 { get; }
[JsonProperty("man")] [JsonProperty("man")] public string UnknownParameters2 { get; }
public string UnknownParameters2 { get; }
[JsonProperty("client")]
public string UnknownParameters3 { get; }
[JsonProperty("hash")] [JsonProperty("client")] public string UnknownParameters3 { get; }
public string FileHash { get; }
[JsonProperty("hash")] public string FileHash { get; }
public GetLyricAccessKeyRequest(string fileHash) public GetLyricAccessKeyRequest(string fileHash)
{ {

View File

@ -5,22 +5,17 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel
{ {
public class GetLyricAccessKeyResponse public class GetLyricAccessKeyResponse
{ {
[JsonProperty("status")] [JsonProperty("status")] public int Status { get; set; }
public int Status { get; set; }
[JsonProperty("errcode")] [JsonProperty("errcode")] public int ErrorCode { get; set; }
public int ErrorCode { get; set; }
[JsonProperty("candidates")] [JsonProperty("candidates")] public List<GetLyricAccessKeyDataObject> AccessKeyDataObjects { get; set; }
public List<GetLyricAccessKeyDataObject> AccessKeyDataObjects { get; set; }
} }
public class GetLyricAccessKeyDataObject public class GetLyricAccessKeyDataObject
{ {
[JsonProperty("accesskey")] [JsonProperty("accesskey")] public string AccessKey { get; set; }
public string AccessKey { get; set; }
[JsonProperty("id")] [JsonProperty("id")] public string Id { get; set; }
public string Id { get; set; }
} }
} }

View File

@ -6,14 +6,11 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel
{ {
public class SongSearchRequest public class SongSearchRequest
{ {
[JsonProperty("filter")] [JsonProperty("filter")] public int Filter { get; }
public int Filter { get; }
[JsonProperty("platform")] [JsonProperty("platform")] public string Platform { get; }
public string Platform { get; }
[JsonProperty("keyword")] [JsonProperty("keyword")] public string Keyword { get; }
public string Keyword { get; }
public SongSearchRequest(string musicName, string artistName) public SongSearchRequest(string musicName, string artistName)
{ {

View File

@ -5,23 +5,18 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel
{ {
public class SongSearchResponse public class SongSearchResponse
{ {
[JsonProperty("status")] [JsonProperty("status")] public int Status { get; set; }
public int Status { get; set; }
[JsonProperty("data")] [JsonProperty("data")] public SongSearchResponseInnerData Data { get; set; }
public SongSearchResponseInnerData Data { get; set; }
[JsonProperty("error_code")] [JsonProperty("error_code")] public int ErrorCode { get; set; }
public int ErrorCode { get; set; }
[JsonProperty("error_msg")] [JsonProperty("error_msg")] public string ErrorMessage { get; set; }
public string ErrorMessage { get; set; }
} }
public class SongSearchResponseInnerData public class SongSearchResponseInnerData
{ {
[JsonProperty("lists")] [JsonProperty("lists")] public List<SongSearchResponseSongDetail> List { get; set; }
public List<SongSearchResponseSongDetail> List { get; set; }
} }
public class SongSearchResponseSongDetail public class SongSearchResponseSongDetail

View File

@ -90,7 +90,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric
public static bool operator ==(LyricItem left, LyricItem right) 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) 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(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true; if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false; if (obj.GetType() != this.GetType()) return false;
return Equals((LyricItem) obj); return Equals((LyricItem)obj);
} }
public override int GetHashCode() public override int GetHashCode()

View File

@ -97,7 +97,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric
private static Dictionary<int, bool> BuildMarkDictionary(LyricItemCollection items) private static Dictionary<int, bool> BuildMarkDictionary(LyricItemCollection items)
{ {
return items return items
.Select((item, index) => new {index, item}) .Select((item, index) => new { index, item })
.ToDictionary(item => item.index, item => false); .ToDictionary(item => item.index, item => false);
} }

View File

@ -70,7 +70,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricDownloaderArgs args) 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); throw new ErrorCodeException(ErrorCodes.TheReturnValueIsIllegal, attachObj: args);
} }

View File

@ -14,8 +14,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption
/// </summary> /// </summary>
public class NcmMusicDecryptor : IMusicDecryptor, ITransientDependency 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[] 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[] AesModifyKey = { 0x23, 0x31, 0x34, 0x6C, 0x6A, 0x6B, 0x5F, 0x21, 0x5C, 0x5D, 0x26, 0x30, 0x55, 0x3C, 0x27, 0x28 };
public async Task<DecryptionResult> ConvertMusic(byte[] sourceBytes) public async Task<DecryptionResult> ConvertMusic(byte[] sourceBytes)
{ {
@ -72,7 +72,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption
{ {
ExtensionObjects = new Dictionary<string, object> ExtensionObjects = new Dictionary<string, object>
{ {
{"JSON", musicInfoJson} { "JSON", musicInfoJson }
} }
}; };
} }
@ -105,10 +105,10 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption
byte[] box = new byte[256]; byte[] box = new byte[256];
for (int i = 0; i < 256; ++i) 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 c;
byte lastByte = 0; byte lastByte = 0;
byte keyOffset = 0; byte keyOffset = 0;
@ -117,7 +117,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption
for (int i = 0; i < 256; ++i) for (int i = 0; i < 256; ++i)
{ {
swap = box[i]; swap = box[i];
c = (byte) ((swap + lastByte + key[keyOffset++]) & 0xff); c = (byte)((swap + lastByte + key[keyOffset++]) & 0xff);
if (keyOffset >= keyLength) if (keyOffset >= keyLength)
{ {
@ -169,7 +169,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.MusicDecryption
for (int i = 0; i < n; i++) 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]; tb[i] ^= sBox[sBox[j] + sBox[(sBox[j] + j) & 0xff] & 0xff];
} }

View File

@ -123,7 +123,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Network
{ {
HttpStatusCode.OK => responseString, HttpStatusCode.OK => responseString,
HttpStatusCode.ServiceUnavailable => throw new ErrorCodeException(ErrorCodes.ServiceUnavailable), 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
/// <exception cref="ErrorCodeException">如果反序列化失败,则可能抛出本异常。</exception> /// <exception cref="ErrorCodeException">如果反序列化失败,则可能抛出本异常。</exception>
private TResponse ConvertHttpResponseToObject<TResponse>(object requestParameters, string responseString) private TResponse ConvertHttpResponseToObject<TResponse>(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 try
{ {

View File

@ -9,7 +9,7 @@
/// 是否启用本功能。 /// 是否启用本功能。
/// </summary> /// </summary>
public bool IsEnable { get; set; } public bool IsEnable { get; set; }
/// <summary> /// <summary>
/// 屏蔽词字典文件,用于替换歌曲名或者歌手名称。 /// 屏蔽词字典文件,用于替换歌曲名或者歌手名称。
/// </summary> /// </summary>

View File

@ -27,7 +27,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
public async ValueTask<MusicInfo> LoadAsync(string filePath) public async ValueTask<MusicInfo> LoadAsync(string filePath)
{ {
await ValueTask.CompletedTask; await ValueTask.CompletedTask;
var regex = _options.TagInfoProviderOptions var regex = _options.TagInfoProviderOptions
.First(t => t.Name == ConstantName) .First(t => t.Name == ConstantName)
.Extensions[RegularExpressionsOption]; .Extensions[RegularExpressionsOption];