Compare commits
No commits in common. "620096a7b106ffcd89ec390329e92d2422e1a818" and "13d9bef20742f0673d1b88e352810efe4f8f4be9" have entirely different histories.
620096a7b1
...
13d9bef207
@ -102,6 +102,7 @@ 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,11 +68,6 @@ 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,8 +19,6 @@ 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();
|
||||||
@ -42,7 +40,7 @@ public class CleanJob : IJob
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
//remove .mp4 files from the media folder
|
//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"))
|
foreach (var file in Directory.GetFiles(_options.MediaFolder!, "*.mp4"))
|
||||||
{
|
{
|
||||||
File.Delete(file);
|
File.Delete(file);
|
||||||
@ -57,7 +55,7 @@ public class CleanJob : IJob
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
//remove .avi files from the detection folder
|
//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"))
|
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,11 +73,7 @@ public class BotHandler : IUpdateHandler
|
|||||||
_logger.LogInformation("User {Id} subscribed to receive messages", id);
|
_logger.LogInformation("User {Id} subscribed to receive messages", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public async Task Update(string message)
|
||||||
/// 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)
|
||||||
{
|
{
|
||||||
@ -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)
|
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)
|
public async Task UpdatePhotos(string[] paths)
|
||||||
{
|
{
|
||||||
if (_subscribers.Count == 0)
|
if (_subscribers.Count == 0)
|
||||||
@ -204,19 +205,6 @@ 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)
|
||||||
@ -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)
|
private async Task OnMessage(TextMessage msg)
|
||||||
@ -350,5 +306,4 @@ public class BotHandler : IUpdateHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -53,10 +53,7 @@ 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);
|
||||||
};
|
};
|
||||||
@ -72,10 +69,10 @@ public static class CommandRegister
|
|||||||
var images = autoScanApp.GetLastScanPictures();
|
var images = autoScanApp.GetLastScanPictures();
|
||||||
if (images.Length == 0)
|
if (images.Length == 0)
|
||||||
{
|
{
|
||||||
await botHandler.UpdateText("No images found");
|
await botHandler.Update("No images found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await botHandler.UpdateText($"Scan completed, found {images.Length} images");
|
await botHandler.Update($"Scan completed, found {images.Length} images");
|
||||||
await botHandler.UpdatePhotos(images);
|
await botHandler.UpdatePhotos(images);
|
||||||
}catch(Exception ex)
|
}catch(Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,5 @@
|
|||||||
"DetectionFolder": "./media/detections/",
|
"DetectionFolder": "./media/detections/",
|
||||||
"RunDry": false
|
"RunDry": false
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"RemoveOriginalFiles": true,
|
|
||||||
"RemoveDetectionFiles": false
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user