1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 07:22:35 +01:00

Fixed: Delay profile being ignored for non-revision upgrades

This commit is contained in:
Mark McDowall 2019-07-01 00:45:05 -07:00
parent 093ed23140
commit 3f67802e3d
2 changed files with 9 additions and 22 deletions

View File

@ -193,10 +193,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
[Test]
public void should_be_false_when_release_is_proper_for_existing_episode_of_different_quality()
{
_remoteEpisode.ParsedEpisodeInfo.Quality = new QualityModel(Quality.HDTV720p, new Revision(version: 2));
_remoteEpisode.ParsedEpisodeInfo.Quality = new QualityModel(Quality.WEBDL720p, new Revision(version: 2));
_remoteEpisode.Release.PublishDate = DateTime.UtcNow;
GivenExistingFile(new QualityModel(Quality.SDTV), Language.English);
GivenExistingFile(new QualityModel(Quality.HDTV720p), Language.English);
_delayProfile.UsenetDelay = 720;

View File

@ -6,28 +6,21 @@ using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles.Delay;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Profiles.Releases;
namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
public class DelaySpecification : IDecisionEngineSpecification
{
private readonly IPendingReleaseService _pendingReleaseService;
private readonly IUpgradableSpecification _upgradableSpecification;
private readonly IDelayProfileService _delayProfileService;
private readonly IPreferredWordService _preferredWordServiceCalculator;
private readonly Logger _logger;
public DelaySpecification(IPendingReleaseService pendingReleaseService,
IUpgradableSpecification upgradableSpecification,
IDelayProfileService delayProfileService,
IPreferredWordService preferredWordServiceCalculator,
Logger logger)
{
_pendingReleaseService = pendingReleaseService;
_upgradableSpecification = upgradableSpecification;
_delayProfileService = delayProfileService;
_preferredWordServiceCalculator = preferredWordServiceCalculator;
_logger = logger;
}
@ -42,7 +35,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
return Decision.Accept();
}
var profile = subject.Series.QualityProfile.Value;
var qualityProfile = subject.Series.QualityProfile.Value;
var languageProfile = subject.Series.LanguageProfile.Value;
var delayProfile = _delayProfileService.BestForTags(subject.Series.Tags);
var delay = delayProfile.GetProtocolDelay(subject.Release.DownloadProtocol);
@ -54,24 +47,18 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
return Decision.Accept();
}
var qualityComparer = new QualityModelComparer(profile);
var qualityComparer = new QualityModelComparer(qualityProfile);
var languageComparer = new LanguageComparer(languageProfile);
if (isPreferredProtocol)
{
foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
{
var upgradable = _upgradableSpecification.IsUpgradable(
profile,
languageProfile,
file.Quality,
file.Language,
_preferredWordServiceCalculator.Calculate(subject.Series, file.GetSceneOrFileName()),
subject.ParsedEpisodeInfo.Quality,
subject.ParsedEpisodeInfo.Language,
subject.PreferredWordScore);
var currentQuality = file.Quality;
var newQuality = subject.ParsedEpisodeInfo.Quality;
var qualityCompare = qualityComparer.Compare(newQuality?.Quality, currentQuality.Quality);
if (upgradable)
if (qualityCompare == 0 && newQuality?.Revision.CompareTo(currentQuality.Revision) > 0)
{
_logger.Debug("New quality is a better revision for existing quality, skipping delay");
return Decision.Accept();
@ -80,7 +67,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
}
// If quality meets or exceeds the best allowed quality in the profile accept it immediately
var bestQualityInProfile = profile.LastAllowedQuality();
var bestQualityInProfile = qualityProfile.LastAllowedQuality();
var isBestInProfile = qualityComparer.Compare(subject.ParsedEpisodeInfo.Quality.Quality, bestQualityInProfile) >= 0;
var isBestInProfileLanguage = languageComparer.Compare(subject.ParsedEpisodeInfo.Language, languageProfile.LastAllowedLanguage()) >= 0;