From dbf86efb0a3b4ac32001b5329b3c19f200e9ad9e Mon Sep 17 00:00:00 2001 From: Bogdan Date: Fri, 3 Feb 2023 15:58:17 +0200 Subject: [PATCH] Fixed: (ExecuteAuth) Request timeout of 15s by default, if not set otherwise --- .../Indexers/Definitions/Anidub.cs | 37 ++++------ .../Indexers/Definitions/AnimeTorrents.cs | 43 ++++-------- .../Indexers/Definitions/Anthelion.cs | 45 ++++-------- .../Definitions/Avistaz/AvistazBase.cs | 13 +--- src/NzbDrone.Core/Indexers/Definitions/BB.cs | 60 ++++++---------- .../Indexers/Definitions/BakaBT.cs | 70 +++++++------------ .../Indexers/Definitions/FunFile.cs | 1 - .../Definitions/Gazelle/GazelleBase.cs | 1 - .../Indexers/Definitions/HDSpace.cs | 3 - .../Indexers/Definitions/HDTorrents.cs | 4 +- .../Indexers/Definitions/ImmortalSeed.cs | 1 - .../Indexers/Definitions/Libble.cs | 3 +- .../Indexers/Definitions/PirateTheNet.cs | 1 - .../Indexers/Definitions/PornoLab.cs | 2 +- .../Indexers/Definitions/PreToMe.cs | 1 - .../Indexers/Definitions/RevolutionTT.cs | 56 ++++++--------- .../Indexers/Definitions/RuTracker.cs | 53 ++++++-------- .../Indexers/Definitions/TVVault.cs | 38 +++------- .../Indexers/Definitions/Toloka.cs | 1 - .../Indexers/Definitions/TorrentBytes.cs | 55 +++++---------- .../Indexers/Definitions/XSpeeds.cs | 3 +- .../Indexers/Definitions/ZonaQ.cs | 51 +++++--------- src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 5 ++ 23 files changed, 187 insertions(+), 360 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Anidub.cs b/src/NzbDrone.Core/Indexers/Definitions/Anidub.cs index 08b918aa1..1e7c820d8 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Anidub.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Anidub.cs @@ -9,10 +9,8 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using AngleSharp.Html.Parser; -using FluentValidation; using NLog; using NzbDrone.Common.Http; -using NzbDrone.Core.Annotations; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Indexers.Settings; @@ -20,14 +18,13 @@ using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions { public class Anidub : TorrentIndexerBase { public override string Name => "Anidub"; - public override string[] IndexerUrls => new string[] { "https://tr.anidub.com/" }; + public override string[] IndexerUrls => new[] { "https://tr.anidub.com/" }; public override string Description => "Anidub is russian anime voiceover group and eponymous anime tracker."; public override string Language => "ru-RU"; public override Encoding Encoding => Encoding.UTF8; @@ -42,7 +39,7 @@ namespace NzbDrone.Core.Indexers.Definitions public override IIndexerRequestGenerator GetRequestGenerator() { - return new AnidubRequestGenerator() { Settings = Settings, Capabilities = Capabilities }; + return new AnidubRequestGenerator { Settings = Settings, Capabilities = Capabilities }; } public override IParseIndexerResponse GetParser() @@ -54,19 +51,17 @@ namespace NzbDrone.Core.Indexers.Definitions { UpdateCookies(null, null); + var mainPage = await ExecuteAuth(new HttpRequest(Settings.BaseUrl)); + var requestBuilder = new HttpRequestBuilder(Settings.BaseUrl + "index.php") { LogResponseContent = true, - AllowAutoRedirect = true + AllowAutoRedirect = true, + Method = HttpMethod.Post }; - var mainPage = await ExecuteAuth(new HttpRequest(Settings.BaseUrl)); - - requestBuilder.Method = HttpMethod.Post; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - requestBuilder.SetCookies(mainPage.GetCookies()); - var authLoginRequest = requestBuilder + .SetCookies(mainPage.GetCookies()) .AddFormParameter("login_name", Settings.Username) .AddFormParameter("login_password", Settings.Password) .AddFormParameter("login", "submit") @@ -82,22 +77,17 @@ namespace NzbDrone.Core.Indexers.Definitions } else { - const string ErrorSelector = "#content .berror .berror_c"; var parser = new HtmlParser(); var document = await parser.ParseDocumentAsync(response.Content); - var errorMessage = document.QuerySelector(ErrorSelector).TextContent.Trim(); - throw new IndexerAuthException("Anidub authentication failed. Error: " + errorMessage); + var errorMessage = document.QuerySelector("#content .berror .berror_c")?.TextContent.Trim(); + + throw new IndexerAuthException(errorMessage ?? "Unknown error message, please report."); } } protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) { - if (httpResponse.Content.Contains("index.php?action=logout")) - { - return false; - } - - return true; + return !httpResponse.Content.Contains("index.php?action=logout"); } private IndexerCapabilities SetCapabilities() @@ -138,6 +128,7 @@ namespace NzbDrone.Core.Indexers.Definitions caps.Categories.AddCategoryMapping(15, NewznabStandardCategory.BooksComics, "Манга"); caps.Categories.AddCategoryMapping(16, NewznabStandardCategory.Audio, "OST"); caps.Categories.AddCategoryMapping(17, NewznabStandardCategory.Audio, "Подкасты"); + return caps; } } @@ -147,10 +138,6 @@ namespace NzbDrone.Core.Indexers.Definitions public UserPassTorrentBaseSettings Settings { get; set; } public IndexerCapabilities Capabilities { get; set; } - public AnidubRequestGenerator() - { - } - private IEnumerable GetPagedRequests(string term, int[] categories) { var requestUrl = string.Empty; diff --git a/src/NzbDrone.Core/Indexers/Definitions/AnimeTorrents.cs b/src/NzbDrone.Core/Indexers/Definitions/AnimeTorrents.cs index a7636df97..200e51102 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/AnimeTorrents.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/AnimeTorrents.cs @@ -7,10 +7,8 @@ using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; using AngleSharp.Html.Parser; -using FluentValidation; using NLog; using NzbDrone.Common.Http; -using NzbDrone.Core.Annotations; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Indexers.Settings; @@ -18,7 +16,6 @@ using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions { @@ -26,7 +23,7 @@ namespace NzbDrone.Core.Indexers.Definitions { public override string Name => "AnimeTorrents"; - public override string[] IndexerUrls => new string[] { "https://animetorrents.me/" }; + public override string[] IndexerUrls => new[] { "https://animetorrents.me/" }; public override string Description => "Definitive source for anime and manga"; private string LoginUrl => Settings.BaseUrl + "login.php"; public override DownloadProtocol Protocol => DownloadProtocol.Torrent; @@ -40,7 +37,7 @@ namespace NzbDrone.Core.Indexers.Definitions public override IIndexerRequestGenerator GetRequestGenerator() { - return new AnimeTorrentsRequestGenerator() { Settings = Settings, Capabilities = Capabilities }; + return new AnimeTorrentsRequestGenerator { Settings = Settings, Capabilities = Capabilities }; } public override IParseIndexerResponse GetParser() @@ -52,23 +49,22 @@ namespace NzbDrone.Core.Indexers.Definitions { UpdateCookies(null, null); + var loginPage = await ExecuteAuth(new HttpRequest(LoginUrl)); + var requestBuilder = new HttpRequestBuilder(LoginUrl) { LogResponseContent = true, - AllowAutoRedirect = true + AllowAutoRedirect = true, + Method = HttpMethod.Post }; - var loginPage = await ExecuteAuth(new HttpRequest(LoginUrl)); - requestBuilder.Method = HttpMethod.Post; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - requestBuilder.SetCookies(loginPage.GetCookies()); - var authLoginRequest = requestBuilder + .SetCookies(loginPage.GetCookies()) .AddFormParameter("username", Settings.Username) .AddFormParameter("password", Settings.Password) .AddFormParameter("form", "login") .AddFormParameter("rememberme[]", "1") - .SetHeader("Content-Type", "multipart/form-data") + .SetHeader("Content-Type", "application/x-www-form-urlencoded") .Build(); var response = await ExecuteAuth(authLoginRequest); @@ -87,12 +83,7 @@ namespace NzbDrone.Core.Indexers.Definitions protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) { - if (httpResponse.Content.Contains("Access Denied!") || httpResponse.Content.Contains("login.php")) - { - return true; - } - - return false; + return httpResponse.Content.Contains("Access Denied!") || httpResponse.Content.Contains("login.php"); } private IndexerCapabilities SetCapabilities() @@ -100,13 +91,13 @@ namespace NzbDrone.Core.Indexers.Definitions var caps = new IndexerCapabilities { TvSearchParams = new List - { - TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep - }, + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep + }, MovieSearchParams = new List - { - MovieSearchParam.Q - } + { + MovieSearchParam.Q + } }; caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Anime Movie"); @@ -138,10 +129,6 @@ namespace NzbDrone.Core.Indexers.Definitions public UserPassTorrentBaseSettings Settings { get; set; } public IndexerCapabilities Capabilities { get; set; } - public AnimeTorrentsRequestGenerator() - { - } - private IEnumerable GetPagedRequests(string term, int[] categories) { var searchString = term; diff --git a/src/NzbDrone.Core/Indexers/Definitions/Anthelion.cs b/src/NzbDrone.Core/Indexers/Definitions/Anthelion.cs index bdffbbca5..f27abcc6d 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Anthelion.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Anthelion.cs @@ -52,39 +52,31 @@ namespace NzbDrone.Core.Indexers.Definitions var requestBuilder = new HttpRequestBuilder(LoginUrl) { LogResponseContent = true, - AllowAutoRedirect = true + AllowAutoRedirect = true, + Method = HttpMethod.Post }; - requestBuilder.Method = HttpMethod.Post; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - var cookies = Cookies; - Cookies = null; + var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) .AddFormParameter("password", Settings.Password) .AddFormParameter("keeplogged", "1") .AddFormParameter("login", "Log+In!") - .SetHeader("Content-Type", "multipart/form-data") + .SetHeader("Content-Type", "application/x-www-form-urlencoded") + .SetHeader("Referer", LoginUrl) .Build(); - var headers = new NameValueCollection - { - { "Referer", LoginUrl } - }; - - authLoginRequest.Headers.Add(headers); - var response = await ExecuteAuth(authLoginRequest); if (CheckIfLoginNeeded(response)) { var parser = new HtmlParser(); var dom = parser.ParseDocument(response.Content); - var errorMessage = dom.QuerySelector("form#loginform").TextContent.Trim(); + var errorMessage = dom.QuerySelector("form#loginform")?.TextContent.Trim(); - throw new IndexerAuthException(errorMessage); + throw new IndexerAuthException(errorMessage ?? "Unknown error message, please report."); } cookies = response.GetCookies(); @@ -95,12 +87,7 @@ namespace NzbDrone.Core.Indexers.Definitions protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) { - if (!httpResponse.Content.Contains("logout.php")) - { - return true; - } - - return false; + return !httpResponse.Content.Contains("logout.php"); } private IndexerCapabilities SetCapabilities() @@ -108,13 +95,13 @@ namespace NzbDrone.Core.Indexers.Definitions var caps = new IndexerCapabilities { TvSearchParams = new List - { - TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep - }, + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep + }, MovieSearchParams = new List - { - MovieSearchParam.Q - } + { + MovieSearchParam.Q + } }; caps.Categories.AddCategoryMapping("1", NewznabStandardCategory.Movies, "Film/Feature"); @@ -131,10 +118,6 @@ namespace NzbDrone.Core.Indexers.Definitions public UserPassTorrentBaseSettings Settings { get; set; } public IndexerCapabilities Capabilities { get; set; } - public AnthelionRequestGenerator() - { - } - private IEnumerable GetPagedRequests(string term, int[] categories, string imdbId = null) { var searchUrl = string.Format("{0}/torrents.php", Settings.BaseUrl.TrimEnd('/')); diff --git a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs index 0aad230f0..1c27320e9 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs @@ -66,12 +66,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz protected override bool CheckIfLoginNeeded(HttpResponse response) { - if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.PreconditionFailed) - { - return true; - } - - return false; + return response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.PreconditionFailed; } protected override void ModifyRequest(IndexerRequest request) @@ -116,12 +111,10 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz { var requestBuilder = new HttpRequestBuilder(LoginUrl) { - LogResponseContent = true + LogResponseContent = true, + Method = HttpMethod.Post }; - requestBuilder.Method = HttpMethod.Post; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) .AddFormParameter("password", Settings.Password) diff --git a/src/NzbDrone.Core/Indexers/Definitions/BB.cs b/src/NzbDrone.Core/Indexers/Definitions/BB.cs index 7c3b0a78f..d8214fa8e 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/BB.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/BB.cs @@ -7,10 +7,8 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using AngleSharp.Dom; using AngleSharp.Html.Parser; -using FluentValidation; using NLog; using NzbDrone.Common.Http; -using NzbDrone.Core.Annotations; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Indexers.Settings; @@ -18,14 +16,13 @@ using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions { public class BB : TorrentIndexerBase { public override string Name => "BB"; - public override string[] IndexerUrls => new string[] { StringUtil.FromBase64("aHR0cHM6Ly9iYWNvbmJpdHMub3JnLw==") }; + public override string[] IndexerUrls => new[] { StringUtil.FromBase64("aHR0cHM6Ly9iYWNvbmJpdHMub3JnLw==") }; private string LoginUrl => Settings.BaseUrl + "login.php"; public override string Description => "BB is a Private Torrent Tracker for 0DAY / GENERAL"; public override string Language => "en-US"; @@ -41,7 +38,7 @@ namespace NzbDrone.Core.Indexers.Definitions public override IIndexerRequestGenerator GetRequestGenerator() { - return new BBRequestGenerator() { Settings = Settings, Capabilities = Capabilities }; + return new BBRequestGenerator { Settings = Settings, Capabilities = Capabilities }; } public override IParseIndexerResponse GetParser() @@ -54,30 +51,22 @@ namespace NzbDrone.Core.Indexers.Definitions var requestBuilder = new HttpRequestBuilder(LoginUrl) { LogResponseContent = true, - AllowAutoRedirect = true + AllowAutoRedirect = true, + Method = HttpMethod.Post }; - requestBuilder.Method = HttpMethod.Post; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - var cookies = Cookies; - Cookies = null; + var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) .AddFormParameter("password", Settings.Password) .AddFormParameter("keeplogged", "1") .AddFormParameter("login", "Log+In!") - .SetHeader("Content-Type", "multipart/form-data") + .SetHeader("Content-Type", "application/x-www-form-urlencoded") + .SetHeader("Referer", LoginUrl) .Build(); - var headers = new NameValueCollection - { - { "Referer", LoginUrl } - }; - - authLoginRequest.Headers.Add(headers); - var response = await ExecuteAuth(authLoginRequest); if (CheckIfLoginNeeded(response)) @@ -105,12 +94,7 @@ namespace NzbDrone.Core.Indexers.Definitions protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) { - if (!httpResponse.Content.Contains("logout.php")) - { - return true; - } - - return false; + return !httpResponse.Content.Contains("logout.php"); } private IndexerCapabilities SetCapabilities() @@ -118,21 +102,21 @@ namespace NzbDrone.Core.Indexers.Definitions var caps = new IndexerCapabilities { TvSearchParams = new List - { - TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep - }, + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep + }, MovieSearchParams = new List - { - MovieSearchParam.Q - }, + { + MovieSearchParam.Q + }, MusicSearchParams = new List - { - MusicSearchParam.Q - }, + { + MusicSearchParam.Q + }, BookSearchParams = new List - { - BookSearchParam.Q - } + { + BookSearchParam.Q + } }; caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.Audio); @@ -163,10 +147,6 @@ namespace NzbDrone.Core.Indexers.Definitions public UserPassTorrentBaseSettings Settings { get; set; } public IndexerCapabilities Capabilities { get; set; } - public BBRequestGenerator() - { - } - private IEnumerable GetPagedRequests(string term, int[] categories) { var searchUrl = string.Format("{0}/torrents.php", Settings.BaseUrl.TrimEnd('/')); diff --git a/src/NzbDrone.Core/Indexers/Definitions/BakaBT.cs b/src/NzbDrone.Core/Indexers/Definitions/BakaBT.cs index 38feb1be8..4a504028a 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/BakaBT.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/BakaBT.cs @@ -8,7 +8,6 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using AngleSharp.Dom; using AngleSharp.Html.Parser; -using FluentValidation; using NLog; using NzbDrone.Common.Http; using NzbDrone.Core.Annotations; @@ -19,7 +18,6 @@ using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions { @@ -27,7 +25,7 @@ namespace NzbDrone.Core.Indexers.Definitions { public override string Name => "BakaBT"; - public override string[] IndexerUrls => new string[] { "https://bakabt.me/" }; + public override string[] IndexerUrls => new[] { "https://bakabt.me/" }; public override string Description => "Anime Community"; private string LoginUrl => Settings.BaseUrl + "login.php"; public override DownloadProtocol Protocol => DownloadProtocol.Torrent; @@ -41,7 +39,7 @@ namespace NzbDrone.Core.Indexers.Definitions public override IIndexerRequestGenerator GetRequestGenerator() { - return new BakaBTRequestGenerator() { Settings = Settings, Capabilities = Capabilities }; + return new BakaBTRequestGenerator { Settings = Settings, Capabilities = Capabilities }; } public override IParseIndexerResponse GetParser() @@ -52,14 +50,14 @@ namespace NzbDrone.Core.Indexers.Definitions public override async Task Download(Uri link) { var request = new HttpRequestBuilder(link.ToString()) - .SetCookies(GetCookies() ?? new Dictionary()) - .Build(); + .SetCookies(GetCookies() ?? new Dictionary()) + .Build(); var response = await _httpClient.ExecuteProxiedAsync(request, Definition); var parser = new HtmlParser(); var dom = parser.ParseDocument(response.Content); - var downloadLink = dom.QuerySelectorAll(".download_link").First().GetAttribute("href"); + var downloadLink = dom.QuerySelector(".download_link")?.GetAttribute("href"); if (string.IsNullOrWhiteSpace(downloadLink)) { @@ -76,19 +74,12 @@ namespace NzbDrone.Core.Indexers.Definitions var requestBuilder = new HttpRequestBuilder(LoginUrl) { LogResponseContent = true, - AllowAutoRedirect = true + AllowAutoRedirect = true, + Method = HttpMethod.Post }; var loginPage = await ExecuteAuth(new HttpRequest(LoginUrl)); - requestBuilder.Method = HttpMethod.Post; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - requestBuilder.SetCookies(loginPage.GetCookies()); - - requestBuilder.AddFormParameter("username", Settings.Username); - requestBuilder.AddFormParameter("password", Settings.Password); - requestBuilder.AddFormParameter("returnto", "/index.php"); - var parser = new HtmlParser(); var dom = parser.ParseDocument(loginPage.Content); var loginKey = dom.QuerySelector("input[name=\"loginKey\"]"); @@ -98,7 +89,11 @@ namespace NzbDrone.Core.Indexers.Definitions } var authLoginRequest = requestBuilder - .SetHeader("Content-Type", "multipart/form-data") + .SetCookies(loginPage.GetCookies()) + .AddFormParameter("username", Settings.Username) + .AddFormParameter("password", Settings.Password) + .AddFormParameter("returnto", "/index.php") + .SetHeader("Content-Type", "application/x-www-form-urlencoded") .Build(); var response = await ExecuteAuth(authLoginRequest); @@ -117,12 +112,7 @@ namespace NzbDrone.Core.Indexers.Definitions protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) { - if (!httpResponse.Content.Contains("Logout")) - { - return true; - } - - return false; + return !httpResponse.Content.Contains("Logout"); } private IndexerCapabilities SetCapabilities() @@ -130,21 +120,21 @@ namespace NzbDrone.Core.Indexers.Definitions var caps = new IndexerCapabilities { TvSearchParams = new List - { - TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep - }, + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep + }, MovieSearchParams = new List - { - MovieSearchParam.Q - }, + { + MovieSearchParam.Q + }, MusicSearchParams = new List - { - MusicSearchParam.Q - }, + { + MusicSearchParam.Q + }, BookSearchParams = new List - { - BookSearchParam.Q - } + { + BookSearchParam.Q + } }; caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.TVAnime, "Anime Series"); @@ -166,10 +156,6 @@ namespace NzbDrone.Core.Indexers.Definitions public BakaBTSettings Settings { get; set; } public IndexerCapabilities Capabilities { get; set; } - public BakaBTRequestGenerator() - { - } - private IEnumerable GetPagedRequests(string term) { var searchString = term; @@ -245,7 +231,7 @@ namespace NzbDrone.Core.Indexers.Definitions { private readonly BakaBTSettings _settings; private readonly IndexerCapabilitiesCategories _categories; - private readonly List _defaultCategories = new List { NewznabStandardCategory.TVAnime }; + private readonly List _defaultCategories = new () { NewznabStandardCategory.TVAnime }; public BakaBTParser(BakaBTSettings settings, IndexerCapabilitiesCategories categories) { @@ -415,10 +401,6 @@ namespace NzbDrone.Core.Indexers.Definitions public class BakaBTSettings : UserPassTorrentBaseSettings { - public BakaBTSettings() - { - } - [FieldDefinition(4, Label = "Add Romaji Title", Type = FieldType.Checkbox, HelpText = "Add releases for Romaji Title")] public bool AddRomajiTitle { get; set; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/FunFile.cs b/src/NzbDrone.Core/Indexers/Definitions/FunFile.cs index c4a5d0066..9f62542b0 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/FunFile.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/FunFile.cs @@ -57,7 +57,6 @@ public class FunFile : TorrentIndexerBase AllowAutoRedirect = true, Method = HttpMethod.Post }; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleBase.cs b/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleBase.cs index 2bfb713d1..581ae06a6 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleBase.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleBase.cs @@ -68,7 +68,6 @@ public abstract class GazelleBase : TorrentIndexerBase LogResponseContent = true, Method = HttpMethod.Post }; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); var authLoginRequestBuilder = requestBuilder .AddFormParameter("username", Settings.Username) diff --git a/src/NzbDrone.Core/Indexers/Definitions/HDSpace.cs b/src/NzbDrone.Core/Indexers/Definitions/HDSpace.cs index f7e155009..94b98ebd9 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/HDSpace.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/HDSpace.cs @@ -59,10 +59,7 @@ namespace NzbDrone.Core.Indexers.Definitions Method = HttpMethod.Post }; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - var cookies = Cookies; - Cookies = null; var authLoginRequest = requestBuilder diff --git a/src/NzbDrone.Core/Indexers/Definitions/HDTorrents.cs b/src/NzbDrone.Core/Indexers/Definitions/HDTorrents.cs index 39662495a..c22b8922a 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/HDTorrents.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/HDTorrents.cs @@ -58,11 +58,9 @@ namespace NzbDrone.Core.Indexers.Definitions Method = HttpMethod.Post }; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - var cookies = Cookies; - Cookies = null; + var authLoginRequest = requestBuilder .AddFormParameter("uid", Settings.Username) .AddFormParameter("pwd", Settings.Password) diff --git a/src/NzbDrone.Core/Indexers/Definitions/ImmortalSeed.cs b/src/NzbDrone.Core/Indexers/Definitions/ImmortalSeed.cs index ad31b384a..0949611fc 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/ImmortalSeed.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/ImmortalSeed.cs @@ -57,7 +57,6 @@ namespace NzbDrone.Core.Indexers.Definitions AllowAutoRedirect = true, Method = HttpMethod.Post }; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Libble.cs b/src/NzbDrone.Core/Indexers/Definitions/Libble.cs index d17f94da7..edd0982be 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Libble.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Libble.cs @@ -58,11 +58,10 @@ public class Libble : TorrentIndexerBase AllowAutoRedirect = true, Method = HttpMethod.Post }; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); var cookies = Cookies; - Cookies = null; + var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) .AddFormParameter("password", Settings.Password) diff --git a/src/NzbDrone.Core/Indexers/Definitions/PirateTheNet.cs b/src/NzbDrone.Core/Indexers/Definitions/PirateTheNet.cs index 102b88388..505a65943 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/PirateTheNet.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/PirateTheNet.cs @@ -65,7 +65,6 @@ public class PirateTheNet : TorrentIndexerBase AllowAutoRedirect = true, Method = HttpMethod.Post }; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); var authLoginRequest = requestBuilder .SetCookies(captchaPage.GetCookies()) diff --git a/src/NzbDrone.Core/Indexers/Definitions/PornoLab.cs b/src/NzbDrone.Core/Indexers/Definitions/PornoLab.cs index ac1ff2f08..eef04ee7d 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/PornoLab.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/PornoLab.cs @@ -60,7 +60,7 @@ namespace NzbDrone.Core.Indexers.Definitions .AddFormParameter("login_username", Settings.Username) .AddFormParameter("login_password", Settings.Password) .AddFormParameter("login", "Login") - .SetHeader("Content-Type", "multipart/form-data") + .SetHeader("Content-Type", "application/x-www-form-urlencoded") .Build(); var response = await ExecuteAuth(authLoginRequest); diff --git a/src/NzbDrone.Core/Indexers/Definitions/PreToMe.cs b/src/NzbDrone.Core/Indexers/Definitions/PreToMe.cs index bd850f27a..55a5c37d9 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/PreToMe.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/PreToMe.cs @@ -65,7 +65,6 @@ public class PreToMe : TorrentIndexerBase AllowAutoRedirect = true, Method = HttpMethod.Post }; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); var authLoginRequest = requestBuilder .SetCookies(loginPage.GetCookies()) diff --git a/src/NzbDrone.Core/Indexers/Definitions/RevolutionTT.cs b/src/NzbDrone.Core/Indexers/Definitions/RevolutionTT.cs index 35beb5a30..60d52de17 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/RevolutionTT.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/RevolutionTT.cs @@ -6,11 +6,9 @@ using System.Linq; using System.Net.Http; using System.Threading.Tasks; using AngleSharp.Html.Parser; -using FluentValidation; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; -using NzbDrone.Core.Annotations; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Indexers.Settings; @@ -18,7 +16,6 @@ using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions { @@ -26,7 +23,7 @@ namespace NzbDrone.Core.Indexers.Definitions { public override string Name => "RevolutionTT"; - public override string[] IndexerUrls => new string[] { "https://revolutiontt.me/" }; + public override string[] IndexerUrls => new[] { "https://revolutiontt.me/" }; public override string Description => "The Revolution has begun"; private string LoginUrl => Settings.BaseUrl + "takelogin.php"; public override DownloadProtocol Protocol => DownloadProtocol.Torrent; @@ -40,7 +37,7 @@ namespace NzbDrone.Core.Indexers.Definitions public override IIndexerRequestGenerator GetRequestGenerator() { - return new RevolutionTTRequestGenerator() { Settings = Settings, Capabilities = Capabilities }; + return new RevolutionTTRequestGenerator { Settings = Settings, Capabilities = Capabilities }; } public override IParseIndexerResponse GetParser() @@ -52,22 +49,20 @@ namespace NzbDrone.Core.Indexers.Definitions { UpdateCookies(null, null); + var loginPage = await ExecuteAuth(new HttpRequest(Settings.BaseUrl + "login.php")); + var requestBuilder = new HttpRequestBuilder(LoginUrl) { LogResponseContent = true, - AllowAutoRedirect = true + AllowAutoRedirect = true, + Method = HttpMethod.Post }; - var loginPage = await ExecuteAuth(new HttpRequest(Settings.BaseUrl + "login.php")); - - requestBuilder.Method = HttpMethod.Post; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - requestBuilder.SetCookies(loginPage.GetCookies()); - var authLoginRequest = requestBuilder + .SetCookies(loginPage.GetCookies()) .AddFormParameter("username", Settings.Username) .AddFormParameter("password", Settings.Password) - .SetHeader("Content-Type", "multipart/form-data") + .SetHeader("Content-Type", "application/x-www-form-urlencoded") .Build(); var response = await ExecuteAuth(authLoginRequest); @@ -86,12 +81,7 @@ namespace NzbDrone.Core.Indexers.Definitions protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) { - if (httpResponse.HasHttpRedirect || !httpResponse.Content.Contains("/logout.php")) - { - return true; - } - - return false; + return httpResponse.HasHttpRedirect || !httpResponse.Content.Contains("/logout.php"); } private IndexerCapabilities SetCapabilities() @@ -99,21 +89,21 @@ namespace NzbDrone.Core.Indexers.Definitions var caps = new IndexerCapabilities { TvSearchParams = new List - { - TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep - }, + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep + }, MovieSearchParams = new List - { - MovieSearchParam.Q, MovieSearchParam.ImdbId - }, + { + MovieSearchParam.Q, MovieSearchParam.ImdbId + }, MusicSearchParams = new List - { - MusicSearchParam.Q - }, + { + MusicSearchParam.Q + }, BookSearchParams = new List - { - BookSearchParam.Q - } + { + BookSearchParam.Q + } }; caps.Categories.AddCategoryMapping("23", NewznabStandardCategory.TVAnime); @@ -158,10 +148,6 @@ namespace NzbDrone.Core.Indexers.Definitions public UserPassTorrentBaseSettings Settings { get; set; } public IndexerCapabilities Capabilities { get; set; } - public RevolutionTTRequestGenerator() - { - } - private IEnumerable GetPagedRequests(string term, int[] categories, string imdbId = null) { var qc = new NameValueCollection diff --git a/src/NzbDrone.Core/Indexers/Definitions/RuTracker.cs b/src/NzbDrone.Core/Indexers/Definitions/RuTracker.cs index 41b5b2fd2..748bae3bc 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/RuTracker.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/RuTracker.cs @@ -8,7 +8,6 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using AngleSharp.Dom; using AngleSharp.Html.Parser; -using FluentValidation; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; @@ -20,7 +19,6 @@ using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions { @@ -28,7 +26,6 @@ namespace NzbDrone.Core.Indexers.Definitions { public override string Name => "RuTracker"; public override string[] IndexerUrls => new[] { "https://rutracker.org/", "https://rutracker.net/" }; - private string LoginUrl => Settings.BaseUrl + "forum/login.php"; public override string Description => "RuTracker is a Semi-Private Russian torrent site with a thriving file-sharing community"; public override string Language => "ru-org"; @@ -57,21 +54,19 @@ namespace NzbDrone.Core.Indexers.Definitions var requestBuilder = new HttpRequestBuilder(LoginUrl) { LogResponseContent = true, - AllowAutoRedirect = true + AllowAutoRedirect = true, + Method = HttpMethod.Post }; - requestBuilder.Method = HttpMethod.Post; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - var cookies = Cookies; - Cookies = null; - requestBuilder.AddFormParameter("login_username", Settings.Username) + + var authLoginRequest = requestBuilder + .AddFormParameter("login_username", Settings.Username) .AddFormParameter("login_password", Settings.Password) .AddFormParameter("login", "Login") - .SetHeader("Content-Type", "multipart/form-data"); - - var authLoginRequest = requestBuilder.Build(); + .SetHeader("Content-Type", "application/x-www-form-urlencoded") + .Build(); var response = await ExecuteAuth(authLoginRequest); @@ -88,12 +83,7 @@ namespace NzbDrone.Core.Indexers.Definitions protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) { - if (httpResponse.RedirectUrl.Contains("login.php") || !httpResponse.Content.Contains("id=\"logged-in-username\"")) - { - return true; - } - - return false; + return httpResponse.RedirectUrl.Contains("login.php") || !httpResponse.Content.Contains("id=\"logged-in-username\""); } private IndexerCapabilities SetCapabilities() @@ -101,25 +91,24 @@ namespace NzbDrone.Core.Indexers.Definitions var caps = new IndexerCapabilities { TvSearchParams = new List - { - TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep - }, + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep + }, MovieSearchParams = new List - { - MovieSearchParam.Q - }, + { + MovieSearchParam.Q + }, MusicSearchParams = new List - { - MusicSearchParam.Q - }, + { + MusicSearchParam.Q + }, BookSearchParams = new List - { - BookSearchParam.Q - } + { + BookSearchParam.Q + }, + SupportsRawSearch = true }; - caps.SupportsRawSearch = true; - caps.Categories.AddCategoryMapping(22, NewznabStandardCategory.Movies, "Наше кино"); caps.Categories.AddCategoryMapping(941, NewznabStandardCategory.Movies, "|- Кино СССР"); caps.Categories.AddCategoryMapping(1666, NewznabStandardCategory.Movies, "|- Детские отечественные фильмы"); diff --git a/src/NzbDrone.Core/Indexers/Definitions/TVVault.cs b/src/NzbDrone.Core/Indexers/Definitions/TVVault.cs index 01f3359ba..b037de537 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/TVVault.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/TVVault.cs @@ -8,11 +8,9 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; using AngleSharp.Html.Parser; -using FluentValidation; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; -using NzbDrone.Core.Annotations; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Indexers.Settings; @@ -20,7 +18,6 @@ using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions { @@ -45,7 +42,7 @@ namespace NzbDrone.Core.Indexers.Definitions public override IIndexerRequestGenerator GetRequestGenerator() { - return new TVVaultRequestGenerator() { Settings = Settings, Capabilities = Capabilities }; + return new TVVaultRequestGenerator { Settings = Settings, Capabilities = Capabilities }; } public override IParseIndexerResponse GetParser() @@ -58,38 +55,31 @@ namespace NzbDrone.Core.Indexers.Definitions var requestBuilder = new HttpRequestBuilder(LoginUrl) { LogResponseContent = true, - AllowAutoRedirect = true + AllowAutoRedirect = true, + Method = HttpMethod.Post }; - requestBuilder.Method = HttpMethod.Post; - var cookies = Cookies; - Cookies = null; + var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) .AddFormParameter("password", Settings.Password) .AddFormParameter("keeplogged", "1") .AddFormParameter("login", "Log+In!") - .SetHeader("Content-Type", "multipart/form-data") + .SetHeader("Content-Type", "application/x-www-form-urlencoded") + .SetHeader("Referer", LoginUrl) .Build(); - var headers = new NameValueCollection - { - { "Referer", LoginUrl } - }; - - authLoginRequest.Headers.Add(headers); - var response = await ExecuteAuth(authLoginRequest); if (CheckIfLoginNeeded(response)) { var parser = new HtmlParser(); var dom = parser.ParseDocument(response.Content); - var errorMessage = dom.QuerySelector("form#loginform").TextContent.Trim(); + var errorMessage = dom.QuerySelector("form#loginform")?.TextContent.Trim(); - throw new IndexerAuthException(errorMessage); + throw new IndexerAuthException(errorMessage ?? "Unknown error message, please report."); } cookies = response.GetCookies(); @@ -100,12 +90,7 @@ namespace NzbDrone.Core.Indexers.Definitions protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) { - if (!httpResponse.Content.Contains("logout.php")) - { - return true; - } - - return false; + return !httpResponse.Content.Contains("logout.php"); } private IndexerCapabilities SetCapabilities() @@ -139,11 +124,6 @@ namespace NzbDrone.Core.Indexers.Definitions { public UserPassTorrentBaseSettings Settings { get; set; } public IndexerCapabilities Capabilities { get; set; } - public string BaseUrl { get; set; } - - public TVVaultRequestGenerator() - { - } private IEnumerable GetPagedRequests(string term, int[] categories, string imdbId = null) { diff --git a/src/NzbDrone.Core/Indexers/Definitions/Toloka.cs b/src/NzbDrone.Core/Indexers/Definitions/Toloka.cs index 6bc8ce6a9..3a096ed7f 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Toloka.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Toloka.cs @@ -60,7 +60,6 @@ namespace NzbDrone.Core.Indexers.Definitions AllowAutoRedirect = true, Method = HttpMethod.Post }; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) diff --git a/src/NzbDrone.Core/Indexers/Definitions/TorrentBytes.cs b/src/NzbDrone.Core/Indexers/Definitions/TorrentBytes.cs index 3e600e887..922acdb61 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/TorrentBytes.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/TorrentBytes.cs @@ -22,7 +22,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class TorrentBytes : TorrentIndexerBase { public override string Name => "Torrent Bytes"; - public override string[] IndexerUrls => new string[] { "https://www.torrentbytes.net/" }; + public override string[] IndexerUrls => new[] { "https://www.torrentbytes.net/" }; private string LoginUrl => Settings.BaseUrl + "takelogin.php"; public override string Description => "A decade of TorrentBytes"; public override string Language => "en-US"; @@ -38,7 +38,7 @@ namespace NzbDrone.Core.Indexers.Definitions public override IIndexerRequestGenerator GetRequestGenerator() { - return new TorrentBytesRequestGenerator() { Settings = Settings, Capabilities = Capabilities }; + return new TorrentBytesRequestGenerator { Settings = Settings, Capabilities = Capabilities }; } public override IParseIndexerResponse GetParser() @@ -51,39 +51,31 @@ namespace NzbDrone.Core.Indexers.Definitions var requestBuilder = new HttpRequestBuilder(LoginUrl) { LogResponseContent = true, - AllowAutoRedirect = true + AllowAutoRedirect = true, + Method = HttpMethod.Post }; - requestBuilder.Method = HttpMethod.Post; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - var cookies = Cookies; - Cookies = null; + var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) .AddFormParameter("password", Settings.Password) .AddFormParameter("returnto", "/") .AddFormParameter("login", "Log in!") - .SetHeader("Content-Type", "multipart/form-data") + .SetHeader("Content-Type", "application/x-www-form-urlencoded") + .SetHeader("Referer", LoginUrl) .Build(); - var headers = new NameValueCollection - { - { "Referer", LoginUrl } - }; - - authLoginRequest.Headers.Add(headers); - var response = await ExecuteAuth(authLoginRequest); if (CheckIfLoginNeeded(response)) { var parser = new HtmlParser(); var dom = parser.ParseDocument(response.Content); - var errorMessage = dom.QuerySelector("td.embedded")?.TextContent.Trim() ?? response.Content; + var errorMessage = dom.QuerySelector("td.embedded")?.TextContent.Trim(); - throw new IndexerAuthException(errorMessage); + throw new IndexerAuthException(errorMessage ?? "Unknown error message, please report."); } cookies = response.GetCookies(); @@ -94,12 +86,7 @@ namespace NzbDrone.Core.Indexers.Definitions protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) { - if (!httpResponse.Content.Contains("my.php")) - { - return true; - } - - return false; + return !httpResponse.Content.Contains("my.php"); } private IndexerCapabilities SetCapabilities() @@ -107,17 +94,17 @@ namespace NzbDrone.Core.Indexers.Definitions var caps = new IndexerCapabilities { TvSearchParams = new List - { - TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep, TvSearchParam.ImdbId - }, + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep, TvSearchParam.ImdbId + }, MovieSearchParams = new List - { - MovieSearchParam.Q, MovieSearchParam.ImdbId - }, + { + MovieSearchParam.Q, MovieSearchParam.ImdbId + }, MusicSearchParams = new List - { - MusicSearchParam.Q - } + { + MusicSearchParam.Q + } }; caps.Categories.AddCategoryMapping(23, NewznabStandardCategory.TVAnime, "Anime"); @@ -164,10 +151,6 @@ namespace NzbDrone.Core.Indexers.Definitions public UserPassTorrentBaseSettings Settings { get; set; } public IndexerCapabilities Capabilities { get; set; } - public TorrentBytesRequestGenerator() - { - } - private IEnumerable GetPagedRequests(string term, int[] categories, string imdbId = null) { var searchUrl = string.Format("{0}/browse.php", Settings.BaseUrl.TrimEnd('/')); diff --git a/src/NzbDrone.Core/Indexers/Definitions/XSpeeds.cs b/src/NzbDrone.Core/Indexers/Definitions/XSpeeds.cs index 348c03c43..74c683d3b 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/XSpeeds.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/XSpeeds.cs @@ -59,7 +59,6 @@ public class XSpeeds : TorrentIndexerBase AllowAutoRedirect = true, Method = HttpMethod.Post }; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); var authLoginRequest = requestBuilder .SetCookies(landingPage.GetCookies()) @@ -81,7 +80,7 @@ public class XSpeeds : TorrentIndexerBase errorMessage = dom.QuerySelector("div.notification-body")?.TextContent.Trim().Replace("\n\t", " "); } - throw new IndexerAuthException(errorMessage); + throw new IndexerAuthException(errorMessage ?? "Unknown error message, please report."); } var cookies = response.GetCookies(); diff --git a/src/NzbDrone.Core/Indexers/Definitions/ZonaQ.cs b/src/NzbDrone.Core/Indexers/Definitions/ZonaQ.cs index 8247e66b8..24d044f58 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/ZonaQ.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/ZonaQ.cs @@ -10,11 +10,9 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using AngleSharp.Html.Parser; -using FluentValidation; using Newtonsoft.Json.Linq; using NLog; using NzbDrone.Common.Http; -using NzbDrone.Core.Annotations; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Indexers.Settings; @@ -22,14 +20,13 @@ using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions { public class ZonaQ : TorrentIndexerBase { public override string Name => "ZonaQ"; - public override string[] IndexerUrls => new string[] { "https://www.zonaq.pw/" }; + public override string[] IndexerUrls => new[] { "https://www.zonaq.pw/" }; private string Login1Url => Settings.BaseUrl + "index.php"; private string Login2Url => Settings.BaseUrl + "paDentro.php"; private string Login3Url => Settings.BaseUrl + "retorno/include/puerta_8_ajax.php"; @@ -48,7 +45,7 @@ namespace NzbDrone.Core.Indexers.Definitions public override IIndexerRequestGenerator GetRequestGenerator() { - return new ZonaQRequestGenerator() { Settings = Settings, Capabilities = Capabilities }; + return new ZonaQRequestGenerator { Settings = Settings, Capabilities = Capabilities }; } public override IParseIndexerResponse GetParser() @@ -78,14 +75,12 @@ namespace NzbDrone.Core.Indexers.Definitions var requestBuilder = new HttpRequestBuilder(Login2Url) { - LogResponseContent = true + LogResponseContent = true, + Method = HttpMethod.Post }; - requestBuilder.Method = HttpMethod.Post; - requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - requestBuilder.SetCookies(loginPage.GetCookies()); - var authLoginRequest = requestBuilder + .SetCookies(loginPage.GetCookies()) .AddFormParameter("user", Settings.Username) .AddFormParameter("passwrd", Settings.Password) .AddFormParameter("hash_passwrd", hashPassword) @@ -101,14 +96,12 @@ namespace NzbDrone.Core.Indexers.Definitions Thread.Sleep(3000); var requestBuilder2 = new HttpRequestBuilder(Login3Url) { - LogResponseContent = true + LogResponseContent = true, + Method = HttpMethod.Post }; - requestBuilder2.Method = HttpMethod.Post; - requestBuilder2.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - requestBuilder2.SetCookies(response.GetCookies()); - var authLoginRequest2 = requestBuilder2 + .SetCookies(response.GetCookies()) .AddFormParameter("passwd", "") .AddFormParameter("cookielength", "43200") .AddFormParameter("respuesta", "") @@ -131,8 +124,9 @@ namespace NzbDrone.Core.Indexers.Definitions LogResponseContent = true }; - requestBuilder4.SetCookies(response.GetCookies()); - var authLoginRequest3 = requestBuilder4.Build(); + var authLoginRequest3 = requestBuilder4 + .SetCookies(response.GetCookies()) + .Build(); response = await ExecuteAuth(authLoginRequest3); @@ -147,12 +141,7 @@ namespace NzbDrone.Core.Indexers.Definitions protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) { - if (httpResponse.Content == null || !httpResponse.Content.Contains("/index.php?action=logout;")) - { - return true; - } - - return false; + return httpResponse.Content == null || !httpResponse.Content.Contains("/index.php?action=logout;"); } private IndexerCapabilities SetCapabilities() @@ -160,13 +149,13 @@ namespace NzbDrone.Core.Indexers.Definitions var caps = new IndexerCapabilities { TvSearchParams = new List - { - TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep - }, + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep + }, MovieSearchParams = new List - { - MovieSearchParam.Q - } + { + MovieSearchParam.Q + } }; caps.Categories.AddCategoryMapping("cat[]=1&subcat[]=1", NewznabStandardCategory.MoviesDVD, "Películas/DVD"); @@ -238,10 +227,6 @@ namespace NzbDrone.Core.Indexers.Definitions public UserPassTorrentBaseSettings Settings { get; set; } public IndexerCapabilities Capabilities { get; set; } - public ZonaQRequestGenerator() - { - } - private IEnumerable GetPagedRequests(string term, int[] categories) { var searchUrl = string.Format("{0}/retorno/2/index.php", Settings.BaseUrl.TrimEnd('/')); diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index b1b7352a4..0df30caf7 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -404,6 +404,11 @@ namespace NzbDrone.Core.Indexers { request.Encoding = Encoding; + if (request.RequestTimeout == TimeSpan.Zero) + { + request.RequestTimeout = TimeSpan.FromSeconds(15); + } + var response = await _httpClient.ExecuteProxiedAsync(request, Definition); _eventAggregator.PublishEvent(new IndexerAuthEvent(Definition.Id, !response.HasHttpError, response.ElapsedTime));