diff --git a/CHANGELOG.md b/CHANGELOG.md index ca4016bf..e507a0fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileConfigPhase.cs b/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileConfigPhase.cs index bef709d3..8a18ca77 100644 --- a/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileConfigPhase.cs +++ b/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileConfigPhase.cs @@ -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); diff --git a/src/Recyclarr.TrashLib/Models/CustomFormatData.cs b/src/Recyclarr.TrashLib/Models/CustomFormatData.cs index 5d6459f1..e3dd4afb 100644 --- a/src/Recyclarr.TrashLib/Models/CustomFormatData.cs +++ b/src/Recyclarr.TrashLib/Models/CustomFormatData.cs @@ -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 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; } diff --git a/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Guide/CustomFormatParserTest.cs b/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Guide/CustomFormatParserTest.cs index 1ab4c6ba..396283fa 100644 --- a/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Guide/CustomFormatParserTest.cs +++ b/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Guide/CustomFormatParserTest.cs @@ -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 }; diff --git a/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Models/CustomFormatDataComparerTest.cs b/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Models/CustomFormatDataComparerTest.cs index d6c3cfe0..c9f8c6d0 100644 --- a/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Models/CustomFormatDataComparerTest.cs +++ b/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Models/CustomFormatDataComparerTest.cs @@ -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" }; diff --git a/src/tests/Recyclarr.TrashLib.TestLibrary/NewCf.cs b/src/tests/Recyclarr.TrashLib.TestLibrary/NewCf.cs index dc5903b1..7f88ba7d 100644 --- a/src/tests/Recyclarr.TrashLib.TestLibrary/NewCf.cs +++ b/src/tests/Recyclarr.TrashLib.TestLibrary/NewCf.cs @@ -11,7 +11,7 @@ public static class NewCf Id = id, Name = name, TrashId = trashId, - TrashScore = score + TrashScores = {["default"] = score} }; }