From 92e7a38bd0a2b832d82163c5ac527ab1e23fe026 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 7 May 2023 15:54:31 +0300 Subject: [PATCH] Fixed: (Rarbg) Move check response by status code to parser --- .../Indexers/Definitions/Rarbg/Rarbg.cs | 23 +------------ .../Indexers/Definitions/Rarbg/RarbgParser.cs | 33 +++++++++++++------ 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs index 8089b6001..33a80dccd 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net; using System.Threading.Tasks; using System.Web; using NLog; @@ -13,7 +12,6 @@ using NzbDrone.Common.Http; using NzbDrone.Common.Serializer; using NzbDrone.Core.Configuration; using NzbDrone.Core.Exceptions; -using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; @@ -84,25 +82,6 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg return cleanReleases.Select(r => (ReleaseInfo)r.Clone()).ToList(); } - public static void CheckResponseByStatusCode(IndexerResponse response, Logger logger) - { - var responseCode = (int)response.HttpResponse.StatusCode; - - switch (responseCode) - { - case (int)HttpStatusCode.TooManyRequests: - logger.Warn("Indexer API limit reached."); - throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(2)); - case 520: - logger.Warn("Indexer API error, likely rate limited by origin server."); - throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(3)); - case (int)HttpStatusCode.OK: - break; - default: - throw new IndexerException(response, "Indexer API call returned an unexpected status code [{0}]", responseCode); - } - } - private IndexerCapabilities SetCapabilities() { var caps = new IndexerCapabilities @@ -157,7 +136,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg { var response = await base.FetchIndexerResponse(request); - CheckResponseByStatusCode(response, _logger); + ((RarbgParser)GetParser()).CheckResponseByStatusCode(response); // try and recover from token errors var jsonResponse = new HttpResponse(response.HttpResponse); diff --git a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgParser.cs index dc057e40a..f612c052c 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgParser.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net; using System.Text.RegularExpressions; using NLog; using NzbDrone.Common.EnvironmentInfo; @@ -28,7 +29,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg { var results = new List(); - Rarbg.CheckResponseByStatusCode(indexerResponse, _logger); + CheckResponseByStatusCode(indexerResponse); var jsonResponse = new HttpResponse(indexerResponse.HttpResponse); @@ -99,18 +100,30 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg return results; } - private string GetGuid(RarbgTorrent torrent) + public void CheckResponseByStatusCode(IndexerResponse response) + { + var responseCode = (int)response.HttpResponse.StatusCode; + + switch (responseCode) + { + case (int)HttpStatusCode.TooManyRequests: + _logger.Warn("Indexer API limit reached."); + throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(2)); + case 520: + _logger.Warn("Indexer API error, likely rate limited by origin server."); + throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(3)); + case (int)HttpStatusCode.OK: + break; + default: + throw new IndexerException(response, "Indexer API call returned an unexpected status code [{0}]", responseCode); + } + } + + private static string GetGuid(RarbgTorrent torrent) { var match = RegexGuid.Match(torrent.download); - if (match.Success) - { - return string.Format("rarbg-{0}", match.Groups[1].Value); - } - else - { - return string.Format("rarbg-{0}", torrent.download); - } + return match.Success ? $"rarbg-{match.Groups[1].Value}" : $"rarbg-{torrent.download}"; } } }