mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-02 21:30:41 +00:00
feat: Complete the logic of the basic file conversion method.
This commit is contained in:
parent
232c36de3b
commit
730d71afc0
@ -10,13 +10,11 @@ using Serilog;
|
|||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
|
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Exceptions;
|
using ZonyLrcTools.Cli.Infrastructure.Exceptions;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Extensions;
|
|
||||||
|
|
||||||
namespace ZonyLrcTools.Cli.Commands
|
namespace ZonyLrcTools.Cli.Commands
|
||||||
{
|
{
|
||||||
[Command("lyric-tool")]
|
[Command("lyric-tool")]
|
||||||
[Subcommand(typeof(ScanCommand),
|
[Subcommand(typeof(DownloadCommand),
|
||||||
typeof(DownloadCommand),
|
|
||||||
typeof(UtilityCommand))]
|
typeof(UtilityCommand))]
|
||||||
public class ToolCommand : ToolCommandBase
|
public class ToolCommand : ToolCommandBase
|
||||||
{
|
{
|
||||||
|
@ -1,17 +1,64 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using McMaster.Extensions.CommandLineUtils;
|
using McMaster.Extensions.CommandLineUtils;
|
||||||
|
using ZonyLrcTools.Cli.Infrastructure.IO;
|
||||||
|
using ZonyLrcTools.Cli.Infrastructure.Threading;
|
||||||
|
|
||||||
namespace ZonyLrcTools.Cli.Commands
|
namespace ZonyLrcTools.Cli.Commands
|
||||||
{
|
{
|
||||||
|
public enum SupportFileType
|
||||||
|
{
|
||||||
|
Ncm = 1,
|
||||||
|
Qcm = 2
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 工具类相关命令。
|
/// 工具类相关命令。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Command("util", Description = "提供常用的工具类功能。")]
|
[Command("util", Description = "提供常用的工具类功能。")]
|
||||||
public class UtilityCommand : ToolCommandBase
|
public class UtilityCommand : ToolCommandBase
|
||||||
{
|
{
|
||||||
protected override Task<int> OnExecuteAsync(CommandLineApplication app)
|
[Required(ErrorMessage = "音乐格式为必须参数,请指定 -t 参数。")]
|
||||||
|
[Option("-t|--type", CommandOptionType.SingleValue, Description = "需要转换的文件格式,参数[Ncm、Qcm]。", ShowInHelpText = true)]
|
||||||
|
public SupportFileType Type { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "文件路径为必须按参数,请传入有效路径。")]
|
||||||
|
[Argument(0, "Path", "指定需要转换的音乐文件路径,支持目录和文件路径。")]
|
||||||
|
public string Path { get; set; }
|
||||||
|
|
||||||
|
private readonly IFileScanner _fileScanner;
|
||||||
|
|
||||||
|
public UtilityCommand(IFileScanner fileScanner)
|
||||||
{
|
{
|
||||||
return base.OnExecuteAsync(app);
|
_fileScanner = fileScanner;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<int> OnExecuteAsync(CommandLineApplication app)
|
||||||
|
{
|
||||||
|
if (Directory.Exists(Path))
|
||||||
|
{
|
||||||
|
var files = await _fileScanner.ScanAsync(Path, new[] {"*.ncm"});
|
||||||
|
|
||||||
|
var wrapTask = new WarpTask(4);
|
||||||
|
var tasks = files
|
||||||
|
.SelectMany(f => f.FilePaths)
|
||||||
|
.Select(path => wrapTask.RunAsync(() => Convert(path)));
|
||||||
|
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
}
|
||||||
|
else if (File.Exists(Path))
|
||||||
|
{
|
||||||
|
await Convert(Path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Convert(string filePath)
|
||||||
|
{
|
||||||
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user