Compare commits
3 Commits
13d9bef207
...
620096a7b1
Author | SHA1 | Date | |
---|---|---|---|
620096a7b1 | |||
7b33a8043b | |||
35b42cc819 |
@ -102,7 +102,6 @@ public class AutoScanApp
|
|||||||
var path = Path.Combine(_options.Scanner.DetectionFolder, name + ".avi");
|
var path = Path.Combine(_options.Scanner.DetectionFolder, name + ".avi");
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
_logger.LogWarning("File {Path} does not exist", path);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
|
@ -68,6 +68,11 @@ public class DVRScanner : IDVRScanner
|
|||||||
await UpdateProcessUntilExits(process, cancellationToken);
|
await UpdateProcessUntilExits(process, cancellationToken);
|
||||||
_logger.LogInformation("Videos scanned successfully!");
|
_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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,8 @@ public class CleanJob : IJob
|
|||||||
public async Task Execute(IJobExecutionContext context)
|
public async Task Execute(IJobExecutionContext context)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Cleaning up files...");
|
_logger.LogInformation("Cleaning up files...");
|
||||||
|
_logger.LogInformation("RemoveOriginalFiles: {RemoveOriginalFiles}", _options.RemoveOriginalFiles);
|
||||||
|
_logger.LogInformation("RemoveDetectionFiles: {RemoveDetectionFiles}", _options.RemoveDetectionFiles);
|
||||||
if (_options.RemoveOriginalFiles)
|
if (_options.RemoveOriginalFiles)
|
||||||
{
|
{
|
||||||
CleanOriginalFiles();
|
CleanOriginalFiles();
|
||||||
@ -40,7 +42,7 @@ public class CleanJob : IJob
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
//remove .mp4 files from the media folder
|
//remove .mp4 files from the media folder
|
||||||
_logger.LogDebug("Removing .mp4 files from media folder {MediaFolder}", _options.MediaFolder);
|
_logger.LogInformation("Removing .mp4 files from media folder {MediaFolder}", _options.MediaFolder);
|
||||||
foreach (var file in Directory.GetFiles(_options.MediaFolder!, "*.mp4"))
|
foreach (var file in Directory.GetFiles(_options.MediaFolder!, "*.mp4"))
|
||||||
{
|
{
|
||||||
File.Delete(file);
|
File.Delete(file);
|
||||||
@ -55,7 +57,7 @@ public class CleanJob : IJob
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
//remove .avi files from the detection folder
|
//remove .avi files from the detection folder
|
||||||
_logger.LogDebug("Removing .avi files from detection folder {DetectionFolder}", _options.Scanner.DetectionFolder);
|
_logger.LogInformation("Removing .avi files from detection folder {DetectionFolder}", _options.Scanner.DetectionFolder);
|
||||||
foreach (var file in Directory.GetFiles(_options.Scanner!.DetectionFolder!, "*.avi"))
|
foreach (var file in Directory.GetFiles(_options.Scanner!.DetectionFolder!, "*.avi"))
|
||||||
{
|
{
|
||||||
File.Delete(file);
|
File.Delete(file);
|
||||||
|
@ -34,7 +34,7 @@ public class DownloaderJob : IJob
|
|||||||
return;
|
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
|
//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 now = DateTime.Now;
|
||||||
var minutes = _options.From.Split(":")[1];
|
var minutes = _options.From.Split(":")[1];
|
||||||
|
@ -73,7 +73,11 @@ public class BotHandler : IUpdateHandler
|
|||||||
_logger.LogInformation("User {Id} subscribed to receive messages", id);
|
_logger.LogInformation("User {Id} subscribed to receive messages", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Update(string message)
|
/// <summary>
|
||||||
|
/// Send text message to all subscribers
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
public async Task UpdateText(string message)
|
||||||
{
|
{
|
||||||
if (_subscribers.Count == 0)
|
if (_subscribers.Count == 0)
|
||||||
{
|
{
|
||||||
@ -99,7 +103,10 @@ public class BotHandler : IUpdateHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Send photo to all subscribers
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path"></param>
|
||||||
public async Task UpdatePhoto(string path)
|
public async Task UpdatePhoto(string path)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -116,20 +123,12 @@ 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)
|
public async Task UpdatePhotos(string[] paths)
|
||||||
{
|
{
|
||||||
if (_subscribers.Count == 0)
|
if (_subscribers.Count == 0)
|
||||||
@ -205,6 +204,19 @@ public class BotHandler : IUpdateHandler
|
|||||||
/// <param name="chatId"></param>
|
/// <param name="chatId"></param>
|
||||||
/// <param name="paths"></param>
|
/// <param name="paths"></param>
|
||||||
public async Task SendPhotos(long chatId, string[] paths)
|
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 streams = paths.Select(File.OpenRead).ToArray();
|
||||||
var photos = streams.Select(stream => new PhotoFile(stream)
|
var photos = streams.Select(stream => new PhotoFile(stream)
|
||||||
@ -226,6 +238,38 @@ 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)
|
private async Task OnMessage(TextMessage msg)
|
||||||
@ -306,4 +350,5 @@ public class BotHandler : IUpdateHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -53,7 +53,10 @@ public static class CommandRegister
|
|||||||
|
|
||||||
var videoPath = autoScanApp.GetVideoPath(photoMessage.Caption);
|
var videoPath = autoScanApp.GetVideoPath(photoMessage.Caption);
|
||||||
if (string.IsNullOrEmpty(videoPath))
|
if (string.IsNullOrEmpty(videoPath))
|
||||||
|
{
|
||||||
|
await botHandler.SendText(msg.Chat.Id, "No video found for this image");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await botHandler.SendVideo(msg.Chat.Id, videoPath);
|
await botHandler.SendVideo(msg.Chat.Id, videoPath);
|
||||||
};
|
};
|
||||||
@ -69,10 +72,10 @@ public static class CommandRegister
|
|||||||
var images = autoScanApp.GetLastScanPictures();
|
var images = autoScanApp.GetLastScanPictures();
|
||||||
if (images.Length == 0)
|
if (images.Length == 0)
|
||||||
{
|
{
|
||||||
await botHandler.Update("No images found");
|
await botHandler.UpdateText("No images found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await botHandler.Update($"Scan completed, found {images.Length} images");
|
await botHandler.UpdateText($"Scan completed, found {images.Length} images");
|
||||||
await botHandler.UpdatePhotos(images);
|
await botHandler.UpdatePhotos(images);
|
||||||
}catch(Exception ex)
|
}catch(Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -33,5 +33,7 @@
|
|||||||
"DetectionFolder": "./media/detections/",
|
"DetectionFolder": "./media/detections/",
|
||||||
"RunDry": false
|
"RunDry": false
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"RemoveOriginalFiles": true,
|
||||||
|
"RemoveDetectionFiles": false
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user