From efe2e28d68fca74ee1ae756300a27c4ed5ff8a83 Mon Sep 17 00:00:00 2001 From: Marcos Cordeiro Date: Thu, 9 Nov 2023 20:06:43 -0300 Subject: [PATCH] Adds downloaded files to integrity check queue --- Wasari.Daemon/Handlers/DownloadRequestHandler.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Wasari.Daemon/Handlers/DownloadRequestHandler.cs b/Wasari.Daemon/Handlers/DownloadRequestHandler.cs index a7d6d23..efe2ce8 100644 --- a/Wasari.Daemon/Handlers/DownloadRequestHandler.cs +++ b/Wasari.Daemon/Handlers/DownloadRequestHandler.cs @@ -5,6 +5,7 @@ using Wasari.App.Abstractions; using Wasari.Daemon.Models; using Wasari.Daemon.Options; +using Wolverine; namespace Wasari.Daemon.Handlers; @@ -15,7 +16,8 @@ public async ValueTask Handle(DownloadRequest request, DownloadServiceSolver downloadServiceSolver, IServiceProvider serviceProvider, IOptions daemonOptions, - IOptions downloadOptions) + IOptions downloadOptions, + IMessageBus messageBus) { if (daemonOptions.Value.RedisLockEnabled) { @@ -29,15 +31,15 @@ public async ValueTask Handle(DownloadRequest request, return; } - await DownloadEpisode(request, logger, downloadServiceSolver, serviceProvider, daemonOptions, downloadOptions); + await DownloadEpisode(request, logger, downloadServiceSolver, serviceProvider, daemonOptions, downloadOptions, messageBus); } else { - await DownloadEpisode(request, logger, downloadServiceSolver, serviceProvider, daemonOptions, downloadOptions); + await DownloadEpisode(request, logger, downloadServiceSolver, serviceProvider, daemonOptions, downloadOptions, messageBus); } } - private static async ValueTask DownloadEpisode(DownloadRequest request, ILogger logger, DownloadServiceSolver downloadServiceSolver, IServiceProvider serviceProvider, IOptions daemonOptions, IOptions downloadOptions) + private static async ValueTask DownloadEpisode(DownloadRequest request, ILogger logger, DownloadServiceSolver downloadServiceSolver, IServiceProvider serviceProvider, IOptions daemonOptions, IOptions downloadOptions, IMessageBus messageBus) { logger.LogInformation("Starting download of {Url}", request.Url); @@ -50,10 +52,14 @@ private static async ValueTask DownloadEpisode(DownloadRequest request, ILogger new DownloadEpisodeOptions(episodesRange, seasonsRange, outputDirectoryOverride)); foreach (var downloadedEpisode in episodes) + { switch (downloadedEpisode.Status) { case DownloadedEpisodeStatus.Downloaded: logger.LogInformation("Downloaded {Episode}", downloadedEpisode); + + if (downloadedEpisode.FilePath != null) + await messageBus.PublishAsync(new CheckVideoIntegrityRequest(downloadedEpisode.FilePath, true)); break; case DownloadedEpisodeStatus.AlreadyExists: logger.LogWarning("Episode already exists {Episode}", downloadedEpisode); @@ -64,6 +70,7 @@ private static async ValueTask DownloadEpisode(DownloadRequest request, ILogger default: throw new ArgumentOutOfRangeException(); } + } if (daemonOptions.Value.NotificationEnabled && serviceProvider.GetService() is { } notificationService) await notificationService.SendNotifcationForDownloadedEpisodeAsync(episodes); }