From 4f9670413d284bd21bc27ffa77ad9de0d1510fb7 Mon Sep 17 00:00:00 2001 From: Diego Heras Date: Tue, 7 Apr 2020 17:16:16 +0200 Subject: [PATCH] torrentday: fix login without recaptcha. resolves #8057 (#8079) I can't test this very well because I always get the callenge in all domains. With this fix the configuration dialog will open at least. --- src/Jackett.Common/Indexers/TorrentDay.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Jackett.Common/Indexers/TorrentDay.cs b/src/Jackett.Common/Indexers/TorrentDay.cs index cfb8ea695..eadc6f482 100644 --- a/src/Jackett.Common/Indexers/TorrentDay.cs +++ b/src/Jackett.Common/Indexers/TorrentDay.cs @@ -132,7 +132,7 @@ namespace Jackett.Common.Indexers //result.CookieHeader.Value = loginPage.Cookies; UpdateCookieHeader(loginPage.Cookies); // update cookies instead of replacing them, see #3717 - result.Captcha.SiteKey = dom.QuerySelector(".g-recaptcha").GetAttribute("data-sitekey"); + result.Captcha.SiteKey = dom.QuerySelector(".g-recaptcha")?.GetAttribute("data-sitekey"); result.Captcha.Version = "2"; return result; } @@ -168,17 +168,19 @@ namespace Jackett.Common.Indexers } var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, configData.CookieHeader.Value, true, null, LoginUrl); - await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("logout.php"), () => + await ConfigureIfOK(result.Cookies, result.Content?.Contains("logout.php") == true, () => { + var errorMessage = result.Content; + var parser = new HtmlParser(); var dom = parser.ParseDocument(result.Content); var messageEl = dom.QuerySelector("#login"); - foreach (var child in messageEl.QuerySelectorAll("form")) - child.Remove(); - var errorMessage = messageEl.TextContent.Trim(); - - if (string.IsNullOrWhiteSpace(errorMessage)) - errorMessage = dom.TextContent; + if (messageEl != null) + { + foreach (var child in messageEl.QuerySelectorAll("form")) + child.Remove(); + errorMessage = messageEl.TextContent.Trim(); + } if (string.IsNullOrWhiteSpace(errorMessage) && result.IsRedirect) errorMessage = $"Got a redirect to {result.RedirectingTo}, please adjust your the alternative link";