Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Adds downloaded files to integrity check queue
Browse files Browse the repository at this point in the history
  • Loading branch information
redbaty committed Nov 9, 2023
1 parent 6cb9608 commit efe2e28
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Wasari.Daemon/Handlers/DownloadRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Wasari.App.Abstractions;
using Wasari.Daemon.Models;
using Wasari.Daemon.Options;
using Wolverine;

namespace Wasari.Daemon.Handlers;

Expand All @@ -15,7 +16,8 @@ public async ValueTask Handle(DownloadRequest request,
DownloadServiceSolver downloadServiceSolver,
IServiceProvider serviceProvider,
IOptions<DaemonOptions> daemonOptions,
IOptions<DownloadOptions> downloadOptions)
IOptions<DownloadOptions> downloadOptions,
IMessageBus messageBus)
{
if (daemonOptions.Value.RedisLockEnabled)
{
Expand All @@ -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> daemonOptions, IOptions<DownloadOptions> downloadOptions)
private static async ValueTask DownloadEpisode(DownloadRequest request, ILogger logger, DownloadServiceSolver downloadServiceSolver, IServiceProvider serviceProvider, IOptions<DaemonOptions> daemonOptions, IOptions<DownloadOptions> downloadOptions, IMessageBus messageBus)
{
logger.LogInformation("Starting download of {Url}", request.Url);

Expand All @@ -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);
Expand All @@ -64,6 +70,7 @@ private static async ValueTask DownloadEpisode(DownloadRequest request, ILogger
default:
throw new ArgumentOutOfRangeException();
}
}

if (daemonOptions.Value.NotificationEnabled && serviceProvider.GetService<NotificationService>() is { } notificationService) await notificationService.SendNotifcationForDownloadedEpisodeAsync(episodes);
}
Expand Down

0 comments on commit efe2e28

Please sign in to comment.