mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-24 22:55:21 -04:00
New: Make indexer HTTP requests async
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Html.Parser;
|
||||
using FluentValidation;
|
||||
using NLog;
|
||||
@@ -44,7 +45,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
return new AnimeTorrentsParser(Settings, Capabilities.Categories, BaseUrl);
|
||||
}
|
||||
|
||||
protected override void DoLogin()
|
||||
protected override async Task DoLogin()
|
||||
{
|
||||
UpdateCookies(null, null);
|
||||
|
||||
@@ -54,7 +55,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
AllowAutoRedirect = true
|
||||
};
|
||||
|
||||
var loginPage = _httpClient.Execute(new HttpRequest(LoginUrl));
|
||||
var loginPage = await _httpClient.ExecuteAsync(new HttpRequest(LoginUrl));
|
||||
requestBuilder.Method = HttpMethod.POST;
|
||||
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
|
||||
requestBuilder.SetCookies(loginPage.GetCookies());
|
||||
@@ -67,7 +68,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
.SetHeader("Content-Type", "multipart/form-data")
|
||||
.Build();
|
||||
|
||||
var response = _httpClient.Execute(authLoginRequest);
|
||||
var response = await _httpClient.ExecuteAsync(authLoginRequest);
|
||||
|
||||
if (response.Content != null && response.Content.Contains("logout.php"))
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
@@ -52,9 +53,9 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
|
||||
return caps;
|
||||
}
|
||||
|
||||
protected override void DoLogin()
|
||||
protected override async Task DoLogin()
|
||||
{
|
||||
Settings.Token = GetToken();
|
||||
Settings.Token = await GetToken();
|
||||
|
||||
if (Definition.Id > 0)
|
||||
{
|
||||
@@ -74,11 +75,11 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override ValidationFailure TestConnection()
|
||||
protected override async Task<ValidationFailure> TestConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
GetToken();
|
||||
await GetToken();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -90,7 +91,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
|
||||
return null;
|
||||
}
|
||||
|
||||
private string GetToken()
|
||||
private async Task<string> GetToken()
|
||||
{
|
||||
var requestBuilder = new HttpRequestBuilder(LoginUrl)
|
||||
{
|
||||
@@ -108,7 +109,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
|
||||
.Accept(HttpAccept.Json)
|
||||
.Build();
|
||||
|
||||
var response = _httpClient.Post<AvistazAuthResponse>(authLoginRequest);
|
||||
var response = await _httpClient.PostAsync<AvistazAuthResponse>(authLoginRequest);
|
||||
var token = response.Resource.Token;
|
||||
|
||||
return token;
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Dom;
|
||||
using AngleSharp.Html.Parser;
|
||||
using FluentValidation;
|
||||
@@ -45,7 +46,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
return new BakaBTParser(Settings, Capabilities.Categories, BaseUrl);
|
||||
}
|
||||
|
||||
protected override void DoLogin()
|
||||
protected override async Task DoLogin()
|
||||
{
|
||||
UpdateCookies(null, null);
|
||||
|
||||
@@ -55,7 +56,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
AllowAutoRedirect = true
|
||||
};
|
||||
|
||||
var loginPage = _httpClient.Execute(new HttpRequest(LoginUrl));
|
||||
var loginPage = await _httpClient.ExecuteAsync(new HttpRequest(LoginUrl));
|
||||
|
||||
requestBuilder.Method = HttpMethod.POST;
|
||||
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
|
||||
@@ -77,7 +78,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
.SetHeader("Content-Type", "multipart/form-data")
|
||||
.Build();
|
||||
|
||||
var response = _httpClient.Execute(authLoginRequest);
|
||||
var response = await _httpClient.ExecuteAsync(authLoginRequest);
|
||||
|
||||
if (response.Content != null && response.Content.Contains("<a href=\"logout.php\">Logout</a>"))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
@@ -95,18 +96,18 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
return generator.CheckIfLoginIsNeeded(httpResponse);
|
||||
}
|
||||
|
||||
protected override void DoLogin()
|
||||
protected override async Task DoLogin()
|
||||
{
|
||||
var generator = (CardigannRequestGenerator)GetRequestGenerator();
|
||||
|
||||
SetCookieFunctions(generator);
|
||||
|
||||
generator.DoLogin();
|
||||
await generator.DoLogin();
|
||||
}
|
||||
|
||||
protected override void Test(List<ValidationFailure> failures)
|
||||
protected override async Task Test(List<ValidationFailure> failures)
|
||||
{
|
||||
base.Test(failures);
|
||||
await base.Test(failures);
|
||||
if (failures.HasErrors())
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Html.Dom;
|
||||
using AngleSharp.Html.Parser;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -157,7 +158,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
return variables;
|
||||
}
|
||||
|
||||
public void DoLogin()
|
||||
public async Task DoLogin()
|
||||
{
|
||||
var login = _definition.Login;
|
||||
|
||||
@@ -190,7 +191,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
|
||||
requestBuilder.Headers.Add("Referer", SiteLink);
|
||||
|
||||
var response = HttpClient.Execute(requestBuilder.Build());
|
||||
var response = await HttpClient.ExecuteAsync(requestBuilder.Build());
|
||||
|
||||
Cookies = response.GetCookies();
|
||||
|
||||
@@ -214,7 +215,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
// landingResultDocument might not be initiated if the login is caused by a relogin during a query
|
||||
if (landingResultDocument == null)
|
||||
{
|
||||
GetConfigurationForSetup(true);
|
||||
await GetConfigurationForSetup(true);
|
||||
}
|
||||
|
||||
var form = landingResultDocument.QuerySelector(formSelector);
|
||||
@@ -327,7 +328,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
|
||||
requestBuilder.Headers.Add("Referer", loginUrl);
|
||||
|
||||
var simpleCaptchaResult = HttpClient.Execute(requestBuilder.Build());
|
||||
var simpleCaptchaResult = await HttpClient.ExecuteAsync(requestBuilder.Build());
|
||||
|
||||
var simpleCaptchaJSON = JObject.Parse(simpleCaptchaResult.Content);
|
||||
var captchaSelection = simpleCaptchaJSON["images"][0]["hash"].ToString();
|
||||
@@ -431,7 +432,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
var request = requestBuilder.Build();
|
||||
request.SetContent(body);
|
||||
|
||||
loginResult = HttpClient.Execute(request);
|
||||
loginResult = await HttpClient.ExecuteAsync(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -451,7 +452,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
requestBuilder.AddFormParameter(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
loginResult = HttpClient.Execute(requestBuilder.Build());
|
||||
loginResult = await HttpClient.ExecuteAsync(requestBuilder.Build());
|
||||
}
|
||||
|
||||
Cookies = loginResult.GetCookies();
|
||||
@@ -486,7 +487,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
|
||||
requestBuilder.Headers.Add("Referer", SiteLink);
|
||||
|
||||
var response = HttpClient.Execute(requestBuilder.Build());
|
||||
var response = await HttpClient.ExecuteAsync(requestBuilder.Build());
|
||||
|
||||
Cookies = response.GetCookies();
|
||||
|
||||
@@ -510,7 +511,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
|
||||
requestBuilder.Headers.Add("Referer", SiteLink);
|
||||
|
||||
var response = HttpClient.Execute(requestBuilder.Build());
|
||||
var response = await HttpClient.ExecuteAsync(requestBuilder.Build());
|
||||
|
||||
Cookies = response.GetCookies();
|
||||
|
||||
@@ -556,7 +557,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
return true;
|
||||
}
|
||||
|
||||
public void GetConfigurationForSetup(bool automaticlogin)
|
||||
public async Task GetConfigurationForSetup(bool automaticlogin)
|
||||
{
|
||||
var login = _definition.Login;
|
||||
|
||||
@@ -587,7 +588,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
requestBuilder.SetCookies(Cookies);
|
||||
}
|
||||
|
||||
landingResult = HttpClient.Execute(requestBuilder.Build());
|
||||
landingResult = await HttpClient.ExecuteAsync(requestBuilder.Build());
|
||||
|
||||
Cookies = landingResult.GetCookies();
|
||||
|
||||
@@ -659,7 +660,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
return;
|
||||
}
|
||||
|
||||
protected bool TestLogin()
|
||||
protected async Task<bool> TestLogin()
|
||||
{
|
||||
var login = _definition.Login;
|
||||
|
||||
@@ -684,7 +685,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
|
||||
requestBuilder.SetCookies(Cookies);
|
||||
}
|
||||
|
||||
var testResult = HttpClient.Execute(requestBuilder.Build());
|
||||
var testResult = await HttpClient.ExecuteAsync(requestBuilder.Build());
|
||||
|
||||
if (testResult.HasHttpRedirect)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Configuration;
|
||||
@@ -47,7 +48,7 @@ namespace NzbDrone.Core.Indexers.Gazelle
|
||||
return caps;
|
||||
}
|
||||
|
||||
protected override void DoLogin()
|
||||
protected override async Task DoLogin()
|
||||
{
|
||||
var requestBuilder = new HttpRequestBuilder(LoginUrl)
|
||||
{
|
||||
@@ -68,7 +69,7 @@ namespace NzbDrone.Core.Indexers.Gazelle
|
||||
.Accept(HttpAccept.Json)
|
||||
.Build();
|
||||
|
||||
var response = _httpClient.Execute(authLoginRequest);
|
||||
var response = await _httpClient.ExecuteAsync(authLoginRequest);
|
||||
|
||||
cookies = response.GetCookies();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Html.Parser;
|
||||
using FluentValidation;
|
||||
using NLog;
|
||||
@@ -43,7 +44,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
return new HDTorrentsParser(Settings, Capabilities.Categories, BaseUrl);
|
||||
}
|
||||
|
||||
protected override void DoLogin()
|
||||
protected override async Task DoLogin()
|
||||
{
|
||||
var requestBuilder = new HttpRequestBuilder(LoginUrl)
|
||||
{
|
||||
@@ -62,7 +63,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
.SetHeader("Content-Type", "multipart/form-data")
|
||||
.Build();
|
||||
|
||||
var response = _httpClient.Execute(authLoginRequest);
|
||||
var response = await _httpClient.ExecuteAsync(authLoginRequest);
|
||||
|
||||
cookies = response.GetCookies();
|
||||
UpdateCookies(cookies, DateTime.Now + TimeSpan.FromDays(30));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
@@ -38,9 +39,9 @@ namespace NzbDrone.Core.Indexers.Headphones
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Test(List<ValidationFailure> failures)
|
||||
protected override async Task Test(List<ValidationFailure> failures)
|
||||
{
|
||||
base.Test(failures);
|
||||
await base.Test(failures);
|
||||
|
||||
if (failures.Any())
|
||||
{
|
||||
@@ -48,7 +49,7 @@ namespace NzbDrone.Core.Indexers.Headphones
|
||||
}
|
||||
}
|
||||
|
||||
public override byte[] Download(HttpUri link)
|
||||
public override async Task<byte[]> Download(HttpUri link)
|
||||
{
|
||||
var requestBuilder = new HttpRequestBuilder(link.FullUri);
|
||||
|
||||
@@ -60,7 +61,8 @@ namespace NzbDrone.Core.Indexers.Headphones
|
||||
|
||||
try
|
||||
{
|
||||
downloadBytes = _httpClient.Execute(request).ResponseData;
|
||||
var response = await _httpClient.ExecuteAsync(request);
|
||||
downloadBytes = response.ResponseData;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
@@ -131,9 +132,9 @@ namespace NzbDrone.Core.Indexers.Newznab
|
||||
return settings;
|
||||
}
|
||||
|
||||
protected override void Test(List<ValidationFailure> failures)
|
||||
protected override async Task Test(List<ValidationFailure> failures)
|
||||
{
|
||||
base.Test(failures);
|
||||
await base.Test(failures);
|
||||
if (failures.HasErrors())
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Html.Parser;
|
||||
using FluentValidation;
|
||||
using NLog;
|
||||
@@ -45,7 +46,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
return new RevolutionTTParser(Settings, Capabilities.Categories, BaseUrl);
|
||||
}
|
||||
|
||||
protected override void DoLogin()
|
||||
protected override async Task DoLogin()
|
||||
{
|
||||
UpdateCookies(null, null);
|
||||
|
||||
@@ -55,7 +56,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
AllowAutoRedirect = true
|
||||
};
|
||||
|
||||
var loginPage = _httpClient.Execute(new HttpRequest(BaseUrl + "login.php"));
|
||||
var loginPage = await _httpClient.ExecuteAsync(new HttpRequest(BaseUrl + "login.php"));
|
||||
|
||||
requestBuilder.Method = HttpMethod.POST;
|
||||
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
|
||||
@@ -67,7 +68,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
.SetHeader("Content-Type", "multipart/form-data")
|
||||
.Build();
|
||||
|
||||
var response = _httpClient.Execute(authLoginRequest);
|
||||
var response = await _httpClient.ExecuteAsync(authLoginRequest);
|
||||
|
||||
if (response.Content != null && response.Content.Contains("/logout.php"))
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using FluentValidation;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
@@ -44,7 +45,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
return new TorrentLeechParser(Settings, Capabilities.Categories, BaseUrl);
|
||||
}
|
||||
|
||||
protected override void DoLogin()
|
||||
protected override async Task DoLogin()
|
||||
{
|
||||
var requestBuilder = new HttpRequestBuilder(LoginUrl)
|
||||
{
|
||||
@@ -63,7 +64,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
.SetHeader("Content-Type", "multipart/form-data")
|
||||
.Build();
|
||||
|
||||
var response = _httpClient.Execute(authLoginRequest);
|
||||
var response = await _httpClient.ExecuteAsync(authLoginRequest);
|
||||
|
||||
cookies = response.GetCookies();
|
||||
UpdateCookies(cookies, DateTime.Now + TimeSpan.FromDays(30));
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Html.Parser;
|
||||
using FluentValidation;
|
||||
using NLog;
|
||||
@@ -44,14 +45,14 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
return new TorrentSeedsParser(Settings, Capabilities.Categories, BaseUrl);
|
||||
}
|
||||
|
||||
protected override void DoLogin()
|
||||
protected override async Task DoLogin()
|
||||
{
|
||||
var requestBuilder = new HttpRequestBuilder(LoginUrl)
|
||||
{
|
||||
LogResponseContent = true
|
||||
};
|
||||
|
||||
var loginPage = _httpClient.Execute(new HttpRequest(TokenUrl));
|
||||
var loginPage = await _httpClient.ExecuteAsync(new HttpRequest(TokenUrl));
|
||||
var parser = new HtmlParser();
|
||||
var dom = parser.ParseDocument(loginPage.Content);
|
||||
var token = dom.QuerySelector("form.form-horizontal > span");
|
||||
@@ -72,7 +73,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
||||
.SetHeader("Content-Type", "multipart/form-data")
|
||||
.Build();
|
||||
|
||||
var response = _httpClient.Execute(authLoginRequest);
|
||||
var response = await _httpClient.ExecuteAsync(authLoginRequest);
|
||||
|
||||
cookies = response.GetCookies();
|
||||
UpdateCookies(cookies, DateTime.Now + TimeSpan.FromDays(30));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
@@ -81,9 +82,9 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
return settings;
|
||||
}
|
||||
|
||||
protected override void Test(List<ValidationFailure> failures)
|
||||
protected override async Task Test(List<ValidationFailure> failures)
|
||||
{
|
||||
base.Test(failures);
|
||||
await base.Test(failures);
|
||||
if (failures.HasErrors())
|
||||
{
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user