2019-06-14 03:54:25 +00:00
|
|
|
using System.Collections.Generic;
|
2014-11-24 00:07:46 +00:00
|
|
|
using System.Linq;
|
2020-01-22 21:47:33 +00:00
|
|
|
using NzbDrone.Core.CustomFormats;
|
2019-06-14 03:54:25 +00:00
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Languages;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Profiles
|
|
|
|
{
|
|
|
|
public class Profile : ModelBase
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
public Profile()
|
|
|
|
{
|
|
|
|
FormatItems = new List<ProfileFormatItem>();
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public string Name { get; set; }
|
2019-06-11 02:59:39 +00:00
|
|
|
public int Cutoff { get; set; }
|
2014-06-08 08:22:55 +00:00
|
|
|
public List<ProfileQualityItem> Items { get; set; }
|
2020-02-25 22:10:52 +00:00
|
|
|
public int MinFormatScore { get; set; }
|
|
|
|
public int CutoffFormatScore { get; set; }
|
2018-08-05 14:28:05 +00:00
|
|
|
public List<ProfileFormatItem> FormatItems { get; set; }
|
2014-06-08 08:22:55 +00:00
|
|
|
public Language Language { get; set; }
|
2019-06-19 02:50:17 +00:00
|
|
|
public bool UpgradeAllowed { get; set; }
|
2014-11-24 00:07:46 +00:00
|
|
|
|
|
|
|
public Quality LastAllowedQuality()
|
|
|
|
{
|
2019-06-11 02:59:39 +00:00
|
|
|
var lastAllowed = Items.Last(q => q.Allowed);
|
|
|
|
|
|
|
|
if (lastAllowed.Quality != null)
|
|
|
|
{
|
|
|
|
return lastAllowed.Quality;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returning any item from the group will work,
|
|
|
|
// returning the last because it's the true last quality.
|
|
|
|
return lastAllowed.Items.Last().Quality;
|
|
|
|
}
|
|
|
|
|
2020-08-29 05:12:43 +00:00
|
|
|
public QualityIndex GetIndex(Quality quality, bool respectGroupOrder = false)
|
2019-06-11 02:59:39 +00:00
|
|
|
{
|
2020-08-29 05:12:43 +00:00
|
|
|
return GetIndex(quality.Id, respectGroupOrder);
|
2019-06-11 02:59:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-29 05:12:43 +00:00
|
|
|
public QualityIndex GetIndex(int id, bool respectGroupOrder = false)
|
2019-06-11 02:59:39 +00:00
|
|
|
{
|
|
|
|
for (var i = 0; i < Items.Count; i++)
|
|
|
|
{
|
|
|
|
var item = Items[i];
|
|
|
|
var quality = item.Quality;
|
|
|
|
|
|
|
|
// Quality matches by ID
|
|
|
|
if (quality != null && quality.Id == id)
|
|
|
|
{
|
|
|
|
return new QualityIndex(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Group matches by ID
|
|
|
|
if (item.Id > 0 && item.Id == id)
|
|
|
|
{
|
|
|
|
return new QualityIndex(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var g = 0; g < item.Items.Count; g++)
|
|
|
|
{
|
|
|
|
var groupItem = item.Items[g];
|
|
|
|
|
|
|
|
if (groupItem.Quality.Id == id)
|
|
|
|
{
|
2020-08-29 05:12:43 +00:00
|
|
|
return respectGroupOrder ? new QualityIndex(i, g) : new QualityIndex(i);
|
2019-06-11 02:59:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new QualityIndex();
|
2014-11-24 00:07:46 +00:00
|
|
|
}
|
2020-01-22 21:47:33 +00:00
|
|
|
|
2020-02-25 22:10:52 +00:00
|
|
|
public int CalculateCustomFormatScore(List<CustomFormat> formats)
|
2020-01-22 21:47:33 +00:00
|
|
|
{
|
2020-02-25 22:10:52 +00:00
|
|
|
return FormatItems.Where(x => formats.Contains(x.Format)).Sum(x => x.Score);
|
2020-01-22 21:47:33 +00:00
|
|
|
}
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
2014-11-24 00:07:46 +00:00
|
|
|
}
|