From 1752fe5c53a9882ed05cff7a197bfb56cb290d88 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 17 Apr 2021 23:44:00 -0400 Subject: [PATCH] Fixed: Don't fail AcceptableSizeSpec when no Album Releases exist for Album --- .../AcceptableSizeSpecification.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs index d2798516d..d19323c91 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs @@ -35,10 +35,18 @@ namespace NzbDrone.Core.DecisionEngine.Specifications var qualityDefinition = _qualityDefinitionService.Get(quality); + var minReleaseDuration = subject.Albums.Select(a => a.AlbumReleases.Value.Where(r => r.Monitored || a.AnyReleaseOk).Select(r => r.Duration).MinOrDefault()).Sum() / 1000; + var maxReleaseDuration = subject.Albums.Select(a => a.AlbumReleases.Value.Where(r => r.Monitored || a.AnyReleaseOk).Select(r => r.Duration).MaxOrDefault()).Sum() / 1000; + if (qualityDefinition.MinSize.HasValue) { + if (maxReleaseDuration == 0) + { + _logger.Debug("Album duration is 0, unable to validate size until it is available, rejecting"); + return Decision.Reject("Album duration is 0, unable to validate size until it is available"); + } + var minSize = qualityDefinition.MinSize.Value.Kilobits(); - var minReleaseDuration = subject.Albums.Select(a => a.AlbumReleases.Value.Where(r => r.Monitored || a.AnyReleaseOk).Select(r => r.Duration).Min()).Sum() / 1000; //Multiply minSize by smallest release duration minSize = minSize * minReleaseDuration; @@ -57,10 +65,14 @@ namespace NzbDrone.Core.DecisionEngine.Specifications { _logger.Debug("Max size is unlimited, skipping size check"); } + else if (maxReleaseDuration == 0) + { + _logger.Debug("Album duration is 0, unable to validate size until it is available, rejecting"); + return Decision.Reject("Album duration is 0, unable to validate size until it is available"); + } else { var maxSize = qualityDefinition.MaxSize.Value.Kilobits(); - var maxReleaseDuration = subject.Albums.Select(a => a.AlbumReleases.Value.Where(r => r.Monitored || a.AnyReleaseOk).Select(r => r.Duration).Max()).Sum() / 1000; //Multiply maxSize by Album.Duration maxSize = maxSize * maxReleaseDuration;