From f6773cb64ef399c4ec1ea2e6aac0305c207f59d9 Mon Sep 17 00:00:00 2001
From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com>
Date: Tue, 29 Jul 2025 18:26:22 -0500
Subject: [PATCH] fix: practice defense driving...seal it all
---
.../Commands/DefaultCommand.cs | 2 +-
.../Hosting/TypeRegistrar.cs | 2 +-
.../Hosting/TypeResolver.cs | 2 +-
.../Media/Audio/AudioExtractor.cs | 2 +-
.../Audio/FailedAudioExtractionException.cs | 17 ++++++++++++++++-
src/StreamShorts.Library/Media/FFMpegService.cs | 2 +-
src/StreamShorts.Library/Media/NAudioService.cs | 2 +-
.../Transcription/TranscriptionSegment.cs | 2 +-
.../Transcription/WhisperTranscriber.cs | 8 +++++++-
9 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/src/StreamShorts.Console/Commands/DefaultCommand.cs b/src/StreamShorts.Console/Commands/DefaultCommand.cs
index 3780956..1b5e5a4 100644
--- a/src/StreamShorts.Console/Commands/DefaultCommand.cs
+++ b/src/StreamShorts.Console/Commands/DefaultCommand.cs
@@ -1,6 +1,6 @@
namespace StreamShorts.Console.Commands;
-internal class DefaultCommand(
+internal sealed class DefaultCommand(
IFileSystem fileSystem,
IAnsiConsole console,
IAudioExtractor audioExtractor,
diff --git a/src/StreamShorts.Console/Hosting/TypeRegistrar.cs b/src/StreamShorts.Console/Hosting/TypeRegistrar.cs
index 50ab983..e8bf08d 100644
--- a/src/StreamShorts.Console/Hosting/TypeRegistrar.cs
+++ b/src/StreamShorts.Console/Hosting/TypeRegistrar.cs
@@ -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;
diff --git a/src/StreamShorts.Console/Hosting/TypeResolver.cs b/src/StreamShorts.Console/Hosting/TypeResolver.cs
index afbb21b..ae3ac08 100644
--- a/src/StreamShorts.Console/Hosting/TypeResolver.cs
+++ b/src/StreamShorts.Console/Hosting/TypeResolver.cs
@@ -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));
diff --git a/src/StreamShorts.Library/Media/Audio/AudioExtractor.cs b/src/StreamShorts.Library/Media/Audio/AudioExtractor.cs
index 19c1f07..cd9d7d3 100644
--- a/src/StreamShorts.Library/Media/Audio/AudioExtractor.cs
+++ b/src/StreamShorts.Library/Media/Audio/AudioExtractor.cs
@@ -4,7 +4,7 @@ namespace StreamShorts.Library.Media.Audio;
/// Extracts audio from video files.
///
///
-public class AudioExtractor : IAudioExtractor
+public sealed class AudioExtractor : IAudioExtractor
{
private readonly IVideoService _videoService = new FFMpegService();
diff --git a/src/StreamShorts.Library/Media/Audio/FailedAudioExtractionException.cs b/src/StreamShorts.Library/Media/Audio/FailedAudioExtractionException.cs
index 25e57ec..cd302bd 100644
--- a/src/StreamShorts.Library/Media/Audio/FailedAudioExtractionException.cs
+++ b/src/StreamShorts.Library/Media/Audio/FailedAudioExtractionException.cs
@@ -1,15 +1,30 @@
namespace StreamShorts.Library.Media.Audio;
-public class FailedAudioExtractionException : Exception
+///
+/// Represents an error that occurs when audio extraction fails.
+///
+public sealed class FailedAudioExtractionException : Exception
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
public FailedAudioExtractionException() : base()
{
}
+ ///
+ /// Initializes a new instance of the class with a specified error message.
+ ///
+ /// The error message that explains the reason for the exception.
public FailedAudioExtractionException(string message) : base(message)
{
}
+ ///
+ /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.
+ ///
+ /// The error message that explains the reason for the exception.
+ /// The exception that is the cause of the current exception.
public FailedAudioExtractionException(string message, Exception innerException) : base(message, innerException)
{
}
diff --git a/src/StreamShorts.Library/Media/FFMpegService.cs b/src/StreamShorts.Library/Media/FFMpegService.cs
index 5c12006..3c7411a 100644
--- a/src/StreamShorts.Library/Media/FFMpegService.cs
+++ b/src/StreamShorts.Library/Media/FFMpegService.cs
@@ -10,7 +10,7 @@ namespace StreamShorts.Library.Media;
/// Represents a service for processing video files using FFMpeg.
///
///
-internal class FFMpegService : IVideoService
+internal sealed class FFMpegService : IVideoService
{
public async Task ExtractAudioFromVideoAsync(Stream video, Stream audio)
{
diff --git a/src/StreamShorts.Library/Media/NAudioService.cs b/src/StreamShorts.Library/Media/NAudioService.cs
index 431ef32..89aa733 100644
--- a/src/StreamShorts.Library/Media/NAudioService.cs
+++ b/src/StreamShorts.Library/Media/NAudioService.cs
@@ -7,7 +7,7 @@ namespace StreamShorts.Library.Media;
/// Represents a service for processing audio files using NAudio.
///
///
-internal class NAudioService : IAudioService
+internal sealed class NAudioService : IAudioService
{
public Stream ConvertMp3ToWav16(Stream mp3)
{
diff --git a/src/StreamShorts.Library/Transcription/TranscriptionSegment.cs b/src/StreamShorts.Library/Transcription/TranscriptionSegment.cs
index bd5a232..5ea5020 100644
--- a/src/StreamShorts.Library/Transcription/TranscriptionSegment.cs
+++ b/src/StreamShorts.Library/Transcription/TranscriptionSegment.cs
@@ -6,7 +6,7 @@ namespace StreamShorts.Library.Transcription;
/// The start time of the segment.
/// The end time of the segment.
/// The transcribed text of the segment.
-public record TranscriptionSegment(
+public sealed record TranscriptionSegment(
TimeSpan StartTime,
TimeSpan EndTime,
string Text
diff --git a/src/StreamShorts.Library/Transcription/WhisperTranscriber.cs b/src/StreamShorts.Library/Transcription/WhisperTranscriber.cs
index f264df5..577f0af 100644
--- a/src/StreamShorts.Library/Transcription/WhisperTranscriber.cs
+++ b/src/StreamShorts.Library/Transcription/WhisperTranscriber.cs
@@ -11,7 +11,7 @@ namespace StreamShorts.Library.Transcription;
/// Represents a transcriber that uses Whisper for audio transcription.
///
///
-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;
+ }
}
\ No newline at end of file