From aa5c6d3f6d9f9a51fe62d3502b2207682c3018d5 Mon Sep 17 00:00:00 2001 From: Guillermo Marcel Date: Thu, 13 Feb 2025 19:11:35 -0300 Subject: [PATCH] feat: add DVR scanner (without dvr files) for detections --- src/CasaBot/CasaBotApp/DVRScanner.cs | 64 +++++++++++++++++++++++++ src/CasaBot/CasaBotApp/appsettings.json | 33 +++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/CasaBot/CasaBotApp/DVRScanner.cs create mode 100644 src/CasaBot/CasaBotApp/appsettings.json diff --git a/src/CasaBot/CasaBotApp/DVRScanner.cs b/src/CasaBot/CasaBotApp/DVRScanner.cs new file mode 100644 index 0000000..a7caf3b --- /dev/null +++ b/src/CasaBot/CasaBotApp/DVRScanner.cs @@ -0,0 +1,64 @@ +using Microsoft.Extensions.Logging; +using System.Diagnostics; + +namespace CasaBotApp; + +public class DVRScanner +{ + private readonly ILogger _logger; + private const string _mediaPath = @".\media"; // Replace with your desired file path + private const string _dvrScannerFile = @".\dvr-scanner\dvr-scan.exe"; + private const string _dvrScannerConfig = @".\dvr-scanner\dvr-scan.cfg"; + + //.\dvr-scanner\dvr-scan.exe -i .\media\*.mp4 -c .\dvr-scanner\dvr-scan.cfg + public DVRScanner(ILogger logger) + { + _logger = logger; + } + + public async Task ScanVideos(CancellationToken cancellationToken = default) + { + try + { + //make sure the directory exists + Directory.CreateDirectory(Path.GetDirectoryName(_mediaPath)!); + + + _logger.LogDebug("Scanning videos..."); + var process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = _dvrScannerFile, + Arguments = $"-i {_mediaPath}\\*.mp4 -c {_dvrScannerConfig}", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + + + + } + }; + process.Start(); + cancellationToken.Register(() => + { + _logger.LogDebug("DVR Process status: ID: {Id}, HasExited: {HasExited}, Responding: {Responding}", + process.Id, process.HasExited, process.Responding); + if(process.HasExited) return; + + _logger.LogWarning("DVR Process is still running, killing it..."); + process.Kill(); + }); + + _logger.LogDebug("DVR Process started with ID: {Id}", process.Id); + await process.WaitForExitAsync(cancellationToken); + + + _logger.LogInformation("Videos scanned successfully!"); + } + catch (Exception ex) + { + _logger.LogError(ex, "An error occurred while scanning the videos"); + } + } +} \ No newline at end of file diff --git a/src/CasaBot/CasaBotApp/appsettings.json b/src/CasaBot/CasaBotApp/appsettings.json new file mode 100644 index 0000000..d1fac61 --- /dev/null +++ b/src/CasaBot/CasaBotApp/appsettings.json @@ -0,0 +1,33 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + }, + "AutoScan": { + "Enabled": false, + "At": "07:00", + "FromDayBefore": true, + "From": "23:00", + "To": "05:00", + "MaxAmount": 1, + "MediaFolder": "./media/originals", + "Shinobi": { + "URL": "http://localhost:8080", + "APIKey": "APIKEY", + "GroupId": "Group", + "MonitorId": "Monitor" + }, + "Scanner": { + "Exe": "./dvr-scanner/dvr.exe", + "ConfigFile": "./dvr-scanner/dvr-scan.cfg", + "DetectionFolder": "./media/detections" + }, + "Screenshot": { + "Folder": "./media/screenshots", + "OffsetSeconds": 0 + } + } +} \ No newline at end of file