refactor(backend): rename AudioTranscoderConfiguration/Service to AudioConfiguration/AudioService
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Musify.Infrastructure.Configuration
|
namespace Musify.Infrastructure.Configuration
|
||||||
{
|
{
|
||||||
public class AudioTranscoderConfiguration
|
public class AudioConfiguration
|
||||||
{
|
{
|
||||||
public const string SectionName = "AudioTranscoder";
|
public const string SectionName = "AudioTranscoder";
|
||||||
|
|
||||||
@@ -7,8 +7,8 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
namespace Musify.Infrastructure.Services
|
namespace Musify.Infrastructure.Services
|
||||||
{
|
{
|
||||||
public partial class AudioTranscoderService(ILogger<AudioTranscoderService> logger,
|
public partial class AudioService(ILogger<AudioService> logger,
|
||||||
AudioTranscoderConfiguration audioTranscoderConfiguration)
|
AudioConfiguration audioConfiguration)
|
||||||
: IAudioTranscoderService
|
: IAudioTranscoderService
|
||||||
{
|
{
|
||||||
record FfmpegExecutionResult(int ExitCode, string StandardOutput, string StandardError);
|
record FfmpegExecutionResult(int ExitCode, string StandardOutput, string StandardError);
|
||||||
@@ -25,7 +25,7 @@ namespace Musify.Infrastructure.Services
|
|||||||
logger.LogInformation("Starting audio transcoding for {DestinationPath}", destinationPath);
|
logger.LogInformation("Starting audio transcoding for {DestinationPath}", destinationPath);
|
||||||
|
|
||||||
var executionResult = await ExecuteFfmpegWithInputAsync(
|
var executionResult = await ExecuteFfmpegWithInputAsync(
|
||||||
BuildAudioFileArguments(destinationPath, audioTranscoderConfiguration.Ffmpeg),
|
BuildAudioFileArguments(destinationPath, audioConfiguration.Ffmpeg),
|
||||||
destinationPath,
|
destinationPath,
|
||||||
audioStream,
|
audioStream,
|
||||||
"TranscodeToAudioFile",
|
"TranscodeToAudioFile",
|
||||||
@@ -40,13 +40,13 @@ namespace Musify.Infrastructure.Services
|
|||||||
|
|
||||||
logger.LogInformation("Audio transcoding completed for {DestinationPath}", destinationPath);
|
logger.LogInformation("Audio transcoding completed for {DestinationPath}", destinationPath);
|
||||||
|
|
||||||
var outputPath = Path.Combine(destinationPath, audioTranscoderConfiguration.Ffmpeg.OutputFileName);
|
var outputPath = Path.Combine(destinationPath, audioConfiguration.Ffmpeg.OutputFileName);
|
||||||
var duration = await GetAudioDurationAsync(outputPath, cancellationToken);
|
var duration = await GetAudioDurationAsync(outputPath, cancellationToken);
|
||||||
return new AudioTranscodeResult(executionResult.ExitCode, duration);
|
return new AudioTranscodeResult(executionResult.ExitCode, duration);
|
||||||
}
|
}
|
||||||
catch (TimeoutException timeoutException)
|
catch (TimeoutException timeoutException)
|
||||||
{
|
{
|
||||||
logger.LogError(timeoutException, "Audio transcoding timed out after {Timeout} for {DestinationPath}", audioTranscoderConfiguration.TranscodingTimeout, destinationPath);
|
logger.LogError(timeoutException, "Audio transcoding timed out after {Timeout} for {DestinationPath}", audioConfiguration.TranscodingTimeout, destinationPath);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@@ -162,7 +162,7 @@ namespace Musify.Infrastructure.Services
|
|||||||
{
|
{
|
||||||
StartInfo = new ProcessStartInfo
|
StartInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = audioTranscoderConfiguration.Ffmpeg.ExecutableName,
|
FileName = audioConfiguration.Ffmpeg.ExecutableName,
|
||||||
WorkingDirectory = workingDirectory,
|
WorkingDirectory = workingDirectory,
|
||||||
Arguments = arguments,
|
Arguments = arguments,
|
||||||
RedirectStandardInput = redirectStandardInput,
|
RedirectStandardInput = redirectStandardInput,
|
||||||
@@ -181,7 +181,7 @@ namespace Musify.Infrastructure.Services
|
|||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using var linkedCancellationTokens = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
using var linkedCancellationTokens = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
||||||
linkedCancellationTokens.CancelAfter(audioTranscoderConfiguration.TranscodingTimeout);
|
linkedCancellationTokens.CancelAfter(audioConfiguration.TranscodingTimeout);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -190,10 +190,10 @@ namespace Musify.Infrastructure.Services
|
|||||||
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
|
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
logger.LogError("[{Operation}] ffmpeg timed out after {Timeout} (PID: {ProcessId} )",
|
logger.LogError("[{Operation}] ffmpeg timed out after {Timeout} (PID: {ProcessId} )",
|
||||||
operationName, audioTranscoderConfiguration.TranscodingTimeout, process.Id);
|
operationName, audioConfiguration.TranscodingTimeout, process.Id);
|
||||||
|
|
||||||
TryKillProcess(process);
|
TryKillProcess(process);
|
||||||
throw new TimeoutException($"ffmpeg execution exceeded timeout {audioTranscoderConfiguration.TranscodingTimeout}.");
|
throw new TimeoutException($"ffmpeg execution exceeded timeout {audioConfiguration.TranscodingTimeout}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var standardError = await errorTask;
|
var standardError = await errorTask;
|
||||||
|
|||||||
@@ -77,14 +77,14 @@ namespace Musify.Infrastructure.Services
|
|||||||
public static IServiceCollection AddAudioTranscoder(this IServiceCollection serviceDescriptors, IConfiguration configuration)
|
public static IServiceCollection AddAudioTranscoder(this IServiceCollection serviceDescriptors, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
serviceDescriptors
|
serviceDescriptors
|
||||||
.AddOptionsWithValidateOnStart<AudioTranscoderConfiguration>()
|
.AddOptionsWithValidateOnStart<AudioConfiguration>()
|
||||||
.Bind(configuration.GetRequiredSection(AudioTranscoderConfiguration.SectionName))
|
.Bind(configuration.GetRequiredSection(AudioConfiguration.SectionName))
|
||||||
.ValidateDataAnnotations();
|
.ValidateDataAnnotations();
|
||||||
|
|
||||||
serviceDescriptors.AddSingleton(serviceProvider =>
|
serviceDescriptors.AddSingleton(serviceProvider =>
|
||||||
serviceProvider.GetRequiredService<IOptions<AudioTranscoderConfiguration>>().Value);
|
serviceProvider.GetRequiredService<IOptions<AudioConfiguration>>().Value);
|
||||||
|
|
||||||
serviceDescriptors.AddScoped<IAudioTranscoderService, AudioTranscoderService>();
|
serviceDescriptors.AddScoped<IAudioTranscoderService, AudioService>();
|
||||||
return serviceDescriptors;
|
return serviceDescriptors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user