fix: Grab scores from the `trash_scores` object in CF json data

The `default` key is assigned a score intended to replace the old
`trash_score` property.
json-serializing-nullable-fields-issue
Robert Dailey 9 months ago
parent 4935377a4b
commit f9ba985d1f

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Program now exits when invalid instances are specified.
- Scores are now pulled from the `trash_scores` object in the guide's CF json files.
### Deprecated

@ -72,7 +72,7 @@ public class QualityProfileConfigPhase
QualityProfileScoreConfig profile,
CustomFormatData cf)
{
var scoreToUse = profile.Score ?? cf.TrashScore;
var scoreToUse = profile.Score ?? cf.DefaultScore ?? cf.TrashScore;
if (scoreToUse is null)
{
_log.Information("No score in guide or config for CF {Name} ({TrashId})", cf.Name, cf.TrashId);

@ -1,4 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;
using Recyclarr.Common.Extensions;
using Recyclarr.TrashLib.Json;
@ -34,16 +33,19 @@ public record CustomFormatData
[JsonProperty("trash_id")]
[JsonNoSerialize]
[SuppressMessage("Design", "CA1044:Properties should not be write only",
Justification = "We want to deserialize but not serialize this property")]
public string TrashId { get; init; } = "";
[JsonProperty("trash_score")]
[JsonNoSerialize]
[SuppressMessage("Design", "CA1044:Properties should not be write only",
Justification = "We want to deserialize but not serialize this property")]
public int? TrashScore { get; init; }
[JsonProperty("trash_scores")]
[JsonNoSerialize]
public Dictionary<string, int> TrashScores { get; init; } = new();
[JsonIgnore]
public int? DefaultScore => TrashScores.TryGetValue("default", out var score) ? score : null;
public int Id { get; set; }
public string Name { get; init; } = "";
public bool IncludeCustomFormatWhenRenaming { get; init; }

@ -13,49 +13,54 @@ public class CustomFormatParserTest
[Test, AutoMockData]
public void Deserialize_works(CustomFormatParser sut)
{
var jsonData = @"
{
'trash_id': '90cedc1fea7ea5d11298bebd3d1d3223',
'trash_score': '-10000',
'name': 'EVO (no WEBDL)',
'includeCustomFormatWhenRenaming': false,
'specifications': [
{
'name': 'EVO',
'implementation': 'ReleaseTitleSpecification',
'negate': false,
'required': true,
'fields': [{
'value': '\\bEVO(TGX)?\\b'
}]
},
{
'name': 'WEBDL',
'implementation': 'SourceSpecification',
'negate': true,
'required': true,
'fields': {
'value': 7
}
},
{
'name': 'WEBRIP',
'implementation': 'SourceSpecification',
'negate': true,
'required': true,
'fields': {
'value': 8
}
}
]
}";
const string jsonData =
"""
{
"trash_id": "90cedc1fea7ea5d11298bebd3d1d3223",
"trash_scores": {
"default": -10000,
},
"name": "EVO (no WEBDL)",
"includeCustomFormatWhenRenaming": false,
"specifications": [
{
"name": "EVO",
"implementation": "ReleaseTitleSpecification",
"negate": false,
"required": true,
"fields": [{
"value": "\\bEVO(TGX)?\\b"
}]
},
{
"name": "WEBDL",
"implementation": "SourceSpecification",
"negate": true,
"required": true,
"fields": {
"value": 7
}
},
{
"name": "WEBRIP",
"implementation": "SourceSpecification",
"negate": true,
"required": true,
"fields": {
"value": 8
}
}
]
}
""";
var result = sut.ParseCustomFormatData(jsonData, "file.json");
result.Should().BeEquivalentTo(new CustomFormatData
{
FileName = "file.json",
TrashId = "90cedc1fea7ea5d11298bebd3d1d3223",
TrashScore = -10000,
TrashScores = {["default"] = -10000},
Name = "EVO (no WEBDL)",
IncludeCustomFormatWhenRenaming = false,
Specifications = new[]
@ -113,7 +118,7 @@ public class CustomFormatParserTest
{
FileName = "file.json",
TrashId = "90cedc1fea7ea5d11298bebd3d1d3223",
TrashScore = -10000,
TrashScores = {["default"] = -10000},
Name = "EVO (no WEBDL)",
IncludeCustomFormatWhenRenaming = false
};

@ -231,7 +231,7 @@ public class CustomFormatDataComparerTest
{
FileName = "file1.json",
TrashId = "a",
TrashScore = 1,
TrashScores = {["default"] = 1},
Category = "one"
};
@ -239,7 +239,7 @@ public class CustomFormatDataComparerTest
{
FileName = "file2.json",
TrashId = "b",
TrashScore = 2,
TrashScores = {["default"] = 2},
Category = "two"
};

@ -11,7 +11,7 @@ public static class NewCf
Id = id,
Name = name,
TrashId = trashId,
TrashScore = score
TrashScores = {["default"] = score}
};
}

Loading…
Cancel
Save