2015-07-29 19:30:28 +00:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using System;
|
2015-07-19 23:05:30 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Jackett.Models
|
|
|
|
|
{
|
|
|
|
|
public class TorznabCapabilities
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public bool SearchAvailable { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool TVSearchAvailable { get; set; }
|
|
|
|
|
|
2017-01-16 16:23:19 +00:00
|
|
|
|
public bool MovieSearchAvailable { get; set; }
|
|
|
|
|
|
2015-07-19 23:05:30 +00:00
|
|
|
|
public bool SupportsTVRageSearch { get; set; }
|
|
|
|
|
|
2017-01-16 16:23:19 +00:00
|
|
|
|
public bool SupportsImdbSearch { get; set; }
|
|
|
|
|
|
2015-07-19 23:05:30 +00:00
|
|
|
|
public List<TorznabCategory> Categories { get; private set; }
|
|
|
|
|
|
|
|
|
|
public TorznabCapabilities()
|
|
|
|
|
{
|
|
|
|
|
Categories = new List<TorznabCategory>();
|
2015-07-29 17:47:51 +00:00
|
|
|
|
SearchAvailable = true;
|
|
|
|
|
TVSearchAvailable = true;
|
2017-01-16 16:23:19 +00:00
|
|
|
|
MovieSearchAvailable = false;
|
2015-07-29 17:47:51 +00:00
|
|
|
|
SupportsTVRageSearch = false;
|
2017-01-16 16:23:19 +00:00
|
|
|
|
SupportsImdbSearch = false;
|
2015-07-19 23:05:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-27 00:03:51 +00:00
|
|
|
|
public TorznabCapabilities(params TorznabCategory[] cats)
|
|
|
|
|
{
|
2015-07-29 17:47:51 +00:00
|
|
|
|
SearchAvailable = true;
|
|
|
|
|
TVSearchAvailable = true;
|
|
|
|
|
SupportsTVRageSearch = false;
|
2017-01-16 16:23:19 +00:00
|
|
|
|
SupportsImdbSearch = false;
|
2015-07-27 00:03:51 +00:00
|
|
|
|
Categories = new List<TorznabCategory>();
|
|
|
|
|
Categories.AddRange(cats);
|
2017-01-16 16:23:19 +00:00
|
|
|
|
MovieSearchAvailable = Categories.Any(i => TorznabCatType.Movies.Contains(i));
|
2015-07-27 00:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 23:05:30 +00:00
|
|
|
|
string SupportedTVSearchParams
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var parameters = new List<string>() { "q", "season", "ep" };
|
|
|
|
|
if (SupportsTVRageSearch)
|
|
|
|
|
parameters.Add("rid");
|
|
|
|
|
return string.Join(",", parameters);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-16 16:23:19 +00:00
|
|
|
|
string SupportedMovieSearchParams
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var parameters = new List<string>() { "q" };
|
|
|
|
|
if (SupportsImdbSearch)
|
|
|
|
|
parameters.Add("imdbid");
|
|
|
|
|
return string.Join(",", parameters);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-14 08:38:51 +00:00
|
|
|
|
public bool SupportsCategories(int[] categories)
|
2017-05-14 16:55:36 +00:00
|
|
|
|
{
|
2017-08-14 08:38:51 +00:00
|
|
|
|
var subCategories = Categories.SelectMany(c => c.SubCategories);
|
|
|
|
|
var allCategories = Categories.Concat(subCategories);
|
|
|
|
|
var supportsCategory = allCategories.Any(i => categories.Any(c => c == i.ID));
|
|
|
|
|
return supportsCategory;
|
2017-05-14 16:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-29 19:30:28 +00:00
|
|
|
|
public JArray CapsToJson()
|
|
|
|
|
{
|
|
|
|
|
var jArray = new JArray();
|
2017-08-14 08:38:51 +00:00
|
|
|
|
foreach (var cat in Categories.GroupBy(p => p.ID).Select(g => g.First()).OrderBy(c => c.ID < 100000 ? "z" + c.ID.ToString() : c.Name))
|
2015-07-29 19:30:28 +00:00
|
|
|
|
{
|
|
|
|
|
jArray.Add(cat.ToJson());
|
|
|
|
|
}
|
|
|
|
|
return jArray;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 23:05:30 +00:00
|
|
|
|
public string ToXml()
|
|
|
|
|
{
|
|
|
|
|
var xdoc = new XDocument(
|
|
|
|
|
new XDeclaration("1.0", "UTF-8", null),
|
|
|
|
|
new XElement("caps",
|
2017-08-17 07:22:04 +00:00
|
|
|
|
new XElement("server",
|
|
|
|
|
new XAttribute("title", "Jackett")
|
|
|
|
|
),
|
2015-07-19 23:05:30 +00:00
|
|
|
|
new XElement("searching",
|
|
|
|
|
new XElement("search",
|
|
|
|
|
new XAttribute("available", SearchAvailable ? "yes" : "no"),
|
|
|
|
|
new XAttribute("supportedParams", "q")
|
|
|
|
|
),
|
|
|
|
|
new XElement("tv-search",
|
|
|
|
|
new XAttribute("available", TVSearchAvailable ? "yes" : "no"),
|
|
|
|
|
new XAttribute("supportedParams", SupportedTVSearchParams)
|
2017-01-16 16:23:19 +00:00
|
|
|
|
),
|
|
|
|
|
new XElement("movie-search",
|
|
|
|
|
new XAttribute("available", MovieSearchAvailable ? "yes" : "no"),
|
|
|
|
|
new XAttribute("supportedParams", SupportedMovieSearchParams)
|
2015-07-19 23:05:30 +00:00
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
new XElement("categories",
|
2017-02-21 12:07:54 +00:00
|
|
|
|
from c in Categories.OrderBy(x => x.ID < 100000 ? "z" + x.ID.ToString() : x.Name)
|
2015-07-19 23:05:30 +00:00
|
|
|
|
select new XElement("category",
|
|
|
|
|
new XAttribute("id", c.ID),
|
|
|
|
|
new XAttribute("name", c.Name),
|
|
|
|
|
from sc in c.SubCategories
|
|
|
|
|
select new XElement("subcat",
|
|
|
|
|
new XAttribute("id", sc.ID),
|
|
|
|
|
new XAttribute("name", sc.Name)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return xdoc.Declaration.ToString() + Environment.NewLine + xdoc.ToString();
|
|
|
|
|
}
|
2017-06-03 13:04:51 +00:00
|
|
|
|
public static TorznabCapabilities Concat(TorznabCapabilities lhs, TorznabCapabilities rhs)
|
2017-05-14 16:55:36 +00:00
|
|
|
|
{
|
|
|
|
|
lhs.SearchAvailable = lhs.SearchAvailable || rhs.SearchAvailable;
|
|
|
|
|
lhs.TVSearchAvailable = lhs.TVSearchAvailable || rhs.TVSearchAvailable;
|
|
|
|
|
lhs.MovieSearchAvailable = lhs.MovieSearchAvailable || rhs.MovieSearchAvailable;
|
|
|
|
|
lhs.SupportsTVRageSearch = lhs.SupportsTVRageSearch || rhs.SupportsTVRageSearch;
|
|
|
|
|
lhs.SupportsImdbSearch = lhs.SupportsImdbSearch || rhs.SupportsImdbSearch;
|
2017-08-14 08:38:51 +00:00
|
|
|
|
lhs.Categories.AddRange(rhs.Categories.Except(lhs.Categories));
|
2017-05-14 16:55:36 +00:00
|
|
|
|
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
2015-07-19 23:05:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|