Compare commits

..

No commits in common. "f94c6d5b2a2e248c27aece3d7695dc433b901a1b" and "7c213faa5f30bfc5aacfe3497d8f3f7f7d17af92" have entirely different histories.

6 changed files with 29 additions and 54 deletions

View File

@ -1,56 +1,46 @@
using AutoScan.Interfaces;
using AutoScan.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Diagnostics;
namespace AutoScan.Implementations;
public class DVRScanner : IDVRScanner
{
private readonly ILogger _logger;
private readonly AutoScanOptions _options;
private DateTime? _startedAt;
public DVRScanner(IOptionsSnapshot<AutoScanOptions> options, ILoggerFactory loggerFactory)
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)
{
_options = options.Value;
_logger = loggerFactory.CreateLogger(nameof(DVRScanner));
_logger = logger;
}
public async Task ScanVideos(CancellationToken cancellationToken = default)
{
if(_options.Scanner == null)
{
throw new ArgumentNullException(nameof(_options.Scanner));
}
try
{
//make sure the directory exists
Directory.CreateDirectory(Path.GetDirectoryName(_mediaPath)!);
_logger.LogDebug("Scanning videos...");
var folderParam = Path.Combine(_options.MediaFolder!, "*.mp4");
var arguments = $"-i {folderParam} -c {_options.Scanner.ConfigFile} --thumbnails highscore";
_logger.LogDebug("Executing command: {_dvrScannerFile} {arguments}", _options.Scanner.Exe, arguments);
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = _options.Scanner.Exe,
Arguments = arguments,
FileName = _dvrScannerFile,
Arguments = $"-i {_mediaPath}\\*.mp4 -c {_dvrScannerConfig}",
RedirectStandardOutput = true,
RedirectStandardError = false,
UseShellExecute = false,
CreateNoWindow = true,
}
};
if(_options.Scanner.RunDry)
{
_logger.LogInformation("Dry run enabled, skipping execution...");
return;
}
_startedAt = DateTime.Now;
process.Start();
process.PriorityClass = ProcessPriorityClass.High;
cancellationToken.Register(() =>
{
_logger.LogDebug("DVR Process status: ID: {Id}, HasExited: {HasExited}, Responding: {Responding}",
@ -62,8 +52,9 @@ public class DVRScanner : IDVRScanner
});
_logger.LogDebug("DVR Process started with ID: {Id}", process.Id);
await process.WaitForExitAsync(cancellationToken);
await UpdateProcessUntilExits(process, cancellationToken);
_logger.LogInformation("Videos scanned successfully!");
}
catch (Exception ex)
@ -71,17 +62,4 @@ public class DVRScanner : IDVRScanner
_logger.LogError(ex, "An error occurred while scanning the videos");
}
}
private async Task UpdateProcessUntilExits(Process process, CancellationToken cancellationToken = default)
{
while (!process.HasExited && !cancellationToken.IsCancellationRequested)
{
await Task.Delay(15000, cancellationToken);
var duration = DateTime.Now - _startedAt;
_logger.LogTrace("[{duration}] DVR Scan running", duration);
}
}
}

View File

@ -38,14 +38,15 @@ public class ShinobiConnector : IDVRConnector
_logger.LogInformation("Found {Count} videos in the specified range", response.videos.Count);
return response.videos.Select(video =>
foreach (var video in response.videos.OrderBy(x => x.time))
{
video.end = video.end.ToLocalTime();
video.time = video.time.ToLocalTime();
_logger.LogDebug("Video: {Filename} - Time: {time} - Ends: {end}", video.filename, video.time, video.end);
return video;
}).OrderBy(x => x.time).ToList();
}
return response.videos;
}
public async Task DownloadMonitorVideo(VideoDetail video, string downloadFolder, CancellationToken cancellationToken = default)

View File

@ -53,7 +53,7 @@ public class DownloaderJob : IJob
var videos = await _dvrConnector.FetchMonitorVideosBetween(from, to, context.CancellationToken);
//if the amount of videos is greater than the max amount in options, log a warning
if (_options.MaxAmount > 0 && videos.Count > _options.MaxAmount)
if (_options.MaxAmount > 0 && videos.Count > _options.MaxAmount)
{
_logger.LogWarning("Amount of videos fetched is greater than the max amount in options ({MaxAmount})", _options.MaxAmount);
videos = videos.Take(_options.MaxAmount).ToList();

View File

@ -16,9 +16,8 @@ public class ScannerJob : IJob
}
public Task Execute(IJobExecutionContext context)
{
_logger.LogWarning("ScannerJob is not implemented yet!");
_logger.LogInformation("Scanner {scannerName} is ready to scan!", _scanner.GetType().Name);
_scanner.ScanVideos();
return Task.CompletedTask;
}

View File

@ -5,5 +5,4 @@ public class ScannerOptions
public string? Exe { get; set; }
public string? ConfigFile { get; set; }
public string? DetectionFolder { get; set; }
public bool RunDry { get; set; } = false;
}

View File

@ -5,8 +5,7 @@
"System": "Information",
"Microsoft": "Information",
"Quartz": "Information",
"System.Net.Http.HttpClient": "Warning",
"DVRScanner": "Trace"
"System.Net.Http.HttpClient": "Warning"
}
},
"Telegram":{
@ -26,13 +25,12 @@
"FromDayBefore": true,
"From": "23:00",
"To": "05:00",
"MaxAmount": 2,
"MaxAmount": 1,
"MediaFolder": "./media/originals/",
"Scanner": {
"Exe": "./dvr-scanner/dvr-scan.exe",
"Exe": "./dvr-scanner/dvr.exe",
"ConfigFile": "./dvr-scanner/dvr-scan.cfg",
"DetectionFolder": "./media/detections/",
"RunDry": false
"DetectionFolder": "./media/detections/"
},
"Screenshot": {
"Folder": "./media/screenshots/",