fix: practice defense driving...seal it all

This commit is contained in:
Stevan Freeborn
2025-07-29 18:26:22 -05:00
parent 07190acb65
commit f6773cb64e
9 changed files with 30 additions and 9 deletions
@@ -1,6 +1,6 @@
namespace StreamShorts.Console.Commands;
internal class DefaultCommand(
internal sealed class DefaultCommand(
IFileSystem fileSystem,
IAnsiConsole console,
IAudioExtractor audioExtractor,
@@ -1,6 +1,6 @@
namespace StreamShorts.Console.Hosting;
internal class TypeRegistrar(IHostBuilder builder) : ITypeRegistrar
internal sealed class TypeRegistrar(IHostBuilder builder) : ITypeRegistrar
{
private readonly IHostBuilder _builder = builder;
@@ -1,6 +1,6 @@
namespace StreamShorts.Console.Hosting;
internal class TypeResolver(IHost provider) : ITypeResolver, IDisposable
internal sealed class TypeResolver(IHost provider) : ITypeResolver, IDisposable
{
private readonly IHost _host = provider ?? throw new ArgumentNullException(nameof(provider));
@@ -4,7 +4,7 @@ namespace StreamShorts.Library.Media.Audio;
/// Extracts audio from video files.
/// </summary>
/// <inheritdoc/>
public class AudioExtractor : IAudioExtractor
public sealed class AudioExtractor : IAudioExtractor
{
private readonly IVideoService _videoService = new FFMpegService();
@@ -1,15 +1,30 @@
namespace StreamShorts.Library.Media.Audio;
public class FailedAudioExtractionException : Exception
/// <summary>
/// Represents an error that occurs when audio extraction fails.
/// </summary>
public sealed class FailedAudioExtractionException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="FailedAudioExtractionException"/> class.
/// </summary>
public FailedAudioExtractionException() : base()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FailedAudioExtractionException"/> class with a specified error message.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
public FailedAudioExtractionException(string message) : base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FailedAudioExtractionException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception.</param>
public FailedAudioExtractionException(string message, Exception innerException) : base(message, innerException)
{
}
@@ -10,7 +10,7 @@ namespace StreamShorts.Library.Media;
/// Represents a service for processing video files using FFMpeg.
/// </summary>
/// <inheritdoc/>
internal class FFMpegService : IVideoService
internal sealed class FFMpegService : IVideoService
{
public async Task<bool> ExtractAudioFromVideoAsync(Stream video, Stream audio)
{
@@ -7,7 +7,7 @@ namespace StreamShorts.Library.Media;
/// Represents a service for processing audio files using NAudio.
/// </summary>
/// <inheritdoc/>
internal class NAudioService : IAudioService
internal sealed class NAudioService : IAudioService
{
public Stream ConvertMp3ToWav16(Stream mp3)
{
@@ -6,7 +6,7 @@ namespace StreamShorts.Library.Transcription;
/// <param name="StartTime">The start time of the segment.</param>
/// <param name="EndTime">The end time of the segment.</param>
/// <param name="Text">The transcribed text of the segment.</param>
public record TranscriptionSegment(
public sealed record TranscriptionSegment(
TimeSpan StartTime,
TimeSpan EndTime,
string Text
@@ -11,7 +11,7 @@ namespace StreamShorts.Library.Transcription;
/// Represents a transcriber that uses Whisper for audio transcription.
/// </summary>
/// <inheritdoc/>
public class WhisperTranscriber : ITranscriber
public sealed class WhisperTranscriber : ITranscriber, IDisposable
{
private readonly IAudioService _audioService = new NAudioService();
private WhisperProcessor? _whisperProcessor;
@@ -76,4 +76,10 @@ public class WhisperTranscriber : ITranscriber
yield return result;
}
}
public void Dispose()
{
_whisperProcessor?.Dispose();
_whisperProcessor = null;
}
}