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

New: Custom Formats

Co-Authored-By: ta264 <ta264@users.noreply.github.com>
This commit is contained in:
Qstick
2022-01-23 23:42:41 -06:00
committed by Mark McDowall
parent 909af6c874
commit b04b4000b8
173 changed files with 6401 additions and 1347 deletions
@@ -1,5 +1,8 @@
using System.Collections.Generic;
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;
@@ -9,10 +12,10 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
{
public interface IUpgradableSpecification
{
bool IsUpgradable(QualityProfile profile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, int currentScore, QualityModel newQuality, Language newLanguage, int newScore);
bool IsUpgradable(QualityProfile profile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, List<CustomFormat> currentCustomFormats, QualityModel newQuality, Language newLanguage, 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, int currentScore, QualityModel newQuality = null, int newScore = 0);
bool CutoffNotMet(QualityProfile profile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, 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);
}
@@ -35,7 +38,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
return newScore > currentScore;
}
public bool IsUpgradable(QualityProfile qualityProfile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, int currentScore, QualityModel newQuality, Language newLanguage, int newScore)
public bool IsUpgradable(QualityProfile qualityProfile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, List<CustomFormat> currentCustomFormats, QualityModel newQuality, Language newLanguage, List<CustomFormat> newCustomFormats)
{
var qualityComparer = new QualityModelComparer(qualityProfile);
var qualityCompare = qualityComparer.Compare(newQuality?.Quality, currentQuality.Quality);
@@ -64,6 +67,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
return true;
}
var currentFormatScore = qualityProfile.CalculateCustomFormatScore(currentCustomFormats);
var newFormatScore = qualityProfile.CalculateCustomFormatScore(newCustomFormats);
// Reject unless the user does not prefer propers/repacks and it's a revision downgrade.
if (downloadPropersAndRepacks != ProperDownloadTypes.DoNotPrefer &&
qualityRevisionComapre < 0)
@@ -86,13 +92,15 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
return false;
}
if (!IsPreferredWordUpgradable(currentScore, newScore))
if (newFormatScore <= currentFormatScore)
{
_logger.Debug("Existing item has an equal or better preferred word score, skipping");
_logger.Debug("New item's custom formats [{0}] do not improve on [{1}], skipping",
newCustomFormats.ConcatToString(),
currentCustomFormats.ConcatToString());
return false;
}
_logger.Debug("New item has a better preferred word score");
_logger.Debug("New item has a better custom format score");
return true;
}
@@ -125,7 +133,13 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
return languageCompare < 0;
}
public bool CutoffNotMet(QualityProfile profile, LanguageProfile languageProfile, QualityModel currentQuality, Language currentLanguage, int currentScore, QualityModel newQuality = null, int newScore = 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)
{
// 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.
@@ -139,7 +153,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
return true;
}
if (IsPreferredWordUpgradable(currentScore, newScore))
if (CustomFormatCutoffNotMet(profile, currentFormats))
{
return true;
}