parent
2641108e84
commit
f0fceb1499
@ -1,142 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using FluentAssertions;
|
|
||||||
using Moq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
|
||||||
using NzbDrone.Common.Http;
|
|
||||||
using NzbDrone.Core.Indexers;
|
|
||||||
using NzbDrone.Core.Indexers.Rarbg;
|
|
||||||
using NzbDrone.Core.Parser.Model;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
|
||||||
using NzbDrone.Test.Common;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.IndexerTests.RarbgTests
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class RarbgFixture : CoreTest<Rarbg>
|
|
||||||
{
|
|
||||||
[SetUp]
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
Subject.Definition = new IndexerDefinition()
|
|
||||||
{
|
|
||||||
Name = "Rarbg",
|
|
||||||
Settings = new RarbgSettings()
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<IRarbgTokenProvider>()
|
|
||||||
.Setup(v => v.GetToken(It.IsAny<RarbgSettings>()))
|
|
||||||
.Returns("validtoken");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_parse_recent_feed_from_Rarbg()
|
|
||||||
{
|
|
||||||
var recentFeed = ReadAllText(@"Files/Indexers/Rarbg/RecentFeed_v2.json");
|
|
||||||
|
|
||||||
Mocker.GetMock<IHttpClient>()
|
|
||||||
.Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.Get)))
|
|
||||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), recentFeed));
|
|
||||||
|
|
||||||
var releases = Subject.FetchRecent();
|
|
||||||
|
|
||||||
releases.Should().HaveCount(4);
|
|
||||||
releases.First().Should().BeOfType<TorrentInfo>();
|
|
||||||
|
|
||||||
var torrentInfo = releases.First() as TorrentInfo;
|
|
||||||
|
|
||||||
torrentInfo.Title.Should().Be("Sense8.S01E01.WEBRip.x264-FGT");
|
|
||||||
torrentInfo.DownloadProtocol.Should().Be(DownloadProtocol.Torrent);
|
|
||||||
torrentInfo.DownloadUrl.Should().Be("magnet:?xt=urn:btih:d8bde635f573acb390c7d7e7efc1556965fdc802&dn=Sense8.S01E01.WEBRip.x264-FGT&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce");
|
|
||||||
torrentInfo.InfoUrl.Should().Be($"https://torrentapi.org/redirect_to_info.php?token=i5cx7b9agd&p=8_6_4_4_5_6__d8bde635f5&app_id={BuildInfo.AppName}");
|
|
||||||
torrentInfo.Indexer.Should().Be(Subject.Definition.Name);
|
|
||||||
torrentInfo.PublishDate.Should().Be(DateTime.Parse("2015-06-05 16:58:11 +0000").ToUniversalTime());
|
|
||||||
torrentInfo.Size.Should().Be(564198371);
|
|
||||||
torrentInfo.InfoHash.Should().BeNull();
|
|
||||||
torrentInfo.MagnetUrl.Should().BeNull();
|
|
||||||
torrentInfo.Peers.Should().Be(304 + 200);
|
|
||||||
torrentInfo.Seeders.Should().Be(304);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_parse_error_20_as_empty_results()
|
|
||||||
{
|
|
||||||
Mocker.GetMock<IHttpClient>()
|
|
||||||
.Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.Get)))
|
|
||||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), "{ error_code: 20, error: \"some message\" }"));
|
|
||||||
|
|
||||||
var releases = Subject.FetchRecent();
|
|
||||||
|
|
||||||
releases.Should().HaveCount(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_warn_on_unknown_error()
|
|
||||||
{
|
|
||||||
Mocker.GetMock<IHttpClient>()
|
|
||||||
.Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.Get)))
|
|
||||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), "{ error_code: 25, error: \"some message\" }"));
|
|
||||||
|
|
||||||
var releases = Subject.FetchRecent();
|
|
||||||
|
|
||||||
releases.Should().HaveCount(0);
|
|
||||||
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_warn_and_record_failure_on_429_response()
|
|
||||||
{
|
|
||||||
Mocker.GetMock<IHttpClient>()
|
|
||||||
.Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.Get)))
|
|
||||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), "", HttpStatusCode.TooManyRequests));
|
|
||||||
|
|
||||||
var releases = Subject.FetchRecent();
|
|
||||||
|
|
||||||
releases.Should().HaveCount(0);
|
|
||||||
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
|
||||||
|
|
||||||
Mocker.GetMock<IIndexerStatusService>()
|
|
||||||
.Verify(v => v.RecordFailure(It.IsAny<int>(), It.Is<TimeSpan>(t => t == TimeSpan.FromMinutes(2))));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_warn_and_record_failure_on_520_response()
|
|
||||||
{
|
|
||||||
Mocker.GetMock<IHttpClient>()
|
|
||||||
.Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.Get)))
|
|
||||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), "", (HttpStatusCode)520));
|
|
||||||
|
|
||||||
var releases = Subject.FetchRecent();
|
|
||||||
|
|
||||||
releases.Should().HaveCount(0);
|
|
||||||
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
|
||||||
|
|
||||||
Mocker.GetMock<IIndexerStatusService>()
|
|
||||||
.Verify(v => v.RecordFailure(It.IsAny<int>(), It.Is<TimeSpan>(t => t == TimeSpan.FromMinutes(3))));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uncomment when RarbgParser is updated
|
|
||||||
// [Test]
|
|
||||||
// public void should_warn_and_record_failure_on_200_response_with_rate_limit()
|
|
||||||
// {
|
|
||||||
// Mocker.GetMock<IHttpClient>()
|
|
||||||
// .Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.Get)))
|
|
||||||
// .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), "{ rate_limit: 1 }"));
|
|
||||||
//
|
|
||||||
// var releases = Subject.FetchRecent();
|
|
||||||
//
|
|
||||||
// releases.Should().HaveCount(0);
|
|
||||||
//
|
|
||||||
// ExceptionVerification.ExpectedWarns(1);
|
|
||||||
//
|
|
||||||
// Mocker.GetMock<IIndexerStatusService>()
|
|
||||||
// .Verify(v => v.RecordFailure(It.IsAny<int>(), It.Is<TimeSpan>(t => t == TimeSpan.FromMinutes(5))));
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using NLog;
|
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
|
||||||
using NzbDrone.Common.Extensions;
|
|
||||||
using NzbDrone.Common.Http;
|
|
||||||
using NzbDrone.Core.Configuration;
|
|
||||||
using NzbDrone.Core.Exceptions;
|
|
||||||
using NzbDrone.Core.Http.CloudFlare;
|
|
||||||
using NzbDrone.Core.Parser;
|
|
||||||
using NzbDrone.Core.Validation;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Indexers.Rarbg
|
|
||||||
{
|
|
||||||
public class Rarbg : HttpIndexerBase<RarbgSettings>
|
|
||||||
{
|
|
||||||
private readonly IRarbgTokenProvider _tokenProvider;
|
|
||||||
|
|
||||||
public override string Name => "Rarbg";
|
|
||||||
|
|
||||||
public override DownloadProtocol Protocol => DownloadProtocol.Torrent;
|
|
||||||
public override TimeSpan RateLimit => TimeSpan.FromSeconds(4);
|
|
||||||
|
|
||||||
public Rarbg(IRarbgTokenProvider tokenProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger)
|
|
||||||
: base(httpClient, indexerStatusService, configService, parsingService, logger)
|
|
||||||
{
|
|
||||||
_tokenProvider = tokenProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override IIndexerRequestGenerator GetRequestGenerator()
|
|
||||||
{
|
|
||||||
return new RarbgRequestGenerator(_tokenProvider) { Settings = Settings };
|
|
||||||
}
|
|
||||||
|
|
||||||
public override IParseIndexerResponse GetParser()
|
|
||||||
{
|
|
||||||
return new RarbgParser();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object RequestAction(string action, IDictionary<string, string> query)
|
|
||||||
{
|
|
||||||
if (action == "checkCaptcha")
|
|
||||||
{
|
|
||||||
Settings.Validate().Filter("BaseUrl").ThrowOnError();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var request = new HttpRequestBuilder(Settings.BaseUrl.Trim('/'))
|
|
||||||
.Resource($"/pubapi_v2.php?get_token=get_token&app_id={BuildInfo.AppName}")
|
|
||||||
.Accept(HttpAccept.Json)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
_httpClient.Get(request);
|
|
||||||
}
|
|
||||||
catch (CloudFlareCaptchaException ex)
|
|
||||||
{
|
|
||||||
return new
|
|
||||||
{
|
|
||||||
captchaRequest = new
|
|
||||||
{
|
|
||||||
host = ex.CaptchaRequest.Host,
|
|
||||||
ray = ex.CaptchaRequest.Ray,
|
|
||||||
siteKey = ex.CaptchaRequest.SiteKey,
|
|
||||||
secretToken = ex.CaptchaRequest.SecretToken,
|
|
||||||
responseUrl = ex.CaptchaRequest.ResponseUrl.FullUri,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return new
|
|
||||||
{
|
|
||||||
captchaToken = ""
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else if (action == "getCaptchaCookie")
|
|
||||||
{
|
|
||||||
if (query["responseUrl"].IsNullOrWhiteSpace())
|
|
||||||
{
|
|
||||||
throw new BadRequestException("QueryParam responseUrl invalid.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query["ray"].IsNullOrWhiteSpace())
|
|
||||||
{
|
|
||||||
throw new BadRequestException("QueryParam ray invalid.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query["captchaResponse"].IsNullOrWhiteSpace())
|
|
||||||
{
|
|
||||||
throw new BadRequestException("QueryParam captchaResponse invalid.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = new HttpRequestBuilder(query["responseUrl"])
|
|
||||||
.AddQueryParam("id", query["ray"])
|
|
||||||
.AddQueryParam("g-recaptcha-response", query["captchaResponse"])
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
request.UseSimplifiedUserAgent = true;
|
|
||||||
request.AllowAutoRedirect = false;
|
|
||||||
|
|
||||||
var response = _httpClient.Get(request);
|
|
||||||
|
|
||||||
var cfClearanceCookie = response.GetCookies()["cf_clearance"];
|
|
||||||
|
|
||||||
return new
|
|
||||||
{
|
|
||||||
captchaToken = cfClearanceCookie
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return new { };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
|
||||||
using NzbDrone.Common.Http;
|
|
||||||
using NzbDrone.Core.Indexers.Exceptions;
|
|
||||||
using NzbDrone.Core.Parser.Model;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Indexers.Rarbg
|
|
||||||
{
|
|
||||||
public class RarbgParser : IParseIndexerResponse
|
|
||||||
{
|
|
||||||
private static readonly Regex RegexGuid = new Regex(@"^magnet:\?xt=urn:btih:([a-f0-9]+)", RegexOptions.Compiled);
|
|
||||||
|
|
||||||
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
|
||||||
{
|
|
||||||
var results = new List<ReleaseInfo>();
|
|
||||||
|
|
||||||
switch (indexerResponse.HttpResponse.StatusCode)
|
|
||||||
{
|
|
||||||
case HttpStatusCode.TooManyRequests:
|
|
||||||
throw new RequestLimitReachedException("Indexer API limit reached", TimeSpan.FromMinutes(2));
|
|
||||||
case (HttpStatusCode)520:
|
|
||||||
throw new RequestLimitReachedException("Indexer API error. Likely rate limited by origin server", TimeSpan.FromMinutes(3));
|
|
||||||
default:
|
|
||||||
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
|
|
||||||
{
|
|
||||||
throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected status code [{0}]", indexerResponse.HttpResponse.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
var jsonResponse = new HttpResponse<RarbgResponse>(indexerResponse.HttpResponse);
|
|
||||||
|
|
||||||
if (jsonResponse.Resource.error_code.HasValue)
|
|
||||||
{
|
|
||||||
if (jsonResponse.Resource.error_code == 5 || jsonResponse.Resource.error_code == 8
|
|
||||||
|| jsonResponse.Resource.error_code == 9 || jsonResponse.Resource.error_code == 10
|
|
||||||
|| jsonResponse.Resource.error_code == 13 || jsonResponse.Resource.error_code == 14
|
|
||||||
|| jsonResponse.Resource.error_code == 20)
|
|
||||||
{
|
|
||||||
// No results, rate limit, tvdbid not found/invalid, or imdbid not found/invalid
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IndexerException(indexerResponse, "Indexer API call returned error {0}: {1}", jsonResponse.Resource.error_code, jsonResponse.Resource.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jsonResponse.Resource.torrent_results == null)
|
|
||||||
{
|
|
||||||
// Despite this being the requested behaviour it appears to be problematic, commenting it out for now
|
|
||||||
// if (jsonResponse.Resource.rate_limit == 1)
|
|
||||||
// {
|
|
||||||
// throw new RequestLimitReachedException("Indexer API limit reached", TimeSpan.FromMinutes(5));
|
|
||||||
// }
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var torrent in jsonResponse.Resource.torrent_results)
|
|
||||||
{
|
|
||||||
var torrentInfo = new TorrentInfo();
|
|
||||||
|
|
||||||
torrentInfo.Guid = GetGuid(torrent);
|
|
||||||
torrentInfo.Title = torrent.title;
|
|
||||||
torrentInfo.Size = torrent.size;
|
|
||||||
torrentInfo.DownloadUrl = torrent.download;
|
|
||||||
torrentInfo.InfoUrl = $"{torrent.info_page}&app_id={BuildInfo.AppName}";
|
|
||||||
torrentInfo.PublishDate = torrent.pubdate.ToUniversalTime();
|
|
||||||
torrentInfo.Seeders = torrent.seeders;
|
|
||||||
torrentInfo.Peers = torrent.leechers + torrent.seeders;
|
|
||||||
|
|
||||||
results.Add(torrentInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
private 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Net;
|
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
|
||||||
using NzbDrone.Common.Extensions;
|
|
||||||
using NzbDrone.Common.Http;
|
|
||||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Indexers.Rarbg
|
|
||||||
{
|
|
||||||
public class RarbgRequestGenerator : IIndexerRequestGenerator
|
|
||||||
{
|
|
||||||
private readonly IRarbgTokenProvider _tokenProvider;
|
|
||||||
|
|
||||||
public RarbgSettings Settings { get; set; }
|
|
||||||
|
|
||||||
public RarbgRequestGenerator(IRarbgTokenProvider tokenProvider)
|
|
||||||
{
|
|
||||||
_tokenProvider = tokenProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IndexerPageableRequestChain GetRecentRequests()
|
|
||||||
{
|
|
||||||
var pageableRequests = new IndexerPageableRequestChain();
|
|
||||||
|
|
||||||
pageableRequests.Add(GetPagedRequests("list", null, null));
|
|
||||||
|
|
||||||
return pageableRequests;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
|
|
||||||
{
|
|
||||||
var pageableRequests = new IndexerPageableRequestChain();
|
|
||||||
|
|
||||||
pageableRequests.Add(GetPagedRequests("search", null, "{0}+{1}", searchCriteria.CleanArtistQuery, searchCriteria.CleanAlbumQuery));
|
|
||||||
|
|
||||||
return pageableRequests;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
|
|
||||||
{
|
|
||||||
var pageableRequests = new IndexerPageableRequestChain();
|
|
||||||
|
|
||||||
pageableRequests.Add(GetPagedRequests("search", null, "{0}", searchCriteria.CleanArtistQuery));
|
|
||||||
|
|
||||||
return pageableRequests;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerable<IndexerRequest> GetPagedRequests(string mode, int? tvdbId, string query, params object[] args)
|
|
||||||
{
|
|
||||||
var requestBuilder = new HttpRequestBuilder(Settings.BaseUrl)
|
|
||||||
.Resource("/pubapi_v2.php")
|
|
||||||
.Accept(HttpAccept.Json);
|
|
||||||
|
|
||||||
requestBuilder.SuppressHttpErrorStatusCodes = new[] { HttpStatusCode.TooManyRequests, (HttpStatusCode)520 };
|
|
||||||
|
|
||||||
if (Settings.CaptchaToken.IsNotNullOrWhiteSpace())
|
|
||||||
{
|
|
||||||
requestBuilder.UseSimplifiedUserAgent = true;
|
|
||||||
requestBuilder.SetCookie("cf_clearance", Settings.CaptchaToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
requestBuilder.AddQueryParam("mode", mode);
|
|
||||||
|
|
||||||
if (tvdbId.HasValue)
|
|
||||||
{
|
|
||||||
requestBuilder.AddQueryParam("search_tvdb", tvdbId.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.IsNotNullOrWhiteSpace())
|
|
||||||
{
|
|
||||||
requestBuilder.AddQueryParam("search_string", string.Format(query, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Settings.RankedOnly)
|
|
||||||
{
|
|
||||||
requestBuilder.AddQueryParam("ranked", "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
requestBuilder.AddQueryParam("category", "1;23;24;25;26");
|
|
||||||
requestBuilder.AddQueryParam("limit", "100");
|
|
||||||
requestBuilder.AddQueryParam("token", _tokenProvider.GetToken(Settings));
|
|
||||||
requestBuilder.AddQueryParam("format", "json_extended");
|
|
||||||
requestBuilder.AddQueryParam("app_id", BuildInfo.AppName);
|
|
||||||
|
|
||||||
yield return new IndexerRequest(requestBuilder.Build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Indexers.Rarbg
|
|
||||||
{
|
|
||||||
public class RarbgResponse
|
|
||||||
{
|
|
||||||
public string error { get; set; }
|
|
||||||
public int? error_code { get; set; }
|
|
||||||
public int? rate_limit { get; set; }
|
|
||||||
public List<RarbgTorrent> torrent_results { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RarbgTorrent
|
|
||||||
{
|
|
||||||
public string title { get; set; }
|
|
||||||
public string category { get; set; }
|
|
||||||
public string download { get; set; }
|
|
||||||
public int? seeders { get; set; }
|
|
||||||
public int? leechers { get; set; }
|
|
||||||
public long size { get; set; }
|
|
||||||
public DateTime pubdate { get; set; }
|
|
||||||
public RarbgTorrentInfo episode_info { get; set; }
|
|
||||||
public int? ranked { get; set; }
|
|
||||||
public string info_page { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RarbgTorrentInfo
|
|
||||||
{
|
|
||||||
// For Future if RARBG decides to return metadata
|
|
||||||
public string artist { get; set; }
|
|
||||||
public string album { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
using FluentValidation;
|
|
||||||
using NzbDrone.Core.Annotations;
|
|
||||||
using NzbDrone.Core.Validation;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Indexers.Rarbg
|
|
||||||
{
|
|
||||||
public class RarbgSettingsValidator : AbstractValidator<RarbgSettings>
|
|
||||||
{
|
|
||||||
public RarbgSettingsValidator()
|
|
||||||
{
|
|
||||||
RuleFor(c => c.BaseUrl).ValidRootUrl();
|
|
||||||
|
|
||||||
RuleFor(c => c.SeedCriteria).SetValidator(_ => new SeedCriteriaSettingsValidator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RarbgSettings : ITorrentIndexerSettings
|
|
||||||
{
|
|
||||||
private static readonly RarbgSettingsValidator Validator = new RarbgSettingsValidator();
|
|
||||||
|
|
||||||
public RarbgSettings()
|
|
||||||
{
|
|
||||||
BaseUrl = "https://torrentapi.org";
|
|
||||||
RankedOnly = false;
|
|
||||||
MinimumSeeders = IndexerDefaults.MINIMUM_SEEDERS;
|
|
||||||
}
|
|
||||||
|
|
||||||
[FieldDefinition(0, Label = "API URL", HelpText = "URL to Rarbg api, not the website.")]
|
|
||||||
public string BaseUrl { get; set; }
|
|
||||||
|
|
||||||
[FieldDefinition(1, Type = FieldType.Checkbox, Label = "Ranked Only", HelpText = "Only include ranked results.")]
|
|
||||||
public bool RankedOnly { get; set; }
|
|
||||||
|
|
||||||
[FieldDefinition(2, Type = FieldType.Captcha, Label = "CAPTCHA Token", HelpText = "CAPTCHA Clearance token used to handle CloudFlare Anti-DDOS measures on shared-ip VPNs.")]
|
|
||||||
public string CaptchaToken { get; set; }
|
|
||||||
|
|
||||||
[FieldDefinition(3, Type = FieldType.Textbox, Label = "Minimum Seeders", HelpText = "Minimum number of seeders required.", Advanced = true)]
|
|
||||||
public int MinimumSeeders { get; set; }
|
|
||||||
|
|
||||||
[FieldDefinition(4)]
|
|
||||||
public SeedCriteriaSettings SeedCriteria { get; set; } = new SeedCriteriaSettings();
|
|
||||||
|
|
||||||
[FieldDefinition(5, Type = FieldType.Number, Label = "Early Download Limit", HelpText = "Time before release date Lidarr will download from this indexer, empty is no limit", Advanced = true)]
|
|
||||||
public int? EarlyReleaseLimit { get; set; }
|
|
||||||
|
|
||||||
public NzbDroneValidationResult Validate()
|
|
||||||
{
|
|
||||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using NLog;
|
|
||||||
using NzbDrone.Common.Cache;
|
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
|
||||||
using NzbDrone.Common.Extensions;
|
|
||||||
using NzbDrone.Common.Http;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Indexers.Rarbg
|
|
||||||
{
|
|
||||||
public interface IRarbgTokenProvider
|
|
||||||
{
|
|
||||||
string GetToken(RarbgSettings settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RarbgTokenProvider : IRarbgTokenProvider
|
|
||||||
{
|
|
||||||
private readonly IHttpClient _httpClient;
|
|
||||||
private readonly ICached<string> _tokenCache;
|
|
||||||
private readonly Logger _logger;
|
|
||||||
|
|
||||||
public RarbgTokenProvider(IHttpClient httpClient, ICacheManager cacheManager, Logger logger)
|
|
||||||
{
|
|
||||||
_httpClient = httpClient;
|
|
||||||
_tokenCache = cacheManager.GetCache<string>(GetType());
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetToken(RarbgSettings settings)
|
|
||||||
{
|
|
||||||
return _tokenCache.Get(settings.BaseUrl,
|
|
||||||
() =>
|
|
||||||
{
|
|
||||||
var requestBuilder = new HttpRequestBuilder(settings.BaseUrl.Trim('/'))
|
|
||||||
.WithRateLimit(3.0)
|
|
||||||
.Resource($"/pubapi_v2.php?get_token=get_token&app_id={BuildInfo.AppName}")
|
|
||||||
.Accept(HttpAccept.Json);
|
|
||||||
|
|
||||||
if (settings.CaptchaToken.IsNotNullOrWhiteSpace())
|
|
||||||
{
|
|
||||||
requestBuilder.UseSimplifiedUserAgent = true;
|
|
||||||
requestBuilder.SetCookie("cf_clearance", settings.CaptchaToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
var response = _httpClient.Get<JObject>(requestBuilder.Build());
|
|
||||||
|
|
||||||
return response.Resource["token"].ToString();
|
|
||||||
},
|
|
||||||
TimeSpan.FromMinutes(14.0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue