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.
41 lines
1.2 KiB
41 lines
1.2 KiB
using System.Linq;
|
|
using NLog;
|
|
using NzbDrone.Common.Instrumentation;
|
|
|
|
namespace NzbDrone.Core.Qualities
|
|
{
|
|
public static class QualityFinder
|
|
{
|
|
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(QualityFinder));
|
|
|
|
public static Quality FindBySourceAndResolution(QualitySource source, int resolution)
|
|
{
|
|
var matchingQuality = Quality.All.SingleOrDefault(q => q.Source == source && q.Resolution == resolution);
|
|
|
|
if (matchingQuality != null)
|
|
{
|
|
return matchingQuality;
|
|
}
|
|
|
|
var matchingResolution = Quality.All.Where(q => q.Resolution == resolution)
|
|
.OrderBy(q => q.Source)
|
|
.ToList();
|
|
|
|
var nearestQuality = Quality.Unknown;
|
|
|
|
foreach (var quality in matchingResolution)
|
|
{
|
|
if (quality.Source >= source)
|
|
{
|
|
nearestQuality = quality;
|
|
break;
|
|
}
|
|
}
|
|
|
|
Logger.Warn("Unable to find exact quality for {0} and {1}. Using {2} as fallback", source, resolution, nearestQuality);
|
|
|
|
return nearestQuality;
|
|
}
|
|
}
|
|
}
|