mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-02 09:11:54 +02:00
parent
24f03fc1e9
commit
8b20a9449c
@ -123,6 +123,7 @@ class EditQualityProfileModalContent extends Component {
|
||||
upgradeAllowed,
|
||||
cutoff,
|
||||
minFormatScore,
|
||||
minUpgradeFormatScore,
|
||||
cutoffFormatScore,
|
||||
items,
|
||||
formatItems
|
||||
@ -244,6 +245,25 @@ class EditQualityProfileModalContent extends Component {
|
||||
</FormGroup>
|
||||
}
|
||||
|
||||
{
|
||||
upgradeAllowed.value && formatItems.value.length > 0 ?
|
||||
<FormGroup size={sizes.EXTRA_SMALL}>
|
||||
<FormLabel size={sizes.SMALL}>
|
||||
{translate('MinimumCustomFormatScoreIncrement')}
|
||||
</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.NUMBER}
|
||||
name="minUpgradeFormatScore"
|
||||
min={1}
|
||||
{...minUpgradeFormatScore}
|
||||
helpText={translate('MinimumCustomFormatScoreIncrementHelpText')}
|
||||
onChange={onInputChange}
|
||||
/>
|
||||
</FormGroup> :
|
||||
null
|
||||
}
|
||||
|
||||
<div className={styles.formatItemLarge}>
|
||||
{getCustomFormatRender(formatItems, otherProps)}
|
||||
</div>
|
||||
|
@ -16,6 +16,7 @@ interface QualityProfile {
|
||||
items: QualityProfileQualityItem[];
|
||||
minFormatScore: number;
|
||||
cutoffFormatScore: number;
|
||||
minUpgradeFormatScore: number;
|
||||
formatItems: QualityProfileFormatItem[];
|
||||
id: number;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
@ -79,9 +80,9 @@ public void should_return_false_if_proper_and_autoDownloadPropers_is_do_not_pref
|
||||
GivenAutoDownloadPropers(ProperDownloadTypes.DoNotPrefer);
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
};
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
@ -96,9 +97,9 @@ public void should_return_false_if_proper_and_autoDownloadPropers_is_do_not_pref
|
||||
public void should_return_false_if_release_and_existing_file_are_the_same()
|
||||
{
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities()
|
||||
};
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities()
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
@ -146,5 +147,95 @@ public void should_return_false_if_release_has_higher_quality_and_cutoff_is_alre
|
||||
new List<CustomFormat>())
|
||||
.Should().Be(UpgradeableRejectReason.QualityCutoff);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_minimum_custom_score_is_not_met()
|
||||
{
|
||||
var customFormatOne = new CustomFormat
|
||||
{
|
||||
Id = 1,
|
||||
Name = "One"
|
||||
};
|
||||
|
||||
var customFormatTwo = new CustomFormat
|
||||
{
|
||||
Id = 2,
|
||||
Name = "Two"
|
||||
};
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true,
|
||||
MinUpgradeFormatScore = 11,
|
||||
CutoffFormatScore = 100,
|
||||
FormatItems = new List<ProfileFormatItem>
|
||||
{
|
||||
new ProfileFormatItem
|
||||
{
|
||||
Format = customFormatOne,
|
||||
Score = 10
|
||||
},
|
||||
new ProfileFormatItem
|
||||
{
|
||||
Format = customFormatTwo,
|
||||
Score = 20
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.DVD),
|
||||
new List<CustomFormat> { customFormatOne },
|
||||
new QualityModel(Quality.DVD),
|
||||
new List<CustomFormat> { customFormatTwo })
|
||||
.Should().Be(UpgradeableRejectReason.MinCustomFormatScore);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_minimum_custom_score_is_met()
|
||||
{
|
||||
var customFormatOne = new CustomFormat
|
||||
{
|
||||
Id = 1,
|
||||
Name = "One"
|
||||
};
|
||||
|
||||
var customFormatTwo = new CustomFormat
|
||||
{
|
||||
Id = 2,
|
||||
Name = "Two"
|
||||
};
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
UpgradeAllowed = true,
|
||||
MinUpgradeFormatScore = 10,
|
||||
CutoffFormatScore = 100,
|
||||
FormatItems = new List<ProfileFormatItem>
|
||||
{
|
||||
new ProfileFormatItem
|
||||
{
|
||||
Format = customFormatOne,
|
||||
Score = 10
|
||||
},
|
||||
new ProfileFormatItem
|
||||
{
|
||||
Format = customFormatTwo,
|
||||
Score = 20
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
new QualityModel(Quality.DVD),
|
||||
new List<CustomFormat> { customFormatOne },
|
||||
new QualityModel(Quality.DVD),
|
||||
new List<CustomFormat> { customFormatTwo })
|
||||
.Should().Be(UpgradeableRejectReason.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(212)]
|
||||
public class add_minium_upgrade_format_score_to_quality_profiles : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("QualityProfiles").AddColumn("MinUpgradeFormatScore").AsInt32().WithDefaultValue(1);
|
||||
}
|
||||
}
|
||||
}
|
@ -95,6 +95,17 @@ public UpgradeableRejectReason IsUpgradable(QualityProfile qualityProfile, Quali
|
||||
return UpgradeableRejectReason.CustomFormatCutoff;
|
||||
}
|
||||
|
||||
if (newFormatScore < currentFormatScore + qualityProfile.MinUpgradeFormatScore)
|
||||
{
|
||||
_logger.Debug("New item's custom formats [{0}] ({1}) do not meet minimum custom format score increment of {3} required for upgrade, skipping. Existing: [{4}] ({5}).",
|
||||
newCustomFormats.ConcatToString(),
|
||||
newFormatScore,
|
||||
qualityProfile.MinUpgradeFormatScore,
|
||||
currentCustomFormats.ConcatToString(),
|
||||
currentFormatScore);
|
||||
return UpgradeableRejectReason.MinCustomFormatScore;
|
||||
}
|
||||
|
||||
_logger.Debug("New item's custom formats [{0}] ({1}) improve on [{2}] ({3}), accepting",
|
||||
newCustomFormats.ConcatToString(),
|
||||
newFormatScore,
|
||||
|
@ -77,6 +77,9 @@ public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase
|
||||
|
||||
case UpgradeableRejectReason.CustomFormatScore:
|
||||
return Decision.Reject("Existing file on disk has a equal or higher custom format score: {0}", qualityProfile.CalculateCustomFormatScore(customFormats));
|
||||
|
||||
case UpgradeableRejectReason.MinCustomFormatScore:
|
||||
return Decision.Reject("Existing file differential between new release does not meet minimum Custom Format score increment: {0}", qualityProfile.MinFormatScore);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ public enum UpgradeableRejectReason
|
||||
BetterRevision,
|
||||
QualityCutoff,
|
||||
CustomFormatScore,
|
||||
CustomFormatCutoff
|
||||
CustomFormatCutoff,
|
||||
MinCustomFormatScore
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ public void Clean()
|
||||
{
|
||||
profile.MinFormatScore = 0;
|
||||
profile.CutoffFormatScore = 0;
|
||||
profile.MinUpgradeFormatScore = 1;
|
||||
}
|
||||
|
||||
updatedProfiles.Add(profile);
|
||||
@ -73,7 +74,7 @@ public void Clean()
|
||||
|
||||
if (updatedProfiles.Any())
|
||||
{
|
||||
_repository.SetFields(updatedProfiles, p => p.FormatItems, p => p.MinFormatScore, p => p.CutoffFormatScore);
|
||||
_repository.SetFields(updatedProfiles, p => p.FormatItems, p => p.MinFormatScore, p => p.CutoffFormatScore, p => p.MinUpgradeFormatScore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1176,6 +1176,8 @@
|
||||
"MinimumAgeHelpText": "Usenet only: Minimum age in minutes of NZBs before they are grabbed. Use this to give new releases time to propagate to your usenet provider.",
|
||||
"MinimumCustomFormatScore": "Minimum Custom Format Score",
|
||||
"MinimumCustomFormatScoreHelpText": "Minimum custom format score allowed to download",
|
||||
"MinimumCustomFormatScoreIncrement": "Minimum Custom Format Score Increment",
|
||||
"MinimumCustomFormatScoreIncrementHelpText": "Minimum required improvement of the custom format score between existing and new releases before {appName} considers it an upgrade",
|
||||
"MinimumFreeSpace": "Minimum Free Space",
|
||||
"MinimumFreeSpaceHelpText": "Prevent import if it would leave less than this amount of disk space available",
|
||||
"MinimumLimits": "Minimum Limits",
|
||||
|
@ -18,6 +18,7 @@ public QualityProfile()
|
||||
public int Cutoff { get; set; }
|
||||
public int MinFormatScore { get; set; }
|
||||
public int CutoffFormatScore { get; set; }
|
||||
public int MinUpgradeFormatScore { get; set; }
|
||||
public List<ProfileFormatItem> FormatItems { get; set; }
|
||||
public List<QualityProfileQualityItem> Items { get; set; }
|
||||
|
||||
|
@ -174,6 +174,7 @@ public void Handle(CustomFormatDeletedEvent message)
|
||||
{
|
||||
profile.MinFormatScore = 0;
|
||||
profile.CutoffFormatScore = 0;
|
||||
profile.MinUpgradeFormatScore = 1;
|
||||
}
|
||||
|
||||
Update(profile);
|
||||
@ -232,6 +233,7 @@ public QualityProfile GetDefaultProfile(string name, Quality cutoff = null, para
|
||||
Items = items,
|
||||
MinFormatScore = 0,
|
||||
CutoffFormatScore = 0,
|
||||
MinUpgradeFormatScore = 1,
|
||||
FormatItems = formatItems
|
||||
};
|
||||
|
||||
|
@ -15,20 +15,19 @@ namespace Sonarr.Api.V3.Profiles.Quality
|
||||
public class QualityProfileController : RestController<QualityProfileResource>
|
||||
{
|
||||
private readonly IQualityProfileService _profileService;
|
||||
private readonly ICustomFormatService _formatService;
|
||||
|
||||
public QualityProfileController(IQualityProfileService profileService, ICustomFormatService formatService)
|
||||
{
|
||||
_profileService = profileService;
|
||||
_formatService = formatService;
|
||||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||
|
||||
SharedValidator.RuleFor(c => c.MinUpgradeFormatScore).GreaterThanOrEqualTo(1);
|
||||
SharedValidator.RuleFor(c => c.Cutoff).ValidCutoff();
|
||||
SharedValidator.RuleFor(c => c.Items).ValidItems();
|
||||
|
||||
SharedValidator.RuleFor(c => c.FormatItems).Must(items =>
|
||||
{
|
||||
var all = _formatService.All().Select(f => f.Id).ToList();
|
||||
var all = formatService.All().Select(f => f.Id).ToList();
|
||||
var ids = items.Select(i => i.Format);
|
||||
|
||||
return all.Except(ids).Empty();
|
||||
|
@ -15,6 +15,7 @@ public class QualityProfileResource : RestResource
|
||||
public List<QualityProfileQualityItemResource> Items { get; set; }
|
||||
public int MinFormatScore { get; set; }
|
||||
public int CutoffFormatScore { get; set; }
|
||||
public int MinUpgradeFormatScore { get; set; }
|
||||
public List<ProfileFormatItemResource> FormatItems { get; set; }
|
||||
}
|
||||
|
||||
@ -56,6 +57,7 @@ public static QualityProfileResource ToResource(this QualityProfile model)
|
||||
Items = model.Items.ConvertAll(ToResource),
|
||||
MinFormatScore = model.MinFormatScore,
|
||||
CutoffFormatScore = model.CutoffFormatScore,
|
||||
MinUpgradeFormatScore = model.MinUpgradeFormatScore,
|
||||
FormatItems = model.FormatItems.ConvertAll(ToResource)
|
||||
};
|
||||
}
|
||||
@ -103,6 +105,7 @@ public static QualityProfile ToModel(this QualityProfileResource resource)
|
||||
Items = resource.Items.ConvertAll(ToModel),
|
||||
MinFormatScore = resource.MinFormatScore,
|
||||
CutoffFormatScore = resource.CutoffFormatScore,
|
||||
MinUpgradeFormatScore = resource.MinUpgradeFormatScore,
|
||||
FormatItems = resource.FormatItems.ConvertAll(ToModel)
|
||||
};
|
||||
}
|
||||
|
@ -10673,6 +10673,10 @@
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"minUpgradeFormatScore": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"formatItems": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
Loading…
Reference in New Issue
Block a user