1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-03-06 11:48:49 +00:00

hdspace: improve error message on login (#14157)

This commit is contained in:
Bogdan 2023-03-16 14:12:19 +02:00 committed by GitHub
parent a9b73e9f8c
commit aff88be54f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,9 +4,9 @@ using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using AngleSharp.Html.Parser; using AngleSharp.Html.Parser;
using Jackett.Common.Extensions;
using Jackett.Common.Models; using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig; using Jackett.Common.Models.IndexerConfig;
using Jackett.Common.Services.Interfaces; using Jackett.Common.Services.Interfaces;
@ -95,25 +95,31 @@ namespace Jackett.Common.Indexers
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson) public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
{ {
LoadValuesFromJson(configJson); LoadValuesFromJson(configJson);
var loginPage = await RequestWithCookiesAsync(LoginUrl, string.Empty); var loginPage = await RequestWithCookiesAsync(LoginUrl, string.Empty);
var pairs = new Dictionary<string, string> var pairs = new Dictionary<string, string>
{ {
{"uid", configData.Username.Value}, { "uid", configData.Username.Value },
{"pwd", configData.Password.Value} { "pwd", configData.Password.Value }
}; };
// Send Post // Send Post
var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginPage.Cookies, true, referer: LoginUrl); var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginPage.Cookies, true, referer: LoginUrl);
await ConfigureIfOK(response.Cookies, response.ContentString?.Contains("logout.php") == true, () => await ConfigureIfOK(response.Cookies, response.ContentString?.Contains("logout.php") == true || response.ContentString?.Contains("Rank: Parked") == true, () =>
{ {
var errorStr = "You have {0} remaining login attempts"; var parser = new HtmlParser();
var remainingAttemptSpan = new Regex(string.Format(errorStr, "(.*?)")) var dom = parser.ParseDocument(response.ContentString);
.Match(loginPage.ContentString).Groups[1].ToString(); var errorMessage = dom
var attempts = Regex.Replace(remainingAttemptSpan, "<.*?>", string.Empty); .QuerySelectorAll("table.lista td.lista span[style*=\"#FF0000\"], table.lista td.header:contains(\"login attempts\")")
var errorMessage = string.Format(errorStr, attempts); .Select(r => r.TextContent.Trim())
throw new ExceptionWithConfigData(errorMessage, configData); .Where(m => m.IsNotNullOrWhiteSpace())
.Join(" ");
throw new ExceptionWithConfigData(errorMessage.IsNotNullOrWhiteSpace() ? errorMessage : "Unknown error message, please report.", configData);
}); });
return IndexerConfigurationStatus.RequiresTesting; return IndexerConfigurationStatus.RequiresTesting;
} }