feat(radarr): support trash_score in custom format json

Trash has started putting scores in the actual importable JSON data. If
a score is found in the JSON data, that takes precedence over any score
parsed from the guide markdown. The `trash_score` field is not required
for backward compatibility.
recyclarr
Robert Dailey 3 years ago
parent 3290ebb131
commit 45cf774ada

@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Support `trash_score` property in Custom Format JSON from the guide. This property is optional and
takes precedence over a score mentioned in the guide markdown.
## [1.5.0] - 2021-05-16
### Added

@ -378,5 +378,42 @@ namespace Trash.Tests.Radarr.CustomFormat.Processors.GuideSteps
processor.DeletedCustomFormatsInCache.Should().BeEmpty();
processor.ProcessedCustomFormats.Should().BeEmpty();
}
[Test]
public void Score_from_json_takes_precedence_over_score_from_guide()
{
var guideData = new List<CustomFormatData>
{
new() {Json = @"{'name': 'name1', 'trash_id': 'id1', 'trash_score': 100}"}
};
var testConfig = new List<CustomFormatConfig>
{
new()
{
Names = new List<string> {"name1"},
QualityProfiles = new List<QualityProfileConfig>
{
new() {Name = "profile", Score = 200}
}
}
};
var processor = new CustomFormatStep();
processor.Process(guideData, testConfig, null);
processor.DuplicatedCustomFormats.Should().BeEmpty();
processor.CustomFormatsWithOutdatedNames.Should().BeEmpty();
processor.DeletedCustomFormatsInCache.Should().BeEmpty();
processor.ProcessedCustomFormats.Should()
.BeEquivalentTo(new List<ProcessedCustomFormatData>
{
new("name1", "id1", JObject.FromObject(new {name = "name1"}))
{
Score = 100
}
},
op => op.Using(new JsonEquivalencyStep()));
}
}
}

@ -97,8 +97,19 @@ namespace Trash.Radarr.CustomFormat.Processors.GuideSteps
CustomFormatCache? cache)
{
JObject obj = JObject.Parse(guideData.Json);
var name = obj["name"].Value<string>();
var trashId = obj["trash_id"].Value<string>();
var name = (string) obj["name"];
var trashId = (string) obj["trash_id"];
int? finalScore;
if (obj.TryGetValue("trash_score", out var score))
{
finalScore = (int) score;
obj.Property("trash_score").Remove();
}
else
{
finalScore = guideData.Score;
}
// Remove trash_id, it's metadata that is not meant for Radarr itself
// Radarr supposedly drops this anyway, but I prefer it to be removed by TrashUpdater
@ -106,7 +117,7 @@ namespace Trash.Radarr.CustomFormat.Processors.GuideSteps
return new ProcessedCustomFormatData(name, trashId, obj)
{
Score = guideData.Score,
Score = finalScore,
CacheEntry = cache?.TrashIdMappings.FirstOrDefault(c => c.TrashId == trashId)
};
}

Loading…
Cancel
Save