mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-10-02 16:52:04 +02:00
Fixed: (Rarbg) Move check response by status code to parser
This commit is contained in:
@@ -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<RarbgResponse>(response.HttpResponse);
|
||||
|
@@ -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<ReleaseInfo>();
|
||||
|
||||
Rarbg.CheckResponseByStatusCode(indexerResponse, _logger);
|
||||
CheckResponseByStatusCode(indexerResponse);
|
||||
|
||||
var jsonResponse = new HttpResponse<RarbgResponse>(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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user