fix: practice defense driving...seal it all
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
namespace StreamShorts.Console.Commands;
|
namespace StreamShorts.Console.Commands;
|
||||||
|
|
||||||
internal class DefaultCommand(
|
internal sealed class DefaultCommand(
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
IAnsiConsole console,
|
IAnsiConsole console,
|
||||||
IAudioExtractor audioExtractor,
|
IAudioExtractor audioExtractor,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace StreamShorts.Console.Hosting;
|
namespace StreamShorts.Console.Hosting;
|
||||||
|
|
||||||
internal class TypeRegistrar(IHostBuilder builder) : ITypeRegistrar
|
internal sealed class TypeRegistrar(IHostBuilder builder) : ITypeRegistrar
|
||||||
{
|
{
|
||||||
private readonly IHostBuilder _builder = builder;
|
private readonly IHostBuilder _builder = builder;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace StreamShorts.Console.Hosting;
|
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));
|
private readonly IHost _host = provider ?? throw new ArgumentNullException(nameof(provider));
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace StreamShorts.Library.Media.Audio;
|
|||||||
/// Extracts audio from video files.
|
/// Extracts audio from video files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public class AudioExtractor : IAudioExtractor
|
public sealed class AudioExtractor : IAudioExtractor
|
||||||
{
|
{
|
||||||
private readonly IVideoService _videoService = new FFMpegService();
|
private readonly IVideoService _videoService = new FFMpegService();
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,30 @@
|
|||||||
namespace StreamShorts.Library.Media.Audio;
|
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()
|
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)
|
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)
|
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.
|
/// Represents a service for processing video files using FFMpeg.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
internal class FFMpegService : IVideoService
|
internal sealed class FFMpegService : IVideoService
|
||||||
{
|
{
|
||||||
public async Task<bool> ExtractAudioFromVideoAsync(Stream video, Stream audio)
|
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.
|
/// Represents a service for processing audio files using NAudio.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
internal class NAudioService : IAudioService
|
internal sealed class NAudioService : IAudioService
|
||||||
{
|
{
|
||||||
public Stream ConvertMp3ToWav16(Stream mp3)
|
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="StartTime">The start time of the segment.</param>
|
||||||
/// <param name="EndTime">The end 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>
|
/// <param name="Text">The transcribed text of the segment.</param>
|
||||||
public record TranscriptionSegment(
|
public sealed record TranscriptionSegment(
|
||||||
TimeSpan StartTime,
|
TimeSpan StartTime,
|
||||||
TimeSpan EndTime,
|
TimeSpan EndTime,
|
||||||
string Text
|
string Text
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace StreamShorts.Library.Transcription;
|
|||||||
/// Represents a transcriber that uses Whisper for audio transcription.
|
/// Represents a transcriber that uses Whisper for audio transcription.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public class WhisperTranscriber : ITranscriber
|
public sealed class WhisperTranscriber : ITranscriber, IDisposable
|
||||||
{
|
{
|
||||||
private readonly IAudioService _audioService = new NAudioService();
|
private readonly IAudioService _audioService = new NAudioService();
|
||||||
private WhisperProcessor? _whisperProcessor;
|
private WhisperProcessor? _whisperProcessor;
|
||||||
@@ -76,4 +76,10 @@ public class WhisperTranscriber : ITranscriber
|
|||||||
yield return result;
|
yield return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_whisperProcessor?.Dispose();
|
||||||
|
_whisperProcessor = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user