Cardigann: add support for multiple paths

This commit is contained in:
kaso17 2017-02-17 19:48:13 +01:00
parent 95dad9d67e
commit 4cee32f75c
1 changed files with 334 additions and 287 deletions

View File

@ -127,6 +127,7 @@ namespace Jackett.Indexers
public class searchBlock
{
public string Path { get; set; }
public List<searchPathBlock> Paths { get; set; }
public List<filterBlock> Keywordsfilters { get; set; }
public Dictionary<string, string> Inputs { get; set; }
public rowsBlock Rows { get; set; }
@ -140,6 +141,12 @@ namespace Jackett.Indexers
public selectorBlock Dateheaders { get; set; }
}
public class searchPathBlock : requestBlock
{
public List<string> Categories { get; set; }
public bool Inheritinputs { get; set; } = true;
}
public class requestBlock
{
public string Path { get; set; }
@ -196,6 +203,20 @@ namespace Jackett.Indexers
if (Definition.Login != null && Definition.Login.Method == null)
Definition.Login.Method = "form";
if (Definition.Search.Paths == null)
{
Definition.Search.Paths = new List<searchPathBlock>();
}
// convert definitions with a single search Path to a Paths entry
if (Definition.Search.Path != null)
{
var legacySearchPath = new searchPathBlock();
legacySearchPath.Path = Definition.Search.Path;
legacySearchPath.Inputs = Definition.Search.Inputs;
Definition.Search.Paths.Add(legacySearchPath);
}
// init missing mandatory attributes
DisplayName = Definition.Name;
DisplayDescription = Definition.Description;
@ -1022,7 +1043,9 @@ namespace Jackett.Indexers
variables[".Query.TraktID"] = null;
variables[".Query.Episode"] = query.GetEpisodeSearchString();
variables[".Categories"] = MapTorznabCapsToTrackers(query);
var mappedCategories = MapTorznabCapsToTrackers(query);
variables[".Categories"] = mappedCategories;
var KeywordTokens = new List<string>();
var KeywordTokenKeys = new List<string> { "Q", "Series", "Movie", "Year" };
@ -1038,13 +1061,36 @@ namespace Jackett.Indexers
variables[".Query.Keywords"] = string.Join(" ", KeywordTokens);
variables[".Keywords"] = applyFilters((string)variables[".Query.Keywords"], Search.Keywordsfilters);
// TODO: prepare queries first and then send them parallel
var SearchPaths = Search.Paths;
foreach (var SearchPath in SearchPaths)
{
// skip path if categories don't match
if (SearchPath.Categories != null && mappedCategories.Count > 0)
{
var invertMatch = (SearchPath.Categories[0] == "!");
var hasIntersect = mappedCategories.Intersect(SearchPath.Categories).Any();
if (invertMatch)
hasIntersect = !hasIntersect;
if (!hasIntersect)
continue;
}
// build search URL
// HttpUtility.UrlPathEncode seems to only encode spaces, we use UrlEncode and replace + with %20 as a workaround
var searchUrl = resolvePath(applyGoTemplateText(Search.Path, variables, HttpUtility.UrlEncode).Replace("+", "%20") + "?").AbsoluteUri;
var searchUrl = resolvePath(applyGoTemplateText(SearchPath.Path, variables, HttpUtility.UrlEncode).Replace("+", "%20") + "?").AbsoluteUri;
var queryCollection = new NameValueCollection();
if (Search.Inputs != null)
var InputsList = new List<Dictionary<string, string>>();
if (SearchPath.Inheritinputs)
InputsList.Add(Search.Inputs);
InputsList.Add(SearchPath.Inputs);
foreach (var Inputs in InputsList)
{
foreach (var Input in Search.Inputs)
if (Inputs != null)
{
foreach (var Input in Inputs)
{
if (Input.Key == "$raw")
searchUrl += applyGoTemplateText(Input.Value, variables, HttpUtility.UrlEncode);
@ -1052,6 +1098,7 @@ namespace Jackett.Indexers
queryCollection.Add(Input.Key, applyGoTemplateText(Input.Value, variables));
}
}
}
if (queryCollection.Count > 0)
searchUrl += "&" + queryCollection.GetQueryString(Encoding);
@ -1352,7 +1399,7 @@ namespace Jackett.Indexers
{
OnParseError(results, ex);
}
}
return releases;
}