2025-02-13 19:10:25 -03:00
|
|
|
|
using AutoScan;
|
2025-02-15 15:55:29 -03:00
|
|
|
|
using AutoScan.Options;
|
2025-02-13 19:10:25 -03:00
|
|
|
|
using CasaBotApp;
|
2025-02-12 19:15:20 -03:00
|
|
|
|
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();
|
|
|
|
|
|
2025-02-14 20:32:04 -03:00
|
|
|
|
var services = new ServiceCollection();
|
2025-02-12 19:15:20 -03:00
|
|
|
|
|
2025-02-14 20:32:04 -03:00
|
|
|
|
services.AddSingleton(configuration);
|
|
|
|
|
services.AddLogging(builder =>
|
2025-02-12 19:15:20 -03:00
|
|
|
|
{
|
2025-02-13 19:10:25 -03:00
|
|
|
|
builder.AddConfiguration(configuration.GetSection("Logging"));
|
2025-02-14 20:32:04 -03:00
|
|
|
|
// builder.AddConsole();
|
|
|
|
|
//add time to logs
|
|
|
|
|
builder.AddSimpleConsole(options =>
|
|
|
|
|
{
|
|
|
|
|
options.IncludeScopes = true;
|
|
|
|
|
options.SingleLine = true;
|
|
|
|
|
options.TimestampFormat = "[HH:mm:ss] ";
|
|
|
|
|
});
|
2025-02-12 19:15:20 -03:00
|
|
|
|
});
|
2025-02-13 19:10:25 -03:00
|
|
|
|
|
2025-02-14 20:32:04 -03:00
|
|
|
|
services.Configure<TelegramOptions>(configuration.GetSection("Telegram"));
|
2025-02-15 15:55:29 -03:00
|
|
|
|
services.Configure<AutoScanOptions>(configuration.GetSection("AutoScan"));
|
|
|
|
|
services.Configure<ShinobiOptions>(configuration.GetSection("Shinobi"));
|
2025-02-14 20:32:04 -03:00
|
|
|
|
|
|
|
|
|
services.AddSingleton<BotHandler>();
|
2025-02-12 19:15:20 -03:00
|
|
|
|
|
2025-02-14 20:32:04 -03:00
|
|
|
|
services.AddAutoScan();
|
|
|
|
|
services.AddHttpClient();
|
|
|
|
|
|
|
|
|
|
var serviceProvider = services.BuildServiceProvider();
|
2025-02-12 19:15:20 -03:00
|
|
|
|
|
2025-02-13 19:10:25 -03:00
|
|
|
|
var logger = serviceProvider.GetService<ILogger<Program>>()!;
|
2025-02-12 19:15:20 -03:00
|
|
|
|
|
2025-02-13 19:10:25 -03:00
|
|
|
|
var botHandler = serviceProvider.GetService<BotHandler>()!;
|
2025-02-14 20:32:04 -03:00
|
|
|
|
var autoScanApp = serviceProvider.GetService<AutoScanApp>()!;
|
2025-02-12 19:15:20 -03:00
|
|
|
|
|
|
|
|
|
using var cts = new CancellationTokenSource();
|
|
|
|
|
|
2025-02-14 20:32:04 -03:00
|
|
|
|
autoScanApp.Run(cts.Token);
|
|
|
|
|
// botHandler.Start(cts.Token);
|
2025-02-12 19:15:20 -03:00
|
|
|
|
|
|
|
|
|
_ = SendMessageToSubscribers(cts.Token);
|
|
|
|
|
|
2025-02-14 20:32:04 -03:00
|
|
|
|
// var videoFileName = configuration.GetValue<string>("VideoFileName") ?? "video.mp4";
|
|
|
|
|
// if (configuration.GetValue<bool>("Fetch"))
|
|
|
|
|
// {
|
|
|
|
|
// var shinobiConnector = serviceProvider.GetService<ShinobiConnector>()!;
|
|
|
|
|
// await shinobiConnector.FetchLastVideo(videoFileName);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (configuration.GetValue<bool>("Scan"))
|
|
|
|
|
// {
|
|
|
|
|
// var dvrScanner = serviceProvider.GetService<DVRScanner>()!;
|
|
|
|
|
// await dvrScanner.ScanVideos(cts.Token);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if(configuration.GetValue<bool>("Screenshot"))
|
|
|
|
|
// {
|
|
|
|
|
// var detected = "2025-02-12T07-00-02.DSME_0001.avi";
|
|
|
|
|
// var ffmpegWrapper = serviceProvider.GetService<FfmpegWrapper>()!;
|
|
|
|
|
// 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);
|
|
|
|
|
// }
|
2025-02-12 19:15:20 -03:00
|
|
|
|
|
2025-02-13 19:10:25 -03:00
|
|
|
|
logger.LogInformation("Bot started");
|
|
|
|
|
logger.LogInformation("Press any key to stop the bot...");
|
2025-02-12 19:15:20 -03:00
|
|
|
|
Console.ReadLine();
|
|
|
|
|
cts.Cancel(); // stop the bot
|
2025-02-14 20:32:04 -03:00
|
|
|
|
|
2025-02-12 19:15:20 -03:00
|
|
|
|
return;
|
|
|
|
|
|
2025-02-12 19:22:18 -03:00
|
|
|
|
|
2025-02-12 19:15:20 -03:00
|
|
|
|
async Task SendMessageToSubscribers(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
while (!cancellationToken.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(TimeSpan.FromMinutes(1), cancellationToken);
|
|
|
|
|
botHandler.Update("Hello from CasaBot! at " + DateTime.Now);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|