mirror of https://github.com/Jackett/Jackett
Cardigann: add Keywordsfilters and before download feature
This commit is contained in:
parent
4a04e5694f
commit
f1fa8c131a
|
@ -357,14 +357,14 @@ namespace Jackett.Indexers
|
||||||
return response.Content;
|
return response.Content;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task<WebClientByteResult> RequestBytesWithCookiesAndRetry(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null)
|
protected async Task<WebClientByteResult> RequestBytesWithCookiesAndRetry(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null, IEnumerable<KeyValuePair<string, string>> data = null)
|
||||||
{
|
{
|
||||||
Exception lastException = null;
|
Exception lastException = null;
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return await RequestBytesWithCookies(url, cookieOverride, method, referer);
|
return await RequestBytesWithCookies(url, cookieOverride, method, referer, data);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -416,13 +416,14 @@ namespace Jackett.Indexers
|
||||||
throw lastException;
|
throw lastException;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task<WebClientByteResult> RequestBytesWithCookies(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null)
|
protected async Task<WebClientByteResult> RequestBytesWithCookies(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null, IEnumerable<KeyValuePair<string, string>> data = null)
|
||||||
{
|
{
|
||||||
var request = new Utils.Clients.WebRequest()
|
var request = new Utils.Clients.WebRequest()
|
||||||
{
|
{
|
||||||
Url = url,
|
Url = url,
|
||||||
Type = method,
|
Type = method,
|
||||||
Cookies = cookieOverride ?? CookieHeader,
|
Cookies = cookieOverride ?? CookieHeader,
|
||||||
|
PostData = data,
|
||||||
Referer = referer,
|
Referer = referer,
|
||||||
Encoding = Encoding
|
Encoding = Encoding
|
||||||
};
|
};
|
||||||
|
|
|
@ -124,6 +124,7 @@ namespace Jackett.Indexers
|
||||||
public class searchBlock
|
public class searchBlock
|
||||||
{
|
{
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
|
public List<filterBlock> Keywordsfilters { get; set; }
|
||||||
public Dictionary<string, string> Inputs { get; set; }
|
public Dictionary<string, string> Inputs { get; set; }
|
||||||
public rowsBlock Rows { get; set; }
|
public rowsBlock Rows { get; set; }
|
||||||
public Dictionary<string, selectorBlock> Fields { get; set; }
|
public Dictionary<string, selectorBlock> Fields { get; set; }
|
||||||
|
@ -136,10 +137,18 @@ namespace Jackett.Indexers
|
||||||
public selectorBlock Dateheaders { get; set; }
|
public selectorBlock Dateheaders { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class requestBlock
|
||||||
|
{
|
||||||
|
public string Path { get; set; }
|
||||||
|
public string Method { get; set; }
|
||||||
|
public Dictionary<string, string> Inputs { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class downloadBlock
|
public class downloadBlock
|
||||||
{
|
{
|
||||||
public string Selector { get; set; }
|
public string Selector { get; set; }
|
||||||
public string Method { get; set; }
|
public string Method { get; set; }
|
||||||
|
public requestBlock Before { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected readonly string[] OptionalFileds = new string[] { "imdb", "rageid", "tvdbid", "banner" };
|
protected readonly string[] OptionalFileds = new string[] { "imdb", "rageid", "tvdbid", "banner" };
|
||||||
|
@ -933,7 +942,7 @@ namespace Jackett.Indexers
|
||||||
if (!string.IsNullOrWhiteSpace((string)variables[".Query.Episode"]))
|
if (!string.IsNullOrWhiteSpace((string)variables[".Query.Episode"]))
|
||||||
KeywordTokens.Add((string)variables[".Query.Episode"]);
|
KeywordTokens.Add((string)variables[".Query.Episode"]);
|
||||||
variables[".Query.Keywords"] = string.Join(" ", KeywordTokens);
|
variables[".Query.Keywords"] = string.Join(" ", KeywordTokens);
|
||||||
variables[".Keywords"] = variables[".Query.Keywords"];
|
variables[".Keywords"] = applyFilters((string)variables[".Query.Keywords"], Search.Keywordsfilters);
|
||||||
|
|
||||||
// build search URL
|
// build search URL
|
||||||
var searchUrl = resolvePath(applyGoTemplateText(Search.Path, variables) + "?").ToString();
|
var searchUrl = resolvePath(applyGoTemplateText(Search.Path, variables) + "?").ToString();
|
||||||
|
@ -1211,12 +1220,71 @@ namespace Jackett.Indexers
|
||||||
return releases;
|
return releases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async Task<WebClientByteResult> handleRequest(requestBlock request, Dictionary<string, object> variables = null, string referer = null)
|
||||||
|
{
|
||||||
|
var requestLinkStr = resolvePath(applyGoTemplateText(request.Path, variables)).ToString();
|
||||||
|
|
||||||
|
Dictionary<string, string> pairs = null;
|
||||||
|
var queryCollection = new NameValueCollection();
|
||||||
|
|
||||||
|
RequestType method = RequestType.GET;
|
||||||
|
if (String.Equals(request.Method, "post", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
method = RequestType.POST;
|
||||||
|
pairs = new Dictionary<string, string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var Input in request.Inputs)
|
||||||
|
{
|
||||||
|
var value = applyGoTemplateText(Input.Value, variables);
|
||||||
|
if (method == RequestType.GET)
|
||||||
|
queryCollection.Add(Input.Key, value);
|
||||||
|
else if (method == RequestType.POST)
|
||||||
|
pairs.Add(Input.Key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queryCollection.Count > 0)
|
||||||
|
{
|
||||||
|
if (!requestLinkStr.Contains("?"))
|
||||||
|
requestLinkStr += "?" + queryCollection.GetQueryString(Encoding).Substring(1);
|
||||||
|
else
|
||||||
|
requestLinkStr += queryCollection.GetQueryString(Encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = await RequestBytesWithCookiesAndRetry(requestLinkStr, null, method, referer, pairs);
|
||||||
|
logger.Debug($"CardigannIndexer ({ID}): handleRequest() remote server returned {response.Status.ToString()}" + (response.IsRedirect ? " => " + response.RedirectingTo : ""));
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IDictionary<string, object> AddTemplateVariablesFromUri(IDictionary<string, object> variables, Uri uri, string prefix = "")
|
||||||
|
{
|
||||||
|
variables[prefix + ".AbsoluteUri"] = uri.AbsoluteUri;
|
||||||
|
variables[prefix + ".AbsolutePath"] = uri.AbsolutePath;
|
||||||
|
variables[prefix + ".Scheme"] = uri.Scheme;
|
||||||
|
variables[prefix + ".Host"] = uri.Host;
|
||||||
|
variables[prefix + ".Port"] = uri.Port.ToString();
|
||||||
|
variables[prefix + ".PathAndQuery"] = uri.PathAndQuery;
|
||||||
|
variables[prefix + ".Query"] = uri.Query;
|
||||||
|
var queryString = HttpUtility.ParseQueryString(uri.Query);
|
||||||
|
foreach (string key in queryString.Keys)
|
||||||
|
{
|
||||||
|
variables[prefix + ".Query." + key] = queryString.Get(key);
|
||||||
|
}
|
||||||
|
return variables;
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<byte[]> Download(Uri link)
|
||||||
{
|
{
|
||||||
var method = RequestType.GET;
|
var method = RequestType.GET;
|
||||||
if (Definition.Download != null)
|
if (Definition.Download != null)
|
||||||
{
|
{
|
||||||
var Download = Definition.Download;
|
var Download = Definition.Download;
|
||||||
|
if (Download.Before != null)
|
||||||
|
{
|
||||||
|
var beforeVariables = getTemplateVariablesFromConfigData();
|
||||||
|
AddTemplateVariablesFromUri(beforeVariables, link, ".DownloadUri");
|
||||||
|
var beforeresult = await handleRequest(Download.Before, beforeVariables, link.ToString());
|
||||||
|
}
|
||||||
if (Download.Method != null)
|
if (Download.Method != null)
|
||||||
{
|
{
|
||||||
if (Download.Method == "post")
|
if (Download.Method == "post")
|
||||||
|
|
Loading…
Reference in New Issue