Fixed: (RarBG) Handle HTTP 200 Rate Limiting False Positive

Fixes: #1277
Finishes: #1169
Related: #1380

partially reverts 5cc044aa8f
pull/1441/head
Bakerboy448 2 years ago committed by Bogdan
parent 252cd97e35
commit ea6d01a49b

@ -12,7 +12,7 @@ namespace NzbDrone.Core.Indexers.Rarbg
{ {
public class RarbgParser : IParseIndexerResponse public class RarbgParser : IParseIndexerResponse
{ {
private static readonly Regex RegexGuid = new Regex(@"^magnet:\?xt=urn:btih:([a-f0-9]+)", RegexOptions.Compiled); private static readonly Regex RegexGuid = new (@"^magnet:\?xt=urn:btih:([a-f0-9]+)", RegexOptions.Compiled);
private readonly IndexerCapabilities _capabilities; private readonly IndexerCapabilities _capabilities;
private readonly Logger _logger; private readonly Logger _logger;
@ -23,6 +23,8 @@ namespace NzbDrone.Core.Indexers.Rarbg
_logger = logger; _logger = logger;
} }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse) public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
{ {
var results = new List<ReleaseInfo>(); var results = new List<ReleaseInfo>();
@ -48,9 +50,9 @@ namespace NzbDrone.Core.Indexers.Rarbg
{ {
var reason = $"{jsonResponse.Resource.error} ({jsonResponse.Resource.error_code})"; var reason = $"{jsonResponse.Resource.error} ({jsonResponse.Resource.error_code})";
if (jsonResponse.Resource.rate_limit is 1) if ((reason == "5") || (jsonResponse.Resource.rate_limit is 1 && jsonResponse.Resource.torrent_results == null))
{ {
_logger.Debug("No results due to rate limiting. Reason: {0}", reason); throw new TooManyRequestsException(indexerResponse.HttpRequest, indexerResponse.HttpResponse, TimeSpan.FromMinutes(5));
} }
else else
{ {
@ -65,24 +67,30 @@ namespace NzbDrone.Core.Indexers.Rarbg
if (jsonResponse.Resource.torrent_results == null) if (jsonResponse.Resource.torrent_results == null)
{ {
if (jsonResponse.Resource.rate_limit == 1)
{
throw new TooManyRequestsException(indexerResponse.HttpRequest, indexerResponse.HttpResponse, TimeSpan.FromMinutes(5));
}
return results; return results;
} }
foreach (var torrent in jsonResponse.Resource.torrent_results) foreach (var torrent in jsonResponse.Resource.torrent_results)
{ {
var torrentInfo = new TorrentInfo(); var torrentInfo = new TorrentInfo
{
torrentInfo.Guid = GetGuid(torrent); Guid = GetGuid(torrent),
torrentInfo.Categories = _capabilities.Categories.MapTrackerCatDescToNewznab(torrent.category); Categories = _capabilities.Categories.MapTrackerCatDescToNewznab(torrent.category),
torrentInfo.Title = torrent.title; Title = torrent.title,
torrentInfo.Size = torrent.size; Size = torrent.size,
torrentInfo.DownloadUrl = torrent.download; DownloadUrl = torrent.download,
torrentInfo.InfoUrl = $"{torrent.info_page}&app_id={BuildInfo.AppName}"; InfoUrl = $"{torrent.info_page}&app_id={BuildInfo.AppName}",
torrentInfo.PublishDate = torrent.pubdate.ToUniversalTime(); PublishDate = torrent.pubdate.ToUniversalTime(),
torrentInfo.Seeders = torrent.seeders; Seeders = torrent.seeders,
torrentInfo.Peers = torrent.leechers + torrent.seeders; Peers = torrent.leechers + torrent.seeders,
torrentInfo.DownloadVolumeFactor = 0; DownloadVolumeFactor = 0,
torrentInfo.UploadVolumeFactor = 1; UploadVolumeFactor = 1
};
if (torrent.movie_info != null) if (torrent.movie_info != null)
{ {
@ -103,8 +111,6 @@ namespace NzbDrone.Core.Indexers.Rarbg
return results; return results;
} }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
private string GetGuid(RarbgTorrent torrent) private string GetGuid(RarbgTorrent torrent)
{ {
var match = RegexGuid.Match(torrent.download); var match = RegexGuid.Match(torrent.download);

Loading…
Cancel
Save