📄
src/Cli/Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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.Infrastructure.Ai; using Slopper.Infrastructure.Database; using Slopper.Infrastructure.Ffmpeg; using Slopper.Infrastructure.YouTube; var builder = Host.CreateApplicationBuilder(); builder.ConfigureOpenTelemetry(); builder.Services.AddClipSelector().AddClipGenerator(); 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 clipRepository = scope.ServiceProvider.GetRequiredService<IClipRepository>(); var clip = await clipRepository .GetLatest(limit: 1, cancellationToken: lifetime.ApplicationStopping) .FirstOrDefaultAsync(lifetime.ApplicationStopping); if (clip is null) { logger.LogInformation("No clips in repository"); return; } logger.LogInformation("Uploading {ClipId}", clip.Id); var youTubeUploader = app.Services.GetRequiredKeyedService<IUploader>("YouTube"); var upload = await youTubeUploader.Upload(clip, lifetime.ApplicationStopping); logger.LogInformation("Clip uploaded at {Url}", upload.CanonicalUrl); await app.StopAsync();