2017-04-15 08:45:10 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-02-21 12:07:54 +00:00
|
|
|
|
using System.Linq;
|
2015-07-28 23:10:04 +00:00
|
|
|
|
|
|
|
|
|
namespace Jackett.Models
|
|
|
|
|
{
|
2015-08-12 17:31:59 +00:00
|
|
|
|
public static partial class TorznabCatType
|
2015-07-28 23:10:04 +00:00
|
|
|
|
{
|
|
|
|
|
|
2017-02-21 12:07:54 +00:00
|
|
|
|
public static bool QueryContainsParentCategory(int[] queryCats, ICollection<int> releaseCats)
|
2015-07-28 23:10:04 +00:00
|
|
|
|
{
|
2017-02-21 12:07:54 +00:00
|
|
|
|
foreach (var releaseCat in releaseCats)
|
2015-07-28 23:10:04 +00:00
|
|
|
|
{
|
2017-02-21 12:07:54 +00:00
|
|
|
|
var cat = AllCats.FirstOrDefault(c => c.ID == releaseCat);
|
|
|
|
|
if (cat != null && queryCats != null)
|
|
|
|
|
{
|
|
|
|
|
return cat.SubCategories.Any(c => queryCats.Contains(c.ID));
|
2017-04-15 08:45:10 +00:00
|
|
|
|
}
|
2015-07-28 23:10:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetCatDesc(int newznabcat)
|
|
|
|
|
{
|
2015-08-12 17:31:59 +00:00
|
|
|
|
var cat = AllCats.FirstOrDefault(c => c.ID == newznabcat);
|
|
|
|
|
if (cat != null)
|
2015-07-28 23:10:04 +00:00
|
|
|
|
{
|
2015-08-12 17:31:59 +00:00
|
|
|
|
return cat.Name;
|
2015-07-28 23:10:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
|
public static string NormalizeCatName(string name)
|
|
|
|
|
{
|
|
|
|
|
return name.Replace(" ", "").ToLower();
|
2016-10-27 07:30:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TorznabCategory GetCatByName(string name)
|
|
|
|
|
{
|
|
|
|
|
var cat = AllCats.FirstOrDefault(c => NormalizeCatName(c.Name) == NormalizeCatName(name));
|
|
|
|
|
if (cat != null)
|
|
|
|
|
{
|
|
|
|
|
return cat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-28 23:10:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|