From 77ac0bb44c9516fe5311841cf4be3f340d6ce2cd Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 8 Apr 2021 17:27:01 -0700 Subject: [PATCH] Fixed: Importing a language upgrade with a worse preferred word score --- .../UpgradeSpecificationFixture.cs | 67 ++++++++++++++++++- .../Specifications/UpgradeSpecification.cs | 2 +- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/UpgradeSpecificationFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/UpgradeSpecificationFixture.cs index ad844cca2..5cdb1e9a3 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/UpgradeSpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/UpgradeSpecificationFixture.cs @@ -281,7 +281,7 @@ public void should_return_false_if_not_a_revision_upgrade_and_prefers_propers() } [Test] - public void should_return_false_if_it_is_not_a_preferred_word_upgrade() + public void should_return_false_if_it_is_a_preferred_word_downgrade_and_equal_language_and_quality() { Mocker.GetMock() .Setup(s => s.DownloadPropersAndRepacks) @@ -300,7 +300,8 @@ public void should_return_false_if_it_is_not_a_preferred_word_upgrade() .With(e => e.EpisodeFile = new LazyLoaded( new EpisodeFile { - Quality = new QualityModel(Quality.Bluray1080p) + Quality = new QualityModel(Quality.Bluray1080p), + Language = Language.Spanish })) .Build() .ToList(); @@ -310,6 +311,68 @@ public void should_return_false_if_it_is_not_a_preferred_word_upgrade() Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse(); } + [Test] + public void should_return_true_if_it_is_a_preferred_word_downgrade_and_language_downgrade_and_a_quality_upgrade() + { + Mocker.GetMock() + .Setup(s => s.DownloadPropersAndRepacks) + .Returns(ProperDownloadTypes.DoNotPrefer); + + Mocker.GetMock() + .Setup(s => s.Calculate(It.IsAny(), It.IsAny())) + .Returns(10); + + _localEpisode.PreferredWordScore = 5; + _localEpisode.Quality = new QualityModel(Quality.Bluray2160p); + + _localEpisode.Episodes = Builder.CreateListOfSize(1) + .All() + .With(e => e.EpisodeFileId = 1) + .With(e => e.EpisodeFile = new LazyLoaded( + new EpisodeFile + { + Quality = new QualityModel(Quality.Bluray1080p), + Language = Language.French + })) + .Build() + .ToList(); + + _localEpisode.FileEpisodeInfo = Builder.CreateNew().Build(); + + Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue(); + } + + [Test] + public void should_return_true_if_it_is_a_preferred_word_downgrade_but_a_language_upgrade() + { + Mocker.GetMock() + .Setup(s => s.DownloadPropersAndRepacks) + .Returns(ProperDownloadTypes.DoNotPrefer); + + Mocker.GetMock() + .Setup(s => s.Calculate(It.IsAny(), It.IsAny())) + .Returns(10); + + _localEpisode.PreferredWordScore = 5; + _localEpisode.Quality = new QualityModel(Quality.Bluray1080p); + + _localEpisode.Episodes = Builder.CreateListOfSize(1) + .All() + .With(e => e.EpisodeFileId = 1) + .With(e => e.EpisodeFile = new LazyLoaded( + new EpisodeFile + { + Quality = new QualityModel(Quality.Bluray1080p), + Language = Language.English + })) + .Build() + .ToList(); + + _localEpisode.FileEpisodeInfo = Builder.CreateNew().Build(); + + Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue(); + } + [Test] public void should_return_true_if_not_a_revision_upgrade_and_does_not_prefer_propers() { diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/UpgradeSpecification.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/UpgradeSpecification.cs index 88affb5a1..9f5079f50 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/UpgradeSpecification.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/UpgradeSpecification.cs @@ -73,7 +73,7 @@ public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem down var episodeFilePreferredWordScore = _episodeFilePreferredWordCalculator.Calculate(localEpisode.Series, episodeFile); - if (qualityCompare == 0 && preferredWordScore < episodeFilePreferredWordScore) + if (qualityCompare == 0 && languageCompare == 0 && preferredWordScore < episodeFilePreferredWordScore) { _logger.Debug("This file isn't a preferred word upgrade for all episodes. Skipping {0}", localEpisode.Path); return Decision.Reject("Not a preferred word upgrade for existing episode file(s)");