feat: add DVR scanner (without dvr files) for detections

This commit is contained in:
Guillermo Marcel 2025-02-13 19:11:35 -03:00
parent da070f5e57
commit aa5c6d3f6d
2 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,64 @@
using Microsoft.Extensions.Logging;
using System.Diagnostics;
namespace CasaBotApp;
public class DVRScanner
{
private readonly ILogger<DVRScanner> _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<DVRScanner> 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");
}
}
}

View File

@ -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
}
}
}