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] [Test]
public void should_be_false_when_release_is_proper_for_existing_episode_of_different_quality() 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; _remoteEpisode.Release.PublishDate = DateTime.UtcNow;
GivenExistingFile(new QualityModel(Quality.SDTV), Language.English); GivenExistingFile(new QualityModel(Quality.HDTV720p), Language.English);
_delayProfile.UsenetDelay = 720; _delayProfile.UsenetDelay = 720;

View File

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