parent
ee59f91ba2
commit
05e7b90aab
@ -0,0 +1,292 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Profiles.Qualities;
|
||||||
|
using NzbDrone.Core.Qualities;
|
||||||
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Core.Languages;
|
||||||
|
using NzbDrone.Core.Profiles.Languages;
|
||||||
|
using NzbDrone.Core.Test.Languages;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class UpgradeAllowedSpecificationFixture : CoreTest<UpgradableSpecification>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_return_false_when_quality_are_the_same_language_is_better_and_upgrade_allowed_is_false_for_language_profile()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English, Language.French),
|
||||||
|
Cutoff = Language.French,
|
||||||
|
UpgradeAllowed = false
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English,
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.French
|
||||||
|
).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_false_when_quality_is_better_languages_are_the_same_and_upgrade_allowed_is_false_for_quality_profile()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = false
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
|
||||||
|
Cutoff = Language.English,
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English,
|
||||||
|
new QualityModel(Quality.Bluray1080p),
|
||||||
|
Language.English
|
||||||
|
).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_for_language_upgrade_when_upgrading_is_allowed()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English, Language.French),
|
||||||
|
Cutoff = Language.French,
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English,
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.French
|
||||||
|
).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_for_same_language_when_upgrading_is_allowed()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English, Language.French),
|
||||||
|
Cutoff = Language.French,
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English,
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English
|
||||||
|
).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_for_same_language_when_upgrading_is_not_allowed()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English, Language.French),
|
||||||
|
Cutoff = Language.French,
|
||||||
|
UpgradeAllowed = false
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English,
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English
|
||||||
|
).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_for_lower_language_when_upgrading_is_allowed()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English, Language.French),
|
||||||
|
Cutoff = Language.French,
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.French,
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English
|
||||||
|
).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_for_lower_language_when_upgrading_is_not_allowed()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English, Language.French),
|
||||||
|
Cutoff = Language.French,
|
||||||
|
UpgradeAllowed = false
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.French,
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English
|
||||||
|
).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_for_quality_upgrade_when_upgrading_is_allowed()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
|
||||||
|
Cutoff = Language.English,
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English,
|
||||||
|
new QualityModel(Quality.Bluray1080p),
|
||||||
|
Language.English
|
||||||
|
).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_for_same_quality_when_upgrading_is_allowed()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
|
||||||
|
Cutoff = Language.English,
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English,
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English
|
||||||
|
).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_for_same_quality_when_upgrading_is_not_allowed()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = false
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
|
||||||
|
Cutoff = Language.English,
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English,
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English
|
||||||
|
).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_for_lower_quality_when_upgrading_is_allowed()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
|
||||||
|
Cutoff = Language.English,
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English,
|
||||||
|
new QualityModel(Quality.SDTV),
|
||||||
|
Language.English
|
||||||
|
).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_for_lower_quality_when_upgrading_is_not_allowed()
|
||||||
|
{
|
||||||
|
Subject.IsUpgradeAllowed(
|
||||||
|
new QualityProfile
|
||||||
|
{
|
||||||
|
Cutoff = Quality.Bluray1080p.Id,
|
||||||
|
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||||
|
UpgradeAllowed = false
|
||||||
|
},
|
||||||
|
new LanguageProfile
|
||||||
|
{
|
||||||
|
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
|
||||||
|
Cutoff = Language.English,
|
||||||
|
UpgradeAllowed = true
|
||||||
|
},
|
||||||
|
new QualityModel(Quality.DVD),
|
||||||
|
Language.English,
|
||||||
|
new QualityModel(Quality.SDTV),
|
||||||
|
Language.English
|
||||||
|
).Should().BeTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||||
|
{
|
||||||
|
public class UpgradeAllowedSpecification : IDecisionEngineSpecification
|
||||||
|
{
|
||||||
|
private readonly UpgradableSpecification _upgradableSpecification;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public UpgradeAllowedSpecification(UpgradableSpecification upgradableSpecification, Logger logger)
|
||||||
|
{
|
||||||
|
_upgradableSpecification = upgradableSpecification;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpecificationPriority Priority => SpecificationPriority.Default;
|
||||||
|
public RejectionType Type => RejectionType.Permanent;
|
||||||
|
|
||||||
|
public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
||||||
|
{
|
||||||
|
var qualityProfile = subject.Series.QualityProfile.Value;
|
||||||
|
var languageProfile = subject.Series.LanguageProfile.Value;
|
||||||
|
|
||||||
|
foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
|
||||||
|
{
|
||||||
|
if (file == null)
|
||||||
|
{
|
||||||
|
_logger.Debug("File is no longer available, skipping this file.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug("Comparing file quality and language with report. Existing file is {0} - {1}", file.Quality, file.Language);
|
||||||
|
|
||||||
|
if (!_upgradableSpecification.IsUpgradeAllowed(qualityProfile,
|
||||||
|
languageProfile,
|
||||||
|
file.Quality,
|
||||||
|
file.Language,
|
||||||
|
subject.ParsedEpisodeInfo.Quality,
|
||||||
|
subject.ParsedEpisodeInfo.Language))
|
||||||
|
{
|
||||||
|
_logger.Debug("Upgrading is not allowed by the quality or language profile");
|
||||||
|
|
||||||
|
return Decision.Reject("Existing file and the Quality or Language profile does not allow upgrades");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue