mirror of
https://github.com/Jackett/Jackett.git
synced 2025-10-02 08:34:32 +02:00
Cardigann: Add support for POST search requests
This commit is contained in:
@@ -1165,8 +1165,14 @@ namespace Jackett.Indexers
|
|||||||
|
|
||||||
// build search URL
|
// build search URL
|
||||||
// HttpUtility.UrlPathEncode seems to only encode spaces, we use UrlEncode and replace + with %20 as a workaround
|
// HttpUtility.UrlPathEncode seems to only encode spaces, we use UrlEncode and replace + with %20 as a workaround
|
||||||
var searchUrl = resolvePath(applyGoTemplateText(SearchPath.Path, variables, HttpUtility.UrlEncode).Replace("+", "%20") + "?").AbsoluteUri;
|
var searchUrl = resolvePath(applyGoTemplateText(SearchPath.Path, variables, HttpUtility.UrlEncode).Replace("+", "%20")).AbsoluteUri;
|
||||||
var queryCollection = new NameValueCollection();
|
var queryCollection = new List<KeyValuePair<string, string>>();
|
||||||
|
RequestType method = RequestType.GET;
|
||||||
|
|
||||||
|
if (String.Equals(SearchPath.Method, "post", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
method = RequestType.POST;
|
||||||
|
}
|
||||||
|
|
||||||
var InputsList = new List<Dictionary<string, string>>();
|
var InputsList = new List<Dictionary<string, string>>();
|
||||||
if (SearchPath.Inheritinputs)
|
if (SearchPath.Inheritinputs)
|
||||||
@@ -1180,20 +1186,38 @@ namespace Jackett.Indexers
|
|||||||
foreach (var Input in Inputs)
|
foreach (var Input in Inputs)
|
||||||
{
|
{
|
||||||
if (Input.Key == "$raw")
|
if (Input.Key == "$raw")
|
||||||
searchUrl += applyGoTemplateText(Input.Value, variables, HttpUtility.UrlEncode);
|
{
|
||||||
|
var rawStr = applyGoTemplateText(Input.Value, variables, HttpUtility.UrlEncode);
|
||||||
|
foreach (string part in rawStr.Split('&'))
|
||||||
|
{
|
||||||
|
var parts = part.Split(new char[] { '=' }, 2);
|
||||||
|
var key = parts[0];
|
||||||
|
if (key.Length == 0)
|
||||||
|
continue;
|
||||||
|
var value = "";
|
||||||
|
if (parts.Count() == 2)
|
||||||
|
value = parts[1];
|
||||||
|
queryCollection.Add(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
queryCollection.Add(Input.Key, applyGoTemplateText(Input.Value, variables));
|
queryCollection.Add(Input.Key, applyGoTemplateText(Input.Value, variables));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (queryCollection.Count > 0)
|
|
||||||
searchUrl += "&" + queryCollection.GetQueryString(Encoding);
|
|
||||||
|
|
||||||
// in case no args are added remove ? again (needed for KAT)
|
if (method == RequestType.GET)
|
||||||
searchUrl = searchUrl.TrimEnd('?');
|
{
|
||||||
|
if (queryCollection.Count > 0)
|
||||||
|
searchUrl += "?" + queryCollection.GetQueryString(Encoding);
|
||||||
|
}
|
||||||
|
|
||||||
// send HTTP request
|
// send HTTP request
|
||||||
var response = await RequestStringWithCookies(searchUrl);
|
WebClientStringResult response = null;
|
||||||
|
if (method == RequestType.POST)
|
||||||
|
response = await PostDataWithCookies(searchUrl, queryCollection);
|
||||||
|
else
|
||||||
|
response = await RequestStringWithCookies(searchUrl);
|
||||||
var results = response.Content;
|
var results = response.Content;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1209,13 +1233,17 @@ namespace Jackett.Indexers
|
|||||||
if (!LoginResult)
|
if (!LoginResult)
|
||||||
throw new Exception(string.Format("Relogin failed"));
|
throw new Exception(string.Format("Relogin failed"));
|
||||||
await TestLogin();
|
await TestLogin();
|
||||||
response = await RequestStringWithCookies(searchUrl);
|
if (method == RequestType.POST)
|
||||||
|
response = await PostDataWithCookies(searchUrl, queryCollection);
|
||||||
|
else
|
||||||
|
response = await RequestStringWithCookies(searchUrl);
|
||||||
results = response.Content;
|
results = response.Content;
|
||||||
SearchResultDocument = SearchResultParser.Parse(results);
|
SearchResultDocument = SearchResultParser.Parse(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForError(response, Definition.Search.Error);
|
checkForError(response, Definition.Search.Error);
|
||||||
|
|
||||||
|
|
||||||
var RowsDom = SearchResultDocument.QuerySelectorAll(Search.Rows.Selector);
|
var RowsDom = SearchResultDocument.QuerySelectorAll(Search.Rows.Selector);
|
||||||
List<IElement> Rows = new List<IElement>();
|
List<IElement> Rows = new List<IElement>();
|
||||||
foreach (var RowDom in RowsDom)
|
foreach (var RowDom in RowsDom)
|
||||||
|
Reference in New Issue
Block a user