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 ### Changed
- Program now exits when invalid instances are specified. - 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 ### Deprecated

@ -72,7 +72,7 @@ public class QualityProfileConfigPhase
QualityProfileScoreConfig profile, QualityProfileScoreConfig profile,
CustomFormatData cf) CustomFormatData cf)
{ {
var scoreToUse = profile.Score ?? cf.TrashScore; var scoreToUse = profile.Score ?? cf.DefaultScore ?? cf.TrashScore;
if (scoreToUse is null) if (scoreToUse is null)
{ {
_log.Information("No score in guide or config for CF {Name} ({TrashId})", cf.Name, cf.TrashId); _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 Newtonsoft.Json;
using Recyclarr.Common.Extensions; using Recyclarr.Common.Extensions;
using Recyclarr.TrashLib.Json; using Recyclarr.TrashLib.Json;
@ -34,16 +33,19 @@ public record CustomFormatData
[JsonProperty("trash_id")] [JsonProperty("trash_id")]
[JsonNoSerialize] [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; } = ""; public string TrashId { get; init; } = "";
[JsonProperty("trash_score")] [JsonProperty("trash_score")]
[JsonNoSerialize] [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; } 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 int Id { get; set; }
public string Name { get; init; } = ""; public string Name { get; init; } = "";
public bool IncludeCustomFormatWhenRenaming { get; init; } public bool IncludeCustomFormatWhenRenaming { get; init; }

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

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

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

Loading…
Cancel
Save