2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2015-07-19 23:05:30 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Models
|
2015-07-19 23:05:30 +00:00
|
|
|
{
|
2020-10-18 20:47:36 +00:00
|
|
|
public enum TvSearchParam
|
|
|
|
{
|
|
|
|
Q,
|
|
|
|
Season,
|
|
|
|
Ep,
|
|
|
|
ImdbId,
|
|
|
|
TvdbId,
|
|
|
|
RId,
|
|
|
|
}
|
|
|
|
|
2020-10-18 17:26:22 +00:00
|
|
|
public enum MovieSearchParam
|
|
|
|
{
|
|
|
|
Q,
|
|
|
|
ImdbId,
|
|
|
|
TmdbId
|
|
|
|
}
|
|
|
|
|
2015-07-19 23:05:30 +00:00
|
|
|
public class TorznabCapabilities
|
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
public int? LimitsMax { get; set; }
|
|
|
|
public int? LimitsDefault { get; set; }
|
2015-07-19 23:05:30 +00:00
|
|
|
|
|
|
|
public bool SearchAvailable { get; set; }
|
|
|
|
|
2020-10-18 20:47:36 +00:00
|
|
|
public List<TvSearchParam> TvSearchParams;
|
|
|
|
public bool TvSearchAvailable => (TvSearchParams.Count > 0);
|
|
|
|
public bool TvSearchSeasonAvailable => (TvSearchParams.Contains(TvSearchParam.Season));
|
|
|
|
public bool TvSearchEpAvailable => (TvSearchParams.Contains(TvSearchParam.Ep));
|
|
|
|
//TvSearchImdbAvailable temporarily disabled due to #8107
|
|
|
|
public bool TvSearchImdbAvailable => false; // (TvSearchParams.Contains(TvSearchParam.ImdbId));
|
|
|
|
public bool TvSearchTvdbAvailable => (TvSearchParams.Contains(TvSearchParam.TvdbId));
|
|
|
|
public bool TvSearchTvRageAvailable => (TvSearchParams.Contains(TvSearchParam.RId));
|
2020-01-09 03:32:02 +00:00
|
|
|
|
2020-10-18 17:26:22 +00:00
|
|
|
public List<MovieSearchParam> MovieSearchParams;
|
|
|
|
public bool MovieSearchAvailable => (MovieSearchParams.Count > 0);
|
|
|
|
public bool MovieSearchImdbAvailable => (MovieSearchParams.Contains(MovieSearchParam.ImdbId));
|
|
|
|
public bool MovieSearchTmdbAvailable => (MovieSearchParams.Contains(MovieSearchParam.TmdbId));
|
2017-10-18 16:30:41 +00:00
|
|
|
|
|
|
|
public List<string> SupportedMusicSearchParamsList;
|
2020-10-18 17:26:22 +00:00
|
|
|
public bool MusicSearchAvailable => (SupportedMusicSearchParamsList.Count > 0);
|
2017-10-18 16:30:41 +00:00
|
|
|
|
2020-08-16 21:44:12 +00:00
|
|
|
public bool BookSearchAvailable { get; set; }
|
|
|
|
|
2015-07-19 23:05:30 +00:00
|
|
|
public List<TorznabCategory> Categories { get; private set; }
|
|
|
|
|
|
|
|
public TorznabCapabilities()
|
|
|
|
{
|
2015-07-29 17:47:51 +00:00
|
|
|
SearchAvailable = true;
|
2020-10-18 20:47:36 +00:00
|
|
|
TvSearchParams = new List<TvSearchParam>();
|
2020-10-18 17:26:22 +00:00
|
|
|
MovieSearchParams = new List<MovieSearchParam>();
|
2017-10-18 16:30:41 +00:00
|
|
|
SupportedMusicSearchParamsList = new List<string>();
|
2020-08-16 21:44:12 +00:00
|
|
|
BookSearchAvailable = false;
|
2015-07-27 00:03:51 +00:00
|
|
|
Categories = new List<TorznabCategory>();
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:47:36 +00:00
|
|
|
public void ParseTvSearchParams(IEnumerable<string> paramsList)
|
2015-07-19 23:05:30 +00:00
|
|
|
{
|
2020-10-18 20:47:36 +00:00
|
|
|
if (paramsList == null)
|
|
|
|
return;
|
|
|
|
foreach (var paramStr in paramsList)
|
|
|
|
if (Enum.TryParse(paramStr, true, out TvSearchParam param))
|
|
|
|
if (!TvSearchParams.Contains(param))
|
|
|
|
TvSearchParams.Add(param);
|
|
|
|
else
|
|
|
|
throw new Exception($"Duplicate tv-search param: {paramStr}");
|
|
|
|
else
|
|
|
|
throw new Exception($"Not supported tv-search param: {paramStr}");
|
2015-07-19 23:05:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 17:26:22 +00:00
|
|
|
public void ParseMovieSearchParams(IEnumerable<string> paramsList)
|
2017-01-16 16:23:19 +00:00
|
|
|
{
|
2020-10-18 17:26:22 +00:00
|
|
|
if (paramsList == null)
|
|
|
|
return;
|
|
|
|
foreach (var paramStr in paramsList)
|
|
|
|
if (Enum.TryParse(paramStr, true, out MovieSearchParam param))
|
|
|
|
if (!MovieSearchParams.Contains(param))
|
|
|
|
MovieSearchParams.Add(param);
|
|
|
|
else
|
|
|
|
throw new Exception($"Duplicate movie-search param: {paramStr}");
|
|
|
|
else
|
|
|
|
throw new Exception($"Not supported movie-search param: {paramStr}");
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:47:36 +00:00
|
|
|
private string SupportedTvSearchParams()
|
|
|
|
{
|
|
|
|
var parameters = new List<string> { "q" }; // q is always enabled
|
|
|
|
if (TvSearchSeasonAvailable)
|
|
|
|
parameters.Add("season");
|
|
|
|
if (TvSearchEpAvailable)
|
|
|
|
parameters.Add("ep");
|
|
|
|
if (TvSearchImdbAvailable)
|
|
|
|
parameters.Add("imdbid");
|
|
|
|
if (TvSearchTvdbAvailable)
|
|
|
|
parameters.Add("tvdbid");
|
|
|
|
if (TvSearchTvRageAvailable)
|
|
|
|
parameters.Add("rid");
|
|
|
|
return string.Join(",", parameters);
|
|
|
|
}
|
|
|
|
|
2020-10-18 17:26:22 +00:00
|
|
|
private string SupportedMovieSearchParams()
|
|
|
|
{
|
2020-10-18 20:47:36 +00:00
|
|
|
var parameters = new List<string> { "q" }; // q is always enabled
|
2020-10-18 17:26:22 +00:00
|
|
|
if (MovieSearchImdbAvailable)
|
|
|
|
parameters.Add("imdbid");
|
|
|
|
if (MovieSearchTmdbAvailable)
|
|
|
|
parameters.Add("tmdbid");
|
|
|
|
return string.Join(",", parameters);
|
2017-01-16 16:23:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
private string SupportedMusicSearchParams => string.Join(",", SupportedMusicSearchParamsList);
|
2017-10-18 16:30:41 +00:00
|
|
|
|
2020-08-16 21:44:12 +00:00
|
|
|
private string SupportedBookSearchParams
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var parameters = new List<string>() { "q" };
|
|
|
|
if (BookSearchAvailable)
|
|
|
|
parameters.Add("author,title");
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-04-06 15:43:18 +00:00
|
|
|
public XDocument GetXDocument()
|
2015-07-19 23:05:30 +00:00
|
|
|
{
|
|
|
|
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")
|
|
|
|
),
|
2017-08-17 07:48:54 +00:00
|
|
|
LimitsMax != null || LimitsDefault != null ?
|
|
|
|
new XElement("limits",
|
|
|
|
LimitsMax != null ? new XAttribute("max", LimitsMax) : null,
|
|
|
|
LimitsDefault != null ? new XAttribute("default", LimitsDefault) : null
|
|
|
|
)
|
|
|
|
: null,
|
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",
|
2020-10-18 20:47:36 +00:00
|
|
|
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"),
|
2020-10-18 17:26:22 +00:00
|
|
|
new XAttribute("supportedParams", SupportedMovieSearchParams())
|
2017-10-18 16:30:41 +00:00
|
|
|
),
|
|
|
|
new XElement("music-search",
|
|
|
|
new XAttribute("available", MusicSearchAvailable ? "yes" : "no"),
|
2017-10-18 16:42:00 +00:00
|
|
|
new XAttribute("supportedParams", SupportedMusicSearchParams)
|
2017-10-23 16:02:53 +00:00
|
|
|
),
|
|
|
|
// inconsistend but apparently already used by various newznab indexers (see #1896)
|
|
|
|
new XElement("audio-search",
|
|
|
|
new XAttribute("available", MusicSearchAvailable ? "yes" : "no"),
|
|
|
|
new XAttribute("supportedParams", SupportedMusicSearchParams)
|
2020-08-16 21:44:12 +00:00
|
|
|
),
|
|
|
|
new XElement("book-search",
|
|
|
|
new XAttribute("available", BookSearchAvailable ? "yes" : "no"),
|
|
|
|
new XAttribute("supportedParams", SupportedBookSearchParams)
|
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)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2018-04-06 15:43:18 +00:00
|
|
|
return xdoc;
|
|
|
|
}
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
public string ToXml() =>
|
|
|
|
GetXDocument().Declaration + Environment.NewLine + GetXDocument();
|
2015-07-19 23:05:30 +00:00
|
|
|
|
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;
|
2020-10-18 20:47:36 +00:00
|
|
|
lhs.TvSearchParams = lhs.TvSearchParams.Union(rhs.TvSearchParams).ToList();
|
2020-10-18 17:26:22 +00:00
|
|
|
lhs.MovieSearchParams = lhs.MovieSearchParams.Union(rhs.MovieSearchParams).ToList();
|
|
|
|
// TODO: add music search
|
|
|
|
lhs.BookSearchAvailable = lhs.BookSearchAvailable || rhs.BookSearchAvailable;
|
2017-08-17 07:57:58 +00:00
|
|
|
lhs.Categories.AddRange(rhs.Categories.Where(x => x.ID < 100000).Except(lhs.Categories)); // exclude indexer specific categories (>= 100000)
|
2017-05-14 16:55:36 +00:00
|
|
|
return lhs;
|
|
|
|
}
|
2015-07-19 23:05:30 +00:00
|
|
|
}
|
|
|
|
}
|