fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Add initial Blazor Server project

recyclarr
Robert Dailey 3 years ago
parent 8b45379cc8
commit 4254f66bc1

@ -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<ProcessedCustomFormatData> CustomFormats
=> _customFormatProcessor.CustomFormats;
public IReadOnlyCollection<TrashIdMapping> 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);
}
}
}

@ -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<ProcessedCustomFormatData> CustomFormats { get; }
IReadOnlyCollection<TrashIdMapping> DeletedCustomFormatsInCache { get; }
bool IsLoaded { get; }
Task ForceBuildGuideData(RadarrConfig config);
Task<bool> BuildGuideData(RadarrConfig config);

@ -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();

@ -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<List<JObject>> GetCustomFormats()
public async Task<List<CustomFormatData>> GetCustomFormats()
{
return await BaseUrl
.AppendPathSegment("customformat")
.GetJsonAsync<List<JObject>>();
.GetJsonAsync<List<CustomFormatData>>();
}
public async Task<int> CreateCustomFormat(ProcessedCustomFormatData cf)
{
var response = await BaseUrl
.AppendPathSegment("customformat")
.PostJsonAsync(cf.Json)
.PostJsonAsync(cf.Data)
.ReceiveJson<JObject>();
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)

@ -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));
}
}
}

@ -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);
}
}

@ -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<ProcessedCustomFormatData> guideCfs,
IReadOnlyCollection<CustomFormatData> radarrCfs,
RadarrConfig config);
void RecordDeletions(IEnumerable<ProcessedCustomFormatData> guideCfs,
List<CustomFormatData> radarrCfs, RadarrConfig config);
}
}

Loading…
Cancel
Save