mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Fixed: (Caridgann) Custom headers in login and download blocks
This commit is contained in:
@@ -763,8 +763,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
return data;
|
||||
}
|
||||
|
||||
protected Dictionary<string, string> ParseCustomHeaders(Dictionary<string, List<string>> customHeaders,
|
||||
Dictionary<string, object> variables)
|
||||
protected Dictionary<string, string> ParseCustomHeaders(Dictionary<string, List<string>> customHeaders, Dictionary<string, object> variables)
|
||||
{
|
||||
if (customHeaders == null)
|
||||
{
|
||||
|
@@ -102,6 +102,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
public List<ErrorBlock> Error { get; set; }
|
||||
public PageTestBlock Test { get; set; }
|
||||
public CaptchaBlock Captcha { get; set; }
|
||||
public Dictionary<string, List<string>> Headers { get; set; }
|
||||
}
|
||||
|
||||
public class ErrorBlock
|
||||
@@ -182,6 +183,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
public string Method { get; set; }
|
||||
public BeforeBlock Before { get; set; }
|
||||
public InfohashBlock Infohash { get; set; }
|
||||
public Dictionary<string, List<string>> Headers { get; set; }
|
||||
}
|
||||
|
||||
public class InfohashBlock
|
||||
|
@@ -193,6 +193,9 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
{
|
||||
var login = _definition.Login;
|
||||
|
||||
var variables = GetBaseTemplateVariables();
|
||||
var headers = ParseCustomHeaders(_definition.Login?.Headers ?? _definition.Search?.Headers, variables);
|
||||
|
||||
if (login.Method == "post")
|
||||
{
|
||||
var pairs = new Dictionary<string, string>();
|
||||
@@ -221,7 +224,15 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
requestBuilder.AddFormParameter(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
Cookies = null;
|
||||
if (login.Cookies != null)
|
||||
{
|
||||
Cookies = CookieUtil.CookieHeaderToDictionary(string.Join("; ", login.Cookies));
|
||||
}
|
||||
|
||||
var request = requestBuilder
|
||||
.SetCookies(Cookies ?? new Dictionary<string, string>())
|
||||
.SetHeaders(headers ?? new Dictionary<string, string>())
|
||||
.SetHeader("Referer", SiteLink)
|
||||
.WithRateLimit(_rateLimit.TotalSeconds)
|
||||
.Build();
|
||||
@@ -241,13 +252,9 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
var queryCollection = new NameValueCollection();
|
||||
var pairs = new Dictionary<string, string>();
|
||||
|
||||
var formSelector = login.Form;
|
||||
if (formSelector == null)
|
||||
{
|
||||
formSelector = "form";
|
||||
}
|
||||
var formSelector = login.Form ?? "form";
|
||||
|
||||
// landingResultDocument might not be initiated if the login is caused by a relogin during a query
|
||||
// landingResultDocument might not be initiated if the login is caused by a re-login during a query
|
||||
if (landingResultDocument == null)
|
||||
{
|
||||
await GetConfigurationForSetup(true);
|
||||
@@ -279,11 +286,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
continue;
|
||||
}
|
||||
|
||||
var value = input.GetAttribute("value");
|
||||
if (value == null)
|
||||
{
|
||||
value = "";
|
||||
}
|
||||
var value = input.GetAttribute("value") ?? "";
|
||||
|
||||
pairs[name] = value;
|
||||
}
|
||||
@@ -364,6 +367,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
|
||||
var request = requestBuilder
|
||||
.SetCookies(Cookies)
|
||||
.SetHeaders(headers ?? new Dictionary<string, string>())
|
||||
.SetHeader("Referer", loginUrl)
|
||||
.WithRateLimit(_rateLimit.TotalSeconds)
|
||||
.Build();
|
||||
@@ -406,7 +410,6 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
var enctype = form.GetAttribute("enctype");
|
||||
if (enctype == "multipart/form-data")
|
||||
{
|
||||
var headers = new Dictionary<string, string>();
|
||||
var boundary = "---------------------------" + DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds.ToString().Replace(".", "");
|
||||
var bodyParts = new List<string>();
|
||||
|
||||
@@ -437,13 +440,9 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
requestBuilder.AddFormParameter(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
foreach (var header in headers)
|
||||
{
|
||||
requestBuilder.SetHeader(header.Key, header.Value);
|
||||
}
|
||||
|
||||
var request = requestBuilder
|
||||
.SetCookies(Cookies)
|
||||
.SetHeaders(headers ?? new Dictionary<string, string>())
|
||||
.SetHeader("Referer", SiteLink)
|
||||
.WithRateLimit(_rateLimit.TotalSeconds)
|
||||
.Build();
|
||||
@@ -470,6 +469,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
|
||||
var request = requestBuilder
|
||||
.SetCookies(Cookies)
|
||||
.SetHeaders(headers ?? new Dictionary<string, string>())
|
||||
.SetHeader("Referer", loginUrl)
|
||||
.WithRateLimit(_rateLimit.TotalSeconds)
|
||||
.Build();
|
||||
@@ -509,6 +509,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
};
|
||||
|
||||
var request = requestBuilder
|
||||
.SetHeaders(headers ?? new Dictionary<string, string>())
|
||||
.SetHeader("Referer", SiteLink)
|
||||
.WithRateLimit(_rateLimit.TotalSeconds)
|
||||
.Build();
|
||||
@@ -537,6 +538,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
};
|
||||
|
||||
var request = requestBuilder
|
||||
.SetHeaders(headers ?? new Dictionary<string, string>())
|
||||
.SetHeader("Referer", SiteLink)
|
||||
.WithRateLimit(_rateLimit.TotalSeconds)
|
||||
.Build();
|
||||
@@ -551,7 +553,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException("Login method " + login.Method + " not implemented");
|
||||
throw new NotImplementedException($"Login method {login.Method} not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,15 +598,11 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
return null;
|
||||
}
|
||||
|
||||
var variables = GetBaseTemplateVariables();
|
||||
var headers = ParseCustomHeaders(_definition.Login?.Headers ?? _definition.Search?.Headers, variables);
|
||||
|
||||
var loginUrl = ResolvePath(login.Path);
|
||||
|
||||
Cookies = null;
|
||||
|
||||
if (login.Cookies != null)
|
||||
{
|
||||
Cookies = CookieUtil.CookieHeaderToDictionary(string.Join("; ", login.Cookies));
|
||||
}
|
||||
|
||||
var requestBuilder = new HttpRequestBuilder(loginUrl.AbsoluteUri)
|
||||
{
|
||||
LogResponseContent = true,
|
||||
@@ -612,12 +610,15 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
Encoding = _encoding
|
||||
};
|
||||
|
||||
if (Cookies != null)
|
||||
Cookies = null;
|
||||
if (login.Cookies != null)
|
||||
{
|
||||
requestBuilder.SetCookies(Cookies);
|
||||
Cookies = CookieUtil.CookieHeaderToDictionary(string.Join("; ", login.Cookies));
|
||||
}
|
||||
|
||||
var request = requestBuilder
|
||||
.SetCookies(Cookies ?? new Dictionary<string, string>())
|
||||
.SetHeaders(headers ?? new Dictionary<string, string>())
|
||||
.SetHeader("Referer", SiteLink)
|
||||
.WithRateLimit(_rateLimit.TotalSeconds)
|
||||
.Build();
|
||||
@@ -653,6 +654,9 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
{
|
||||
var captcha = login.Captcha;
|
||||
|
||||
var variables = GetBaseTemplateVariables();
|
||||
var headers = ParseCustomHeaders(_definition.Login?.Headers ?? _definition.Search?.Headers, variables);
|
||||
|
||||
if (captcha.Type == "image")
|
||||
{
|
||||
var captchaElement = landingResultDocument.QuerySelector(captcha.Selector);
|
||||
@@ -663,6 +667,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
|
||||
var request = new HttpRequestBuilder(captchaUrl.ToString())
|
||||
.SetCookies(landingResult.GetCookies())
|
||||
.SetHeaders(headers ?? new Dictionary<string, string>())
|
||||
.SetHeader("Referer", loginUrl.AbsoluteUri)
|
||||
.SetEncoding(_encoding)
|
||||
.WithRateLimit(_rateLimit.TotalSeconds)
|
||||
@@ -757,8 +762,11 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
}
|
||||
}
|
||||
|
||||
var headers = ParseCustomHeaders(_definition.Download?.Headers ?? _definition.Search?.Headers, variables);
|
||||
|
||||
var httpRequest = httpRequestBuilder
|
||||
.SetCookies(Cookies ?? new Dictionary<string, string>())
|
||||
.SetHeaders(headers ?? new Dictionary<string, string>())
|
||||
.SetHeader("Referer", referer)
|
||||
.WithRateLimit(_rateLimit.TotalSeconds)
|
||||
.Build();
|
||||
@@ -773,11 +781,10 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
{
|
||||
Cookies = GetCookies();
|
||||
var method = HttpMethod.Get;
|
||||
var headers = new Dictionary<string, string>();
|
||||
|
||||
var variables = GetBaseTemplateVariables();
|
||||
AddTemplateVariablesFromUri(variables, link, ".DownloadUri");
|
||||
headers = ParseCustomHeaders(_definition.Search?.Headers, variables);
|
||||
var headers = ParseCustomHeaders(_definition.Download?.Headers ?? _definition.Search?.Headers, variables);
|
||||
|
||||
if (_definition.Download != null)
|
||||
{
|
||||
|
Reference in New Issue
Block a user