mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-21 22:05:38 -04:00
New: Custom Format Language Condition
This commit is contained in:
@@ -3,8 +3,6 @@ using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Profiles.Languages;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
@@ -12,12 +10,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
public interface IUpgradableSpecification
|
||||
{
|
||||
bool IsUpgradable(QualityProfile profile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, List<CustomFormat> currentCustomFormats, QualityModel newQuality, Language newLanguage, List<CustomFormat> newCustomFormats);
|
||||
bool IsUpgradable(QualityProfile profile, QualityModel currentQuality, List<CustomFormat> currentCustomFormats, QualityModel newQuality, List<CustomFormat> newCustomFormats);
|
||||
bool QualityCutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null);
|
||||
bool LanguageCutoffNotMet(LanguageProfile languageProfile, Language currentLanguage);
|
||||
bool CutoffNotMet(QualityProfile profile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, List<CustomFormat> currentCustomFormats, QualityModel newQuality = null);
|
||||
bool CutoffNotMet(QualityProfile profile, QualityModel currentQuality, List<CustomFormat> currentCustomFormats, QualityModel newQuality = null);
|
||||
bool IsRevisionUpgrade(QualityModel currentQuality, QualityModel newQuality);
|
||||
bool IsUpgradeAllowed(QualityProfile qualityProfile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, QualityModel newQuality, Language newLanguage);
|
||||
bool IsUpgradeAllowed(QualityProfile qualityProfile, QualityModel currentQuality, QualityModel newQuality);
|
||||
}
|
||||
|
||||
public class UpgradableSpecification : IUpgradableSpecification
|
||||
@@ -38,7 +35,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
return newScore > currentScore;
|
||||
}
|
||||
|
||||
public bool IsUpgradable(QualityProfile qualityProfile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, List<CustomFormat> currentCustomFormats, QualityModel newQuality, Language newLanguage, List<CustomFormat> newCustomFormats)
|
||||
public bool IsUpgradable(QualityProfile qualityProfile, QualityModel currentQuality, List<CustomFormat> currentCustomFormats, QualityModel newQuality, List<CustomFormat> newCustomFormats)
|
||||
{
|
||||
var qualityComparer = new QualityModelComparer(qualityProfile);
|
||||
var qualityCompare = qualityComparer.Compare(newQuality?.Quality, currentQuality.Quality);
|
||||
@@ -78,20 +75,6 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
return false;
|
||||
}
|
||||
|
||||
var languageCompare = new LanguageComparer(languageProfile).Compare(newLanguage, currentLanguage);
|
||||
|
||||
if (languageCompare > 0)
|
||||
{
|
||||
_logger.Debug("New item has a more preferred language");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (languageCompare < 0)
|
||||
{
|
||||
_logger.Debug("Existing item has better language, skipping");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newFormatScore <= currentFormatScore)
|
||||
{
|
||||
_logger.Debug("New item's custom formats [{0}] do not improve on [{1}], skipping",
|
||||
@@ -122,32 +105,14 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool LanguageCutoffNotMet(LanguageProfile languageProfile, Language currentLanguage)
|
||||
{
|
||||
var cutoff = languageProfile.UpgradeAllowed
|
||||
? languageProfile.Cutoff
|
||||
: languageProfile.FirstAllowedLanguage();
|
||||
|
||||
var languageCompare = new LanguageComparer(languageProfile).Compare(currentLanguage, cutoff);
|
||||
|
||||
return languageCompare < 0;
|
||||
}
|
||||
|
||||
private bool CustomFormatCutoffNotMet(QualityProfile profile, List<CustomFormat> currentFormats)
|
||||
{
|
||||
var score = profile.CalculateCustomFormatScore(currentFormats);
|
||||
return score < profile.CutoffFormatScore;
|
||||
}
|
||||
|
||||
public bool CutoffNotMet(QualityProfile profile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, List<CustomFormat> currentFormats, QualityModel newQuality = null)
|
||||
public bool CutoffNotMet(QualityProfile profile, QualityModel currentQuality, List<CustomFormat> currentFormats, QualityModel newQuality = null)
|
||||
{
|
||||
// If we can upgrade the language (it is not the cutoff) then the quality doesn't
|
||||
// matter as we can always get same quality with prefered language.
|
||||
if (LanguageCutoffNotMet(languageProfile, currentLanguage))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (QualityCutoffNotMet(profile, currentQuality, newQuality))
|
||||
{
|
||||
return true;
|
||||
@@ -177,13 +142,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsUpgradeAllowed(QualityProfile qualityProfile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, QualityModel newQuality, Language newLanguage)
|
||||
public bool IsUpgradeAllowed(QualityProfile qualityProfile, QualityModel currentQuality, QualityModel newQuality)
|
||||
{
|
||||
var isQualityUpgrade = new QualityModelComparer(qualityProfile).Compare(newQuality, currentQuality) > 0;
|
||||
var isLanguageUpgrade = new LanguageComparer(languageProfile).Compare(newLanguage, currentLanguage) > 0;
|
||||
|
||||
if ((isQualityUpgrade && qualityProfile.UpgradeAllowed) ||
|
||||
(isLanguageUpgrade && languageProfile.UpgradeAllowed))
|
||||
if (isQualityUpgrade && qualityProfile.UpgradeAllowed)
|
||||
{
|
||||
_logger.Debug("At least one profile allows upgrading");
|
||||
return true;
|
||||
@@ -195,12 +158,6 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isLanguageUpgrade && !languageProfile.UpgradeAllowed)
|
||||
{
|
||||
_logger.Debug("Language profile does not allow upgrades, skipping");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user