feat: refactor audio extraction to reusable class
This commit is contained in:
@@ -2,11 +2,13 @@ namespace StreamShorts.Console.Commands;
|
||||
|
||||
internal class DefaultCommand(
|
||||
IFileSystem fileSystem,
|
||||
IAnsiConsole console
|
||||
IAnsiConsole console,
|
||||
IAudioExtractor audioExtractor
|
||||
) : AsyncCommand<DefaultCommand.Settings>
|
||||
{
|
||||
private readonly IFileSystem _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
|
||||
private readonly IAnsiConsole _console = console ?? throw new ArgumentNullException(nameof(console));
|
||||
private readonly IAudioExtractor _audioExtractor = audioExtractor ?? throw new ArgumentNullException(nameof(audioExtractor));
|
||||
|
||||
internal class Settings : CommandSettings
|
||||
{
|
||||
@@ -37,9 +39,28 @@ internal class DefaultCommand(
|
||||
return base.Validate(context, settings);
|
||||
}
|
||||
|
||||
public override Task<int> ExecuteAsync(CommandContext context, Settings settings)
|
||||
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
|
||||
{
|
||||
_console.Write($"[green]Processing stream:[/] {settings.Stream}");
|
||||
return Task.FromResult(0);
|
||||
_console.MarkupLine($"[blue]Processing stream:[/] {settings.Stream}");
|
||||
var videoStream = _fileSystem.File.OpenRead(settings.Stream);
|
||||
|
||||
Stream? audioStream = null;
|
||||
|
||||
await _console.Status()
|
||||
.Spinner(Spinner.Known.Dots)
|
||||
.StartAsync("Extracting audio...", async ctx =>
|
||||
{
|
||||
audioStream = await _audioExtractor.ExtractMp3FromMp4Async(videoStream).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
if (audioStream is null)
|
||||
{
|
||||
_console.MarkupLine("[red]Failed[/] to extract audio from the stream.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
_console.MarkupLine($"[blue]Audio extracted[/] [green]successfully![/]");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user