From 28d09cd384d316fb1e9270b1d6f0fe90f2caef5a Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 17 Apr 2023 06:19:35 +0300 Subject: [PATCH] Fixed: (Rarbg) Simplify retry fetching for expired tokens --- .../Indexers/Definitions/Rarbg/Rarbg.cs | 37 +++++-------------- .../Rarbg/RarbgRequestGenerator.cs | 4 +- .../Definitions/Rarbg/RarbgTokenProvider.cs | 2 +- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs index 8618ff78c..3455964da 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs @@ -58,7 +58,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg case (int)HttpStatusCode.OK: break; default: - throw new IndexerException(response, "Indexer API call returned an unexpected StatusCode [{0}]", responseCode); + throw new IndexerException(response, "Indexer API call returned an unexpected status code [{0}]", responseCode); } } @@ -112,9 +112,9 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg return caps; } - protected override async Task FetchPage(IndexerRequest request, IParseIndexerResponse parser) + protected override async Task FetchIndexerResponse(IndexerRequest request) { - var response = await FetchIndexerResponse(request); + var response = await base.FetchIndexerResponse(request); CheckResponseByStatusCode(response); @@ -133,36 +133,19 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg qs.Set("token", newToken); request.HttpRequest.Url = request.Url.SetQuery(qs.GetQueryString()); - response = await FetchIndexerResponse(request); + + return await FetchIndexerResponse(request); } - else if (jsonResponse.Resource.error_code is 5) + + if (jsonResponse.Resource.error_code is 5) { _logger.Debug("Rarbg temp rate limit hit, retrying request"); - response = await FetchIndexerResponse(request); - } - } - try - { - var releases = parser.ParseResponse(response).ToList(); - - if (releases.Count == 0) - { - _logger.Trace(response.Content); + return await FetchIndexerResponse(request); } - - return new IndexerQueryResult - { - Releases = releases, - Response = response.HttpResponse - }; - } - catch (Exception ex) - { - ex.WithData(response.HttpResponse, 128 * 1024); - _logger.Trace("Unexpected Response content ({0} bytes): {1}", response.HttpResponse.ResponseData.Length, response.HttpResponse.Content); - throw; } + + return response; } public override object RequestAction(string action, IDictionary query) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgRequestGenerator.cs index 31eddb7a9..cfa678047 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgRequestGenerator.cs @@ -46,11 +46,11 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg { requestBuilder.AddQueryParam("search_imdb", imdbId); } - else if (tmdbId.HasValue && tmdbId > 0) + else if (tmdbId is > 0) { requestBuilder.AddQueryParam("search_themoviedb", tmdbId); } - else if (tvdbId.HasValue && tvdbId > 0) + else if (tvdbId is > 0) { requestBuilder.AddQueryParam("search_tvdb", tvdbId); } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgTokenProvider.cs b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgTokenProvider.cs index c8e74377b..f85bc8797 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgTokenProvider.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgTokenProvider.cs @@ -47,7 +47,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg return response.Resource["token"].ToString(); }, - TimeSpan.FromMinutes(14.0)); + TimeSpan.FromMinutes(14)); } } }