You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/src/TrashLib/Radarr/CustomFormat/Processors/GuideSteps/ConfigStep.cs

69 lines
2.4 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using Common.Extensions;
using MoreLinq.Extensions;
using TrashLib.Radarr.Config;
using TrashLib.Radarr.CustomFormat.Models;
namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
internal class ConfigStep : IConfigStep
{
public List<string> CustomFormatsNotInGuide { get; } = new();
public List<ProcessedConfigData> ConfigData { get; } = new();
public void Process(IReadOnlyCollection<ProcessedCustomFormatData> processedCfs,
IEnumerable<CustomFormatConfig> config)
{
foreach (var singleConfig in config)
{
var validCfs = new List<ProcessedCustomFormatData>();
foreach (var name in singleConfig.Names)
{
var match = FindCustomFormatByName(processedCfs, name);
if (match == null)
{
CustomFormatsNotInGuide.Add(name);
}
else
{
validCfs.Add(match);
}
}
foreach (var trashId in singleConfig.TrashIds)
{
var match = processedCfs.FirstOrDefault(cf => cf.TrashId.EqualsIgnoreCase(trashId));
if (match == null)
{
CustomFormatsNotInGuide.Add(trashId);
}
else
{
validCfs.Add(match);
}
}
ConfigData.Add(new ProcessedConfigData
{
QualityProfiles = singleConfig.QualityProfiles,
CustomFormats = validCfs
.DistinctBy(cf => cf.TrashId, StringComparer.InvariantCultureIgnoreCase)
.ToList()
});
}
}
private static ProcessedCustomFormatData? FindCustomFormatByName(
IReadOnlyCollection<ProcessedCustomFormatData> processedCfs, string name)
{
return processedCfs.FirstOrDefault(
cf => cf.CacheEntry?.CustomFormatName.EqualsIgnoreCase(name) ?? false) ??
processedCfs.FirstOrDefault(
cf => cf.Name.EqualsIgnoreCase(name));
}
}
}