2025-07-29 18:00:09 -05:00
|
|
|
Log.Logger = new LoggerConfiguration()
|
2025-07-23 23:55:56 -05:00
|
|
|
.WriteTo.File(
|
|
|
|
|
formatter: new CompactJsonFormatter(),
|
|
|
|
|
path: Path.Combine(AppContext.BaseDirectory, "logs", "log.jsonl"),
|
|
|
|
|
rollingInterval: RollingInterval.Day
|
|
|
|
|
)
|
|
|
|
|
.Enrich.FromLogContext()
|
|
|
|
|
.MinimumLevel.Verbose()
|
|
|
|
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Fatal)
|
|
|
|
|
.CreateLogger();
|
2025-07-21 23:51:59 -05:00
|
|
|
|
2025-07-23 23:55:56 -05:00
|
|
|
try
|
2025-07-21 01:01:09 -05:00
|
|
|
{
|
2025-07-23 23:55:56 -05:00
|
|
|
var appName = Assembly.GetExecutingAssembly().GetName().Name;
|
|
|
|
|
Log.Information("Starting {AppName}", appName);
|
|
|
|
|
|
|
|
|
|
await Host.CreateDefaultBuilder(args)
|
|
|
|
|
.ConfigureLogging(static l => l.ClearProviders())
|
|
|
|
|
.ConfigureServices(static (_, services) =>
|
|
|
|
|
{
|
|
|
|
|
services.AddSingleton(AnsiConsole.Console);
|
|
|
|
|
services.AddSingleton<IFileSystem, FileSystem>();
|
2025-07-24 11:22:15 -05:00
|
|
|
services.AddSingleton<IAudioExtractor, AudioExtractor>();
|
2025-07-29 18:00:09 -05:00
|
|
|
services.AddSingleton<ITranscriber, WhisperTranscriber>();
|
2025-07-23 23:55:56 -05:00
|
|
|
})
|
|
|
|
|
.BuildApp()
|
|
|
|
|
.RunAsync(args);
|
|
|
|
|
|
|
|
|
|
Log.Information("{AppName} has completed successfully.", appName);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Fatal(ex, "An unhandled exception occurred during execution.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
await Log.CloseAndFlushAsync();
|
2025-07-21 01:01:09 -05:00
|
|
|
}
|
|
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// if (string.IsNullOrWhiteSpace(apiKey))
|
|
|
|
|
// {
|
|
|
|
|
// throw new InvalidOperationException("GeminiApiKey is not configured in appsettings.json.");
|
|
|
|
|
// }
|
2025-07-23 02:16:48 -05:00
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// using var client = new HttpClient()
|
|
|
|
|
// {
|
|
|
|
|
// Timeout = TimeSpan.FromMinutes(30)
|
|
|
|
|
// };
|
2025-07-23 02:16:48 -05:00
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// var requestUrl = $"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent?key={apiKey}";
|
|
|
|
|
// using var request = new HttpRequestMessage(HttpMethod.Post, requestUrl)
|
|
|
|
|
// {
|
|
|
|
|
// Content = new StringContent(
|
|
|
|
|
// JsonSerializer.Serialize(new
|
|
|
|
|
// {
|
|
|
|
|
// contents = new[]
|
|
|
|
|
// {
|
|
|
|
|
// new
|
|
|
|
|
// {
|
|
|
|
|
// role = "user",
|
|
|
|
|
// parts = new[]
|
|
|
|
|
// {
|
|
|
|
|
// new
|
|
|
|
|
// {
|
|
|
|
|
// text = prompt
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// generationConfig = new
|
|
|
|
|
// {
|
|
|
|
|
// responseMimeType = "application/json",
|
|
|
|
|
// }
|
|
|
|
|
// }),
|
|
|
|
|
// Encoding.UTF8,
|
|
|
|
|
// "application/json"
|
|
|
|
|
// )
|
|
|
|
|
// };
|
|
|
|
|
// var response = await client.SendAsync(request);
|
|
|
|
|
// var responseContent = await response.Content.ReadAsStringAsync();
|
|
|
|
|
// var responseJson = JsonSerializer.Deserialize<LLMResponse>(responseContent);
|
|
|
|
|
// var candidatesText = responseJson?
|
|
|
|
|
// .Candidates?
|
|
|
|
|
// .FirstOrDefault()?
|
|
|
|
|
// .Content
|
|
|
|
|
// .Parts?.FirstOrDefault()?
|
|
|
|
|
// .Text;
|
|
|
|
|
// var analysis = JsonSerializer.Deserialize<List<LLMAnalysis>>(candidatesText ?? string.Empty);
|
2025-07-21 23:51:59 -05:00
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// if (analysis is null)
|
|
|
|
|
// {
|
|
|
|
|
// Console.WriteLine(resourceManager.GetString("LLMAnalysisFailed", CultureInfo.CurrentCulture));
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2025-07-21 23:51:59 -05:00
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// foreach (var result in analysis)
|
|
|
|
|
// {
|
|
|
|
|
// var fileName = string.Concat(result.Title.Split(Path.GetInvalidFileNameChars()));
|
|
|
|
|
// await FFMpeg.SubVideoAsync(
|
|
|
|
|
// args[0],
|
|
|
|
|
// $"{fileName}.mp4",
|
|
|
|
|
// result.StartTime,
|
|
|
|
|
// result.EndTime
|
|
|
|
|
// );
|
|
|
|
|
// }
|
2025-07-21 23:51:59 -05:00
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// // Step 6: Use analysis to generate a short video
|
2025-07-21 23:51:59 -05:00
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// record LLMAnalysis(
|
|
|
|
|
// [property: JsonPropertyName("title")]
|
|
|
|
|
// string Title,
|
|
|
|
|
// [property: JsonPropertyName("description")]
|
|
|
|
|
// string Description,
|
|
|
|
|
// [property: JsonPropertyName("explanation")]
|
|
|
|
|
// string Explanation,
|
|
|
|
|
// [property: JsonPropertyName("start_time")]
|
|
|
|
|
// TimeSpan StartTime,
|
|
|
|
|
// [property: JsonPropertyName("end_time")]
|
|
|
|
|
// TimeSpan EndTime
|
|
|
|
|
// );
|
2025-07-21 23:51:59 -05:00
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// record LLMResponse(
|
|
|
|
|
// [property: JsonPropertyName("candidates")]
|
|
|
|
|
// Candidate[] Candidates
|
|
|
|
|
// );
|
2025-07-23 02:16:48 -05:00
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// record Candidate(
|
|
|
|
|
// [property: JsonPropertyName("content")]
|
|
|
|
|
// Content Content
|
|
|
|
|
// );
|
2025-07-23 02:16:48 -05:00
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// record Content(
|
|
|
|
|
// [property: JsonPropertyName("parts")]
|
|
|
|
|
// Part[] Parts
|
|
|
|
|
// );
|
2025-07-23 02:16:48 -05:00
|
|
|
|
2025-07-24 11:22:15 -05:00
|
|
|
// record Part(
|
|
|
|
|
// [property: JsonPropertyName("text")]
|
|
|
|
|
// string Text
|
|
|
|
|
// );
|