From 4254f66bc11fe1f7262b0dc75ca4e5df446f176c Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Thu, 1 Jul 2021 22:56:43 -0500 Subject: [PATCH] fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Add initial Blazor Server project --- src/Recyclarr/Code/Radarr/GuideProcessor.cs | 10 +++---- src/Recyclarr/Code/Radarr/IGuideProcessor.cs | 2 -- .../CustomFormats/CustomFormatsPage.razor.cs | 7 ++--- .../CustomFormat/Api/CustomFormatService.cs | 9 ++++--- .../GuideSteps/QualityProfileStep.cs | 27 ++++++++++++------- .../ICustomFormatApiPersistenceStep.cs | 2 ++ .../PersistenceSteps/IJsonTransactionStep.cs | 10 +++++++ 7 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/Recyclarr/Code/Radarr/GuideProcessor.cs b/src/Recyclarr/Code/Radarr/GuideProcessor.cs index 43c0ea70..df39508b 100644 --- a/src/Recyclarr/Code/Radarr/GuideProcessor.cs +++ b/src/Recyclarr/Code/Radarr/GuideProcessor.cs @@ -7,7 +7,6 @@ using TrashLib.Radarr.Config; using TrashLib.Radarr.CustomFormat.Api; using TrashLib.Radarr.CustomFormat.Guide; using TrashLib.Radarr.CustomFormat.Models; -using TrashLib.Radarr.CustomFormat.Models.Cache; using TrashLib.Radarr.CustomFormat.Processors.GuideSteps; using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps; @@ -43,9 +42,6 @@ namespace Recyclarr.Code.Radarr public IReadOnlyCollection CustomFormats => _customFormatProcessor.CustomFormats; - public IReadOnlyCollection DeletedCustomFormatsInCache - => _customFormatProcessor.DeletedCustomFormatsInCache; - public bool IsLoaded => _guideCustomFormatJson is not null; public async Task ForceBuildGuideData(RadarrConfig config) @@ -84,13 +80,13 @@ namespace Recyclarr.Code.Radarr // Step 1.1: Optionally record deletions of custom formats in cache but not in the guide if (config.DeleteOldCustomFormats) { - _jsonTransactionStep.RecordDeletions(CustomFormats, radarrCfs); + _jsonTransactionStep.RecordDeletions(CustomFormats, radarrCfs, config); } // Step 2: For each merged CF, persist it to Radarr via its API. This will involve a combination of updates // to existing CFs and creation of brand new ones, depending on what's already available in Radarr. - await _customFormatCustomFormatApiPersister.Process( - customFormatService, _jsonTransactionStep.Transactions); + await _customFormatCustomFormatApiPersister.Process(config, customFormatService, + _jsonTransactionStep.Transactions); } } } diff --git a/src/Recyclarr/Code/Radarr/IGuideProcessor.cs b/src/Recyclarr/Code/Radarr/IGuideProcessor.cs index 12ba448e..f389b901 100644 --- a/src/Recyclarr/Code/Radarr/IGuideProcessor.cs +++ b/src/Recyclarr/Code/Radarr/IGuideProcessor.cs @@ -2,14 +2,12 @@ using System.Collections.Generic; using System.Threading.Tasks; using TrashLib.Radarr.Config; using TrashLib.Radarr.CustomFormat.Models; -using TrashLib.Radarr.CustomFormat.Models.Cache; namespace Recyclarr.Code.Radarr { public interface IGuideProcessor { IReadOnlyCollection CustomFormats { get; } - IReadOnlyCollection DeletedCustomFormatsInCache { get; } bool IsLoaded { get; } Task ForceBuildGuideData(RadarrConfig config); Task BuildGuideData(RadarrConfig config); diff --git a/src/Recyclarr/Pages/Radarr/CustomFormats/CustomFormatsPage.razor.cs b/src/Recyclarr/Pages/Radarr/CustomFormats/CustomFormatsPage.razor.cs index 21ff6f97..05da2fa9 100644 --- a/src/Recyclarr/Pages/Radarr/CustomFormats/CustomFormatsPage.razor.cs +++ b/src/Recyclarr/Pages/Radarr/CustomFormats/CustomFormatsPage.razor.cs @@ -89,10 +89,11 @@ namespace Recyclarr.Pages.Radarr.CustomFormats if (ActiveConfig.Value.Config != null) { - ActiveConfig.Value.Config.CustomFormats = _currentSelection + var container = ActiveConfig.Value.Config.CustomFormats; + container.Clear(); + container.AddRange(_currentSelection .Where(s => s.ExistsInGuide) - .Select(s => s.Item) - .ToList(); + .Select(s => s.Item)); } ConfigRepo.Save(); diff --git a/src/TrashLib/Radarr/CustomFormat/Api/CustomFormatService.cs b/src/TrashLib/Radarr/CustomFormat/Api/CustomFormatService.cs index 0bb19512..9b5c0a74 100644 --- a/src/TrashLib/Radarr/CustomFormat/Api/CustomFormatService.cs +++ b/src/TrashLib/Radarr/CustomFormat/Api/CustomFormatService.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Flurl; using Flurl.Http; using Newtonsoft.Json.Linq; +using TrashLib.Radarr.CustomFormat.Api.Models; using TrashLib.Radarr.CustomFormat.Models; namespace TrashLib.Radarr.CustomFormat.Api @@ -16,18 +17,18 @@ namespace TrashLib.Radarr.CustomFormat.Api private string BaseUrl { get; } - public async Task> GetCustomFormats() + public async Task> GetCustomFormats() { return await BaseUrl .AppendPathSegment("customformat") - .GetJsonAsync>(); + .GetJsonAsync>(); } public async Task CreateCustomFormat(ProcessedCustomFormatData cf) { var response = await BaseUrl .AppendPathSegment("customformat") - .PostJsonAsync(cf.Json) + .PostJsonAsync(cf.Data) .ReceiveJson(); return (int) response["id"]; @@ -37,7 +38,7 @@ namespace TrashLib.Radarr.CustomFormat.Api { await BaseUrl .AppendPathSegment($"customformat/{formatId}") - .PutJsonAsync(cf.Json); + .PutJsonAsync(cf.Data); } public async Task DeleteCustomFormat(int formatId) diff --git a/src/TrashLib/Radarr/CustomFormat/Processors/GuideSteps/QualityProfileStep.cs b/src/TrashLib/Radarr/CustomFormat/Processors/GuideSteps/QualityProfileStep.cs index 2825e2aa..b40a95f7 100644 --- a/src/TrashLib/Radarr/CustomFormat/Processors/GuideSteps/QualityProfileStep.cs +++ b/src/TrashLib/Radarr/CustomFormat/Processors/GuideSteps/QualityProfileStep.cs @@ -16,35 +16,42 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps foreach (var profile in config.QualityProfiles) foreach (var cfScore in profile.Scores) { + var matchingCf = customFormats.FirstOrDefault(cf => cf.TrashId == cfScore.TrashId); + if (matchingCf is null) + { + continue; + } + // Check if there is a score we can use. Priority is: // 1. Score from the YAML config is used. If user did not provide, // 2. Score from the guide is used. If the guide did not have one, - // 3. Warn the user and - var scoreToUse = profile.Scores.FirstOrDefault(s => s.TrashId == cf.TrashId); - if (scoreToUse == null) + // 3. Record the CF without a score + var scoreToUse = matchingCf?.Score; + if (scoreToUse is null) { - if (cf.Score == null) + if (cfScore.Score is null) { - CustomFormatsWithoutScore.Add((cf.Name, cf.TrashId, profile.)); + var name = matchingCf!.Name; + CustomFormatsWithoutScore.Add((name, cfScore.TrashId, profile.ProfileName)); } else { - scoreToUse = cf.Score.Value; + scoreToUse = cfScore.Score.Value; } } - if (scoreToUse == null) + if (scoreToUse is null) { continue; } - if (!ProfileScores.TryGetValue(profile.Name, out var mapping)) + if (!ProfileScores.TryGetValue(profile.ProfileName, out var mapping)) { mapping = new QualityProfileCustomFormatScoreMapping(profile.ResetUnmatchedScores); - ProfileScores[profile.Name] = mapping; + ProfileScores[profile.ProfileName] = mapping; } - mapping.Mapping.Add(new FormatMappingEntry(cf, scoreToUse.Value)); + mapping.Mapping.Add(new FormatMappingEntry(matchingCf!, scoreToUse.Value)); } } } diff --git a/src/TrashLib/Radarr/CustomFormat/Processors/PersistenceSteps/ICustomFormatApiPersistenceStep.cs b/src/TrashLib/Radarr/CustomFormat/Processors/PersistenceSteps/ICustomFormatApiPersistenceStep.cs index b6172f30..9ea7335e 100644 --- a/src/TrashLib/Radarr/CustomFormat/Processors/PersistenceSteps/ICustomFormatApiPersistenceStep.cs +++ b/src/TrashLib/Radarr/CustomFormat/Processors/PersistenceSteps/ICustomFormatApiPersistenceStep.cs @@ -1,9 +1,11 @@ using System.Threading.Tasks; +using TrashLib.Radarr.Config; using TrashLib.Radarr.CustomFormat.Api; namespace TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps { public interface ICustomFormatApiPersistenceStep { + Task Process(RadarrConfig config, ICustomFormatService api, CustomFormatTransactionData transactions); } } diff --git a/src/TrashLib/Radarr/CustomFormat/Processors/PersistenceSteps/IJsonTransactionStep.cs b/src/TrashLib/Radarr/CustomFormat/Processors/PersistenceSteps/IJsonTransactionStep.cs index 3fd7576b..45611295 100644 --- a/src/TrashLib/Radarr/CustomFormat/Processors/PersistenceSteps/IJsonTransactionStep.cs +++ b/src/TrashLib/Radarr/CustomFormat/Processors/PersistenceSteps/IJsonTransactionStep.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Newtonsoft.Json.Linq; using TrashLib.Radarr.Config; +using TrashLib.Radarr.CustomFormat.Api.Models; using TrashLib.Radarr.CustomFormat.Models; using TrashLib.Radarr.CustomFormat.Models.Cache; @@ -8,5 +9,14 @@ namespace TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps { public interface IJsonTransactionStep { + CustomFormatTransactionData Transactions { get; } + + void Process( + IEnumerable guideCfs, + IReadOnlyCollection radarrCfs, + RadarrConfig config); + + void RecordDeletions(IEnumerable guideCfs, + List radarrCfs, RadarrConfig config); } }