📄 src/Cli/Program.cs
using System;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Slopper.Cli;
using Slopper.Cli.YouTubeAuth;
using Slopper.Domain;
using Slopper.Domain.Describer;
using Slopper.Infrastructure.Ai;
using Slopper.Infrastructure.Database;
using Slopper.Infrastructure.Ffmpeg;
using Slopper.Infrastructure.YouTube;

var builder = Host.CreateApplicationBuilder();

builder.ConfigureOpenTelemetry();

builder.Services.AddClipSelector().AddClipGenerator().AddCleaner();

builder.Services.AddJellyfinDatabase().AddSlopperDatabase().AddFfmpegServices().AddAi().AddYouTubeUploader();

builder.Services.AddYouTubeAuth();

using var app = builder.Build();

await app.StartAsync();

var lifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();
var logger = app.Services.GetRequiredService<ILogger<Program>>();

using var scope = app.Services.CreateScope();
var timeProvider = scope.ServiceProvider.GetRequiredService<TimeProvider>();
var clipDescriber = scope.ServiceProvider.GetRequiredService<ClipDescriber>();

var utcNow = timeProvider.GetUtcNow();
var media = new MediaItem(Guid.Parse(args[0]), args[1], new Subtitles.Embedded(int.Parse(args[2])));

var start = TimeSpan.Parse(args[3]);
var duration = TimeSpan.Parse(args[4]);

var description = await clipDescriber.DescribeClip(media, start, duration, lifetime.ApplicationStopping);

logger.LogInformation("Description: {Caption} ({Tags})", description.Caption, description.Tags.Select(t => t.Value));

await app.StopAsync();