1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-27 22:57:09 -04:00

New: Calculate custom formats on demand

This commit is contained in:
ta264
2020-01-22 21:47:33 +00:00
parent 13701498ce
commit df101258c5
103 changed files with 1901 additions and 1346 deletions
@@ -1,12 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Profiles;
namespace NzbDrone.Core.Qualities
{
public class QualityModelComparer : IComparer<Quality>, IComparer<QualityModel>, IComparer<CustomFormat>, IComparer<List<CustomFormat>>
public class QualityModelComparer : IComparer<Quality>, IComparer<QualityModel>
{
private readonly Profile _profile;
@@ -50,49 +48,10 @@ namespace NzbDrone.Core.Qualities
if (result == 0)
{
result = Compare(left.CustomFormats, right.CustomFormats);
if (result == 0)
{
result = left.Revision.CompareTo(right.Revision);
}
result = left.Revision.CompareTo(right.Revision);
}
return result;
}
public int Compare(List<CustomFormat> left, List<CustomFormat> right)
{
List<int> leftIndicies = GetIndicies(left, _profile);
List<int> rightIndicies = GetIndicies(right, _profile);
int leftTotal = leftIndicies.Sum();
int rightTotal = rightIndicies.Sum();
return leftTotal.CompareTo(rightTotal);
}
public static List<int> GetIndicies(List<CustomFormat> formats, Profile profile)
{
return formats.WithNone().Select(f => profile.FormatItems.FindIndex(v => Equals(v.Format, f))).ToList();
}
public int Compare(CustomFormat left, CustomFormat right)
{
var leftIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format, left));
var rightIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format, right));
return leftIndex.CompareTo(rightIndex);
}
public int Compare(List<CustomFormat> left, int right)
{
left = left.WithNone();
var leftIndicies = GetIndicies(left, _profile);
var rightIndex = _profile.FormatItems.FindIndex(v => Equals(v.Format.Id, right));
return leftIndicies.Select(i => i.CompareTo(rightIndex)).Max();
}
}
}