using AutoScan; using CasaBotApp; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; // See https://aka.ms/new-console-template for more information var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); IConfigurationRoot configuration = new ConfigurationBuilder() .AddJsonFile($"appsettings.json", true, true) .AddJsonFile($"appsettings.{environment}.json", true, true) .AddEnvironmentVariables() .Build(); var services = new ServiceCollection(); services.AddSingleton(configuration); services.AddLogging(builder => { builder.AddConfiguration(configuration.GetSection("Logging")); // builder.AddConsole(); //add time to logs builder.AddSimpleConsole(options => { options.IncludeScopes = true; options.SingleLine = true; options.TimestampFormat = "[HH:mm:ss] "; }); }); services.Configure(configuration.GetSection("Telegram")); services.Configure(configuration.GetSection("AutoScan")); services.AddSingleton(); services.AddAutoScan(); services.AddHttpClient(); var serviceProvider = services.BuildServiceProvider(); var logger = serviceProvider.GetService>()!; var botHandler = serviceProvider.GetService()!; var autoScanApp = serviceProvider.GetService()!; using var cts = new CancellationTokenSource(); autoScanApp.Run(cts.Token); // botHandler.Start(cts.Token); _ = SendMessageToSubscribers(cts.Token); // var videoFileName = configuration.GetValue("VideoFileName") ?? "video.mp4"; // if (configuration.GetValue("Fetch")) // { // var shinobiConnector = serviceProvider.GetService()!; // await shinobiConnector.FetchLastVideo(videoFileName); // } // // if (configuration.GetValue("Scan")) // { // var dvrScanner = serviceProvider.GetService()!; // await dvrScanner.ScanVideos(cts.Token); // } // // if(configuration.GetValue("Screenshot")) // { // var detected = "2025-02-12T07-00-02.DSME_0001.avi"; // var ffmpegWrapper = serviceProvider.GetService()!; // var duration = await ffmpegWrapper.GetVideoDuration($@".\media\detected\{detected}"); // logger.LogInformation("Video duration: {Duration}", duration); // var middleTime = (duration / 2).Add(TimeSpan.FromSeconds(0.5)); // // //Extract frame at middle time // var screenshotPath = $@".\media\detected\{detected}-ss.png"; // await ffmpegWrapper.ExtractFrame($@".\media\detected\{detected}", screenshotPath, middleTime); // logger.LogInformation("Screenshot extracted at {MiddleTime}", middleTime); // // //botHandler.Subscribe(115151151); // await botHandler.UpdatePhoto(screenshotPath); // } logger.LogInformation("Bot started"); logger.LogInformation("Press any key to stop the bot..."); Console.ReadLine(); cts.Cancel(); // stop the bot return; async Task SendMessageToSubscribers(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { await Task.Delay(TimeSpan.FromMinutes(1), cancellationToken); botHandler.Update("Hello from CasaBot! at " + DateTime.Now); } }