2025-08-19 16:25:15 -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())
|
2025-08-19 12:43:34 -05:00
|
|
|
.ConfigureHostConfiguration(static config => config.AddJsonFile("appsettings.json"))
|
2025-07-23 23:55:56 -05:00
|
|
|
.ConfigureServices(static (_, services) =>
|
|
|
|
|
{
|
2025-08-12 00:17:37 -05:00
|
|
|
services.AddHttpClient();
|
2025-07-23 23:55:56 -05:00
|
|
|
services.AddSingleton(AnsiConsole.Console);
|
|
|
|
|
services.AddSingleton<IFileSystem, FileSystem>();
|
2025-08-12 00:17:37 -05:00
|
|
|
services.AddSingleton(TimeProvider.System);
|
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-08-12 00:17:37 -05:00
|
|
|
services.AddSingleton<ITranscriptAnalyzer, GeminiAnalyzer>(sp =>
|
|
|
|
|
{
|
2025-08-19 12:43:34 -05:00
|
|
|
const string modelOptionName = "Model";
|
|
|
|
|
const string keyOptionName = "ApiKey";
|
|
|
|
|
var config = sp.GetRequiredService<IConfiguration>();
|
|
|
|
|
var geminiSection = config.GetSection("Gemini");
|
|
|
|
|
var key = geminiSection[keyOptionName];
|
|
|
|
|
var model = geminiSection[modelOptionName];
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(key))
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException($"{keyOptionName} is not configured in appsettings.json.");
|
|
|
|
|
}
|
2025-08-19 16:25:15 -05:00
|
|
|
|
2025-08-12 00:17:37 -05:00
|
|
|
var clientFactory = sp.GetRequiredService<IHttpClientFactory>();
|
|
|
|
|
|
2025-08-19 12:43:34 -05:00
|
|
|
return new GeminiAnalyzer(clientFactory, key, model);
|
2025-08-12 00:17:37 -05:00
|
|
|
});
|
|
|
|
|
services.AddSingleton<IShortsCreator, ShortsCreator>();
|
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-08-19 16:25:15 -05:00
|
|
|
}
|