chore: lots of chores
This commit is contained in:
@@ -28,4 +28,4 @@ public sealed class FailedTranscriptAnalysisException : Exception
|
||||
public FailedTranscriptAnalysisException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// Represents content with role and parts for Gemini API.
|
||||
/// </summary>
|
||||
/// <param name="Role">The role of the content (e.g., "user", "assistant").</param>
|
||||
/// <param name="Parts">The array of content parts.</param>
|
||||
internal record Content(
|
||||
[property: JsonPropertyName("role")]
|
||||
string Role,
|
||||
@@ -7,6 +12,10 @@ internal record Content(
|
||||
Part[] Parts
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Represents a part of content for Gemini API.
|
||||
/// </summary>
|
||||
/// <param name="Text">The text content of the part.</param>
|
||||
internal record Part(
|
||||
[property: JsonPropertyName("text")]
|
||||
string Text
|
||||
|
||||
@@ -2,6 +2,11 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace StreamShorts.Library.Analysis.Gemini;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to generate content using Gemini.
|
||||
/// </summary>
|
||||
/// <param name="Contents">The content array for the request.</param>
|
||||
/// <param name="GenerationConfig">The generation configuration.</param>
|
||||
internal record GenerateContentRequest(
|
||||
[property: JsonPropertyName("contents")]
|
||||
Content[] Contents,
|
||||
@@ -9,6 +14,10 @@ internal record GenerateContentRequest(
|
||||
GenerationConfig GenerationConfig
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Represents configuration for content generation.
|
||||
/// </summary>
|
||||
/// <param name="ResponseMimeType">The MIME type for the response.</param>
|
||||
internal record GenerationConfig(
|
||||
[property: JsonPropertyName("responseMimeType")]
|
||||
string ResponseMimeType
|
||||
|
||||
@@ -2,13 +2,20 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace StreamShorts.Library.Analysis.Gemini;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a response from the Gemini content generation API.
|
||||
/// </summary>
|
||||
/// <param name="Candidates">The array of candidate responses.</param>
|
||||
internal record GenerateContentResponse(
|
||||
[property: JsonPropertyName("candidates")]
|
||||
Candidate[] Candidates
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Represents a candidate response from content generation.
|
||||
/// </summary>
|
||||
/// <param name="Content">The generated content.</param>
|
||||
internal record Candidate(
|
||||
[property: JsonPropertyName("content")]
|
||||
Content Content
|
||||
);
|
||||
|
||||
);
|
||||
@@ -16,4 +16,4 @@ public record ShortCandidate(
|
||||
TimeSpan StartTime,
|
||||
[property: JsonPropertyName("end_time")]
|
||||
TimeSpan EndTime
|
||||
);
|
||||
);
|
||||
@@ -16,10 +16,10 @@ public sealed class AudioExtractor : IAudioExtractor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AudioExtractor"/> class with a specified FFMpeg service.
|
||||
/// Initializes a new instance of the <see cref="AudioExtractor"/> class with a specified <see cref="IVideoService"/>.
|
||||
/// </summary>
|
||||
/// <param name="videoService">The video service to use for audio extraction.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the FFMpeg service is null.</exception>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the video service is null.</exception>
|
||||
internal AudioExtractor(IVideoService videoService)
|
||||
{
|
||||
_videoService = videoService ?? throw new ArgumentNullException(nameof(videoService), $"{nameof(videoService)} cannot be null");
|
||||
|
||||
@@ -23,8 +23,8 @@ internal sealed class FFMpegService : IVideoService
|
||||
}
|
||||
|
||||
public async Task CreateClipFromVideoAsync(
|
||||
string sourcePath,
|
||||
string destinationPath,
|
||||
string sourcePath,
|
||||
string destinationPath,
|
||||
TimeSpan startTime,
|
||||
TimeSpan endTime,
|
||||
TimeSpan? buffer = null
|
||||
@@ -32,7 +32,7 @@ internal sealed class FFMpegService : IVideoService
|
||||
{
|
||||
var start = startTime - (buffer ?? TimeSpan.Zero);
|
||||
var end = endTime + (buffer ?? TimeSpan.Zero);
|
||||
|
||||
|
||||
await FFMpeg.SubVideoAsync(sourcePath, destinationPath, start, end)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ internal interface IVideoService
|
||||
/// <param name="audio">The output audio stream.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result indicates whether the extraction was successful.</returns>
|
||||
Task<bool> ExtractAudioFromVideoAsync(Stream video, Stream audio);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a clip from a video file based on the specified start and end times.
|
||||
/// </summary>
|
||||
|
||||
@@ -6,14 +6,22 @@ namespace StreamShorts.Library.Media.Video;
|
||||
/// Represents a service that creates video shorts.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public class ShortsCreator : IShortsCreator
|
||||
public sealed class ShortsCreator : IShortsCreator
|
||||
{
|
||||
private readonly IVideoService _videoService = new FFMpegService();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ShortsCreator"/> class.
|
||||
/// </summary>
|
||||
public ShortsCreator()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ShortsCreator"/> class with a specified <see cref="IVideoService"/>.
|
||||
/// </summary>
|
||||
/// <param name="videoService">The video service.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the video service is null.</exception>
|
||||
internal ShortsCreator(IVideoService videoService)
|
||||
{
|
||||
_videoService = videoService ?? throw new ArgumentNullException(nameof(videoService), $"{nameof(videoService)} cannot be null");
|
||||
@@ -25,17 +33,17 @@ public class ShortsCreator : IShortsCreator
|
||||
{
|
||||
throw new ArgumentNullException(nameof(sourcePath), $"{nameof(sourcePath)} cannot be null or whitespace");
|
||||
}
|
||||
|
||||
|
||||
if (candidate is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(candidate), $"{nameof(candidate)} cannot be null");
|
||||
}
|
||||
|
||||
|
||||
if (string.IsNullOrWhiteSpace(destinationPath))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(destinationPath), $"{nameof(destinationPath)} cannot be null or whitespace");
|
||||
}
|
||||
|
||||
|
||||
await _videoService.CreateClipFromVideoAsync(sourcePath, destinationPath, candidate.StartTime, candidate.EndTime, buffer)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -12,4 +12,4 @@ public interface ITranscriber
|
||||
/// <param name="cancellationToken">A cancellation token to cancel the operation.</param>
|
||||
/// <returns>An <see cref="IAsyncEnumerable{T}"/> where T is <see cref="TranscriptionSegment"/>.</returns>
|
||||
IAsyncEnumerable<TranscriptionSegment> TranscribeAsync(Stream audio, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user