1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-21 22:05:38 -04:00

New: Option to not prefer repacks/propers (for use with Preferred Words)

Closes #3084
This commit is contained in:
Mark McDowall
2019-05-04 00:33:13 -07:00
parent a06cbc44cd
commit 7321075631
15 changed files with 283 additions and 77 deletions
@@ -1,4 +1,5 @@
using NLog;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Profiles.Languages;
using NzbDrone.Core.Profiles.Qualities;
@@ -18,41 +19,15 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public class UpgradableSpecification : IUpgradableSpecification
{
private readonly IConfigService _configService;
private readonly Logger _logger;
public UpgradableSpecification(Logger logger)
public UpgradableSpecification(IConfigService configService, Logger logger)
{
_configService = configService;
_logger = logger;
}
private bool IsLanguageUpgradable(LanguageProfile profile, Language currentLanguage, Language newLanguage = null)
{
if (newLanguage != null)
{
var compare = new LanguageComparer(profile).Compare(newLanguage, currentLanguage);
if (compare <= 0)
{
return false;
}
}
return true;
}
private bool IsQualityUpgradable(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null)
{
if (newQuality != null)
{
var compare = new QualityModelComparer(profile).Compare(newQuality, currentQuality);
if (compare <= 0)
{
_logger.Debug("Existing item has better quality, skipping");
return false;
}
}
return true;
}
private bool IsPreferredWordUpgradable(int currentScore, int newScore)
{
return newScore > currentScore;
@@ -60,23 +35,36 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public bool IsUpgradable(QualityProfile qualityProfile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, int currentScore, QualityModel newQuality, Language newLanguage, int newScore)
{
if (IsQualityUpgradable(qualityProfile, currentQuality, newQuality))
var qualityComparer = new QualityModelComparer(qualityProfile);
var qualityCompare = qualityComparer.Compare(newQuality?.Quality, currentQuality.Quality);
if (qualityCompare > 0)
{
return true;
}
if (new QualityModelComparer(qualityProfile).Compare(newQuality, currentQuality) < 0)
if (qualityCompare < 0)
{
_logger.Debug("Existing item has better quality, skipping");
return false;
}
if (IsLanguageUpgradable(languageProfile, currentLanguage, newLanguage))
// Accept unless the user doesn't want to prefer propers, optionally they can
// use preferred words to prefer propers/repacks over non-propers/repacks.
if (_configService.DownloadPropersAndRepacks != ProperDownloadTypes.DoNotPrefer &&
newQuality?.Revision.CompareTo(currentQuality.Revision) > 0)
{
return true;
}
if (new LanguageComparer(languageProfile).Compare(newLanguage, currentLanguage) < 0)
var languageCompare = new LanguageComparer(languageProfile).Compare(newLanguage, currentLanguage);
if (languageCompare > 0)
{
return true;
}
if (languageCompare < 0)
{
_logger.Debug("Existing item has better language, skipping");
return false;