Improved Quality lookup.

This commit is contained in:
Taloth Saldono 2016-07-25 23:43:06 +02:00
parent 1218dd255f
commit 6f2dd5d2fa
1 changed files with 48 additions and 44 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Qualities
@ -72,15 +73,13 @@ namespace NzbDrone.Core.Qualities
//public static Quality WEBRip720p { get { return new Quality(14, "WEBRip-720p"); } }
//public static Quality WEBRip1080p { get { return new Quality(15, "WEBRip-1080p"); } }
public static Quality HDTV2160p { get { return new Quality(16, "HDTV-2160p"); } }
//public static Quality WEBRip2160p { get { return new Quality(17, "WEBRip-1080p"); } }
//public static Quality WEBRip2160p { get { return new Quality(17, "WEBRip-2160p"); } }
public static Quality WEBDL2160p { get { return new Quality(18, "WEBDL-2160p"); } }
public static Quality Bluray2160p { get { return new Quality(19, "Bluray-2160p"); } }
public static List<Quality> All
static Quality()
{
get
{
return new List<Quality>
All = new List<Quality>
{
Unknown,
SDTV,
@ -97,14 +96,14 @@ namespace NzbDrone.Core.Qualities
WEBDL2160p,
Bluray2160p,
};
}
AllLookup = new Quality[All.Select(v => v.Id).Max() + 1];
foreach (var quality in All)
{
AllLookup[quality.Id] = quality;
}
public static HashSet<QualityDefinition> DefaultQualityDefinitions
{
get
{
return new HashSet<QualityDefinition>
DefaultQualityDefinitions = new HashSet<QualityDefinition>
{
new QualityDefinition(Quality.Unknown) { Weight = 1, MinSize = 0, MaxSize = 100 },
new QualityDefinition(Quality.SDTV) { Weight = 2, MinSize = 0, MaxSize = 100 },
@ -122,13 +121,18 @@ namespace NzbDrone.Core.Qualities
new QualityDefinition(Quality.Bluray2160p) { Weight = 14, MinSize = 0, MaxSize = null },
};
}
}
public static readonly List<Quality> All;
public static readonly Quality[] AllLookup;
public static readonly HashSet<QualityDefinition> DefaultQualityDefinitions;
public static Quality FindById(int id)
{
if (id == 0) return Unknown;
Quality quality = All.FirstOrDefault(v => v.Id == id);
var quality = AllLookup[id];
if (quality == null)
throw new ArgumentException("ID does not match a known quality", "id");