2019-06-14 03:54:25 +00:00
|
|
|
using System.Collections.Generic;
|
2014-11-24 00:07:46 +00:00
|
|
|
using System.Linq;
|
2019-06-14 03:54:25 +00:00
|
|
|
using NzbDrone.Core.CustomFormats;
|
|
|
|
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; }
|
2018-08-05 14:28:05 +00:00
|
|
|
public CustomFormat FormatCutoff { get; set; }
|
|
|
|
public List<ProfileFormatItem> FormatItems { get; set; }
|
2017-01-27 19:01:28 +00:00
|
|
|
public List<string> PreferredTags { get; set; }
|
2014-06-08 08:22:55 +00:00
|
|
|
public Language Language { 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public QualityIndex GetIndex(Quality quality)
|
|
|
|
{
|
|
|
|
return GetIndex(quality.Id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public QualityIndex GetIndex(int id)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return new QualityIndex(i, g);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new QualityIndex();
|
2014-11-24 00:07:46 +00:00
|
|
|
}
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
2014-11-24 00:07:46 +00:00
|
|
|
}
|