Compare commits

..

No commits in common. "620096a7b106ffcd89ec390329e92d2422e1a818" and "13d9bef20742f0673d1b88e352810efe4f8f4be9" have entirely different histories.

7 changed files with 22 additions and 78 deletions

View File

@ -102,6 +102,7 @@ public class AutoScanApp
var path = Path.Combine(_options.Scanner.DetectionFolder, name + ".avi");
if (!File.Exists(path))
{
_logger.LogWarning("File {Path} does not exist", path);
return null;
}
return path;

View File

@ -68,11 +68,6 @@ public class DVRScanner : IDVRScanner
await UpdateProcessUntilExits(process, cancellationToken);
_logger.LogInformation("Videos scanned successfully!");
//Count the number of .avi files and .jpg files in the detection folder
var aviFiles = Directory.GetFiles(_options.Scanner.DetectionFolder!, "*.avi");
var jpgFiles = Directory.GetFiles(_options.Scanner.DetectionFolder!, "*.jpg");
_logger.LogInformation("Found {AviCount} .avi files and {JpgCount} .jpg files in the detection folder", aviFiles.Length, jpgFiles.Length);
}
catch (Exception ex)
{

View File

@ -19,8 +19,6 @@ public class CleanJob : IJob
public async Task Execute(IJobExecutionContext context)
{
_logger.LogInformation("Cleaning up files...");
_logger.LogInformation("RemoveOriginalFiles: {RemoveOriginalFiles}", _options.RemoveOriginalFiles);
_logger.LogInformation("RemoveDetectionFiles: {RemoveDetectionFiles}", _options.RemoveDetectionFiles);
if (_options.RemoveOriginalFiles)
{
CleanOriginalFiles();
@ -42,7 +40,7 @@ public class CleanJob : IJob
return;
//remove .mp4 files from the media folder
_logger.LogInformation("Removing .mp4 files from media folder {MediaFolder}", _options.MediaFolder);
_logger.LogDebug("Removing .mp4 files from media folder {MediaFolder}", _options.MediaFolder);
foreach (var file in Directory.GetFiles(_options.MediaFolder!, "*.mp4"))
{
File.Delete(file);
@ -57,7 +55,7 @@ public class CleanJob : IJob
return;
//remove .avi files from the detection folder
_logger.LogInformation("Removing .avi files from detection folder {DetectionFolder}", _options.Scanner.DetectionFolder);
_logger.LogDebug("Removing .avi files from detection folder {DetectionFolder}", _options.Scanner.DetectionFolder);
foreach (var file in Directory.GetFiles(_options.Scanner!.DetectionFolder!, "*.avi"))
{
File.Delete(file);

View File

@ -34,7 +34,7 @@ public class DownloaderJob : IJob
return;
}
//time to start retrieving videos,
//time to start retrieving videos
//for example, if options.From is 23:00 and options.FromDayBefore is true, from should be yesterday at 23:00
var now = DateTime.Now;
var minutes = _options.From.Split(":")[1];

View File

@ -73,11 +73,7 @@ public class BotHandler : IUpdateHandler
_logger.LogInformation("User {Id} subscribed to receive messages", id);
}
/// <summary>
/// Send text message to all subscribers
/// </summary>
/// <param name="message"></param>
public async Task UpdateText(string message)
public async Task Update(string message)
{
if (_subscribers.Count == 0)
{
@ -103,10 +99,7 @@ public class BotHandler : IUpdateHandler
}
/// <summary>
/// Send photo to all subscribers
/// </summary>
/// <param name="path"></param>
public async Task UpdatePhoto(string path)
{
@ -123,12 +116,20 @@ public class BotHandler : IUpdateHandler
}
}
public async Task SendVideo(long chatId, string path)
{
_logger.LogInformation("Sending video to {ChatId}", chatId);
await using var stream = File.OpenRead(path);
var send = new SendVideoFile(chatId.ToString(), stream);
var response = await _bot.HandleAsync(send);
if (!response.Ok)
{
_logger.LogError("Error sending video.");
}
_logger.LogInformation("Video sent to {ChatId}", chatId);
stream.Close();
}
/// <summary>
/// Send photos to all subscribers
/// </summary>
/// <param name="paths"></param>
public async Task UpdatePhotos(string[] paths)
{
if (_subscribers.Count == 0)
@ -204,19 +205,6 @@ public class BotHandler : IUpdateHandler
/// <param name="chatId"></param>
/// <param name="paths"></param>
public async Task SendPhotos(long chatId, string[] paths)
{
var groups = paths.Select((x, i) => (x, i))
.GroupBy(x => x.i / 10)
.Select(x => x.Select(y => y.x).ToArray())
.ToArray();
foreach(var group in groups)
{
await SendPhotosInt(chatId, group);
}
}
private async Task SendPhotosInt(long chatId, string[] paths)
{
var streams = paths.Select(File.OpenRead).ToArray();
var photos = streams.Select(stream => new PhotoFile(stream)
@ -238,38 +226,6 @@ public class BotHandler : IUpdateHandler
}
}
/// <summary>
/// Send Text Message to a specific chat
/// </summary>
/// <param name="chatId"></param>
/// <param name="textMessage"></param>
public async Task SendText(long chatId, string textMessage)
{
var response = await SndTxt(chatId, textMessage);
if (!response.Ok)
{
_logger.LogError("Error sending message to {ChatId}", chatId);
}
}
/// <summary>
/// Send single video to a specific chat
/// </summary>
/// <param name="chatId"></param>
/// <param name="path"></param>
public async Task SendVideo(long chatId, string path)
{
_logger.LogInformation("Sending video to {ChatId}", chatId);
await using var stream = File.OpenRead(path);
var send = new SendVideoFile(chatId.ToString(), stream);
var response = await _bot.HandleAsync(send);
if (!response.Ok)
{
_logger.LogError("Error sending video.");
}
_logger.LogInformation("Video sent to {ChatId}", chatId);
stream.Close();
}
private async Task OnMessage(TextMessage msg)
@ -350,5 +306,4 @@ public class BotHandler : IUpdateHandler
}
}
}

View File

@ -53,10 +53,7 @@ public static class CommandRegister
var videoPath = autoScanApp.GetVideoPath(photoMessage.Caption);
if (string.IsNullOrEmpty(videoPath))
{
await botHandler.SendText(msg.Chat.Id, "No video found for this image");
return;
}
await botHandler.SendVideo(msg.Chat.Id, videoPath);
};
@ -72,10 +69,10 @@ public static class CommandRegister
var images = autoScanApp.GetLastScanPictures();
if (images.Length == 0)
{
await botHandler.UpdateText("No images found");
await botHandler.Update("No images found");
return;
}
await botHandler.UpdateText($"Scan completed, found {images.Length} images");
await botHandler.Update($"Scan completed, found {images.Length} images");
await botHandler.UpdatePhotos(images);
}catch(Exception ex)
{

View File

@ -33,7 +33,5 @@
"DetectionFolder": "./media/detections/",
"RunDry": false
}
},
"RemoveOriginalFiles": true,
"RemoveDetectionFiles": false
}
}