mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
More AnimeTorrents work
This commit is contained in:
@@ -10,6 +10,7 @@ using NLog;
|
|||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Core.Annotations;
|
using NzbDrone.Core.Annotations;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
|
using NzbDrone.Core.Indexers.Exceptions;
|
||||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||||
using NzbDrone.Core.Parser;
|
using NzbDrone.Core.Parser;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
@@ -45,17 +46,19 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|||||||
|
|
||||||
protected override void DoLogin()
|
protected override void DoLogin()
|
||||||
{
|
{
|
||||||
|
UpdateCookies(null, null);
|
||||||
|
|
||||||
var requestBuilder = new HttpRequestBuilder(LoginUrl)
|
var requestBuilder = new HttpRequestBuilder(LoginUrl)
|
||||||
{
|
{
|
||||||
LogResponseContent = true
|
LogResponseContent = true,
|
||||||
|
AllowAutoRedirect = true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var loginPage = _httpClient.Execute(new HttpRequest(LoginUrl));
|
||||||
requestBuilder.Method = HttpMethod.POST;
|
requestBuilder.Method = HttpMethod.POST;
|
||||||
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
|
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
|
||||||
|
requestBuilder.SetCookies(loginPage.GetCookies());
|
||||||
|
|
||||||
var cookies = Cookies;
|
|
||||||
|
|
||||||
Cookies = null;
|
|
||||||
var authLoginRequest = requestBuilder
|
var authLoginRequest = requestBuilder
|
||||||
.AddFormParameter("username", Settings.Username)
|
.AddFormParameter("username", Settings.Username)
|
||||||
.AddFormParameter("password", Settings.Password)
|
.AddFormParameter("password", Settings.Password)
|
||||||
@@ -66,10 +69,16 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|||||||
|
|
||||||
var response = _httpClient.Execute(authLoginRequest);
|
var response = _httpClient.Execute(authLoginRequest);
|
||||||
|
|
||||||
cookies = response.GetCookies();
|
if (response.Content != null && response.Content.Contains("logout.php"))
|
||||||
UpdateCookies(cookies, DateTime.Now + TimeSpan.FromDays(30));
|
{
|
||||||
|
UpdateCookies(response.GetCookies(), DateTime.Now + TimeSpan.FromDays(30));
|
||||||
|
|
||||||
_logger.Debug("AnimeTorrents authentication succeeded.");
|
_logger.Debug("AnimeTorrents authentication succeeded");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IndexerAuthException("AnimeTorrents authentication failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool CheckIfLoginNeeded(HttpResponse httpResponse)
|
protected override bool CheckIfLoginNeeded(HttpResponse httpResponse)
|
||||||
|
@@ -21,7 +21,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet
|
|||||||
switch (indexerResponse.HttpResponse.StatusCode)
|
switch (indexerResponse.HttpResponse.StatusCode)
|
||||||
{
|
{
|
||||||
case HttpStatusCode.Unauthorized:
|
case HttpStatusCode.Unauthorized:
|
||||||
throw new ApiKeyException("API Key invalid or not authorized");
|
throw new IndexerAuthException("API Key invalid or not authorized");
|
||||||
case HttpStatusCode.NotFound:
|
case HttpStatusCode.NotFound:
|
||||||
throw new IndexerException(indexerResponse, "Indexer API call returned NotFound, the Indexer API may have changed.");
|
throw new IndexerException(indexerResponse, "Indexer API call returned NotFound, the Indexer API may have changed.");
|
||||||
case HttpStatusCode.ServiceUnavailable:
|
case HttpStatusCode.ServiceUnavailable:
|
||||||
|
@@ -35,12 +35,12 @@ namespace NzbDrone.Core.Indexers.Newznab
|
|||||||
|
|
||||||
if (code >= 100 && code <= 199)
|
if (code >= 100 && code <= 199)
|
||||||
{
|
{
|
||||||
throw new ApiKeyException(errorMessage);
|
throw new IndexerAuthException(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!indexerResponse.Request.Url.FullUri.Contains("apikey=") && (errorMessage == "Missing parameter" || errorMessage.Contains("apikey")))
|
if (!indexerResponse.Request.Url.FullUri.Contains("apikey=") && (errorMessage == "Missing parameter" || errorMessage.Contains("apikey")))
|
||||||
{
|
{
|
||||||
throw new ApiKeyException("Indexer requires an API key");
|
throw new IndexerAuthException("Indexer requires an API key");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorMessage == "Request limit reached")
|
if (errorMessage == "Request limit reached")
|
||||||
|
@@ -32,12 +32,12 @@ namespace NzbDrone.Core.Indexers.Torznab
|
|||||||
|
|
||||||
if (code >= 100 && code <= 199)
|
if (code >= 100 && code <= 199)
|
||||||
{
|
{
|
||||||
throw new ApiKeyException("Invalid API key");
|
throw new IndexerAuthException("Invalid API key");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!indexerResponse.Request.Url.FullUri.Contains("apikey=") && errorMessage == "Missing parameter")
|
if (!indexerResponse.Request.Url.FullUri.Contains("apikey=") && errorMessage == "Missing parameter")
|
||||||
{
|
{
|
||||||
throw new ApiKeyException("Indexer requires an API key");
|
throw new IndexerAuthException("Indexer requires an API key");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorMessage == "Request limit reached")
|
if (errorMessage == "Request limit reached")
|
||||||
|
@@ -1,17 +0,0 @@
|
|||||||
using NzbDrone.Common.Exceptions;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Indexers.Exceptions
|
|
||||||
{
|
|
||||||
public class ApiKeyException : NzbDroneException
|
|
||||||
{
|
|
||||||
public ApiKeyException(string message, params object[] args)
|
|
||||||
: base(message, args)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApiKeyException(string message)
|
|
||||||
: base(message)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,17 @@
|
|||||||
|
using NzbDrone.Common.Exceptions;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Indexers.Exceptions
|
||||||
|
{
|
||||||
|
public class IndexerAuthException : NzbDroneException
|
||||||
|
{
|
||||||
|
public IndexerAuthException(string message, params object[] args)
|
||||||
|
: base(message, args)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public IndexerAuthException(string message)
|
||||||
|
: base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -304,10 +304,10 @@ namespace NzbDrone.Core.Indexers
|
|||||||
_indexerStatusService.RecordFailure(Definition.Id, TimeSpan.FromHours(1));
|
_indexerStatusService.RecordFailure(Definition.Id, TimeSpan.FromHours(1));
|
||||||
_logger.Warn("API Request Limit reached for {0}", this);
|
_logger.Warn("API Request Limit reached for {0}", this);
|
||||||
}
|
}
|
||||||
catch (ApiKeyException)
|
catch (IndexerAuthException)
|
||||||
{
|
{
|
||||||
_indexerStatusService.RecordFailure(Definition.Id);
|
_indexerStatusService.RecordFailure(Definition.Id);
|
||||||
_logger.Warn("Invalid API Key for {0} {1}", this, url);
|
_logger.Warn("Invalid Credentials for {0} {1}", this, url);
|
||||||
}
|
}
|
||||||
catch (CloudFlareCaptchaException ex)
|
catch (CloudFlareCaptchaException ex)
|
||||||
{
|
{
|
||||||
@@ -480,9 +480,9 @@ namespace NzbDrone.Core.Indexers
|
|||||||
return new ValidationFailure(string.Empty, "Query successful, but no results were returned from your indexer. This may be an issue with the indexer or your indexer category settings.");
|
return new ValidationFailure(string.Empty, "Query successful, but no results were returned from your indexer. This may be an issue with the indexer or your indexer category settings.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ApiKeyException ex)
|
catch (IndexerAuthException ex)
|
||||||
{
|
{
|
||||||
_logger.Warn("Indexer returned result for RSS URL, API Key appears to be invalid: " + ex.Message);
|
_logger.Warn("Indexer returned result for RSS URL, Credentials appears to be invalid: " + ex.Message);
|
||||||
|
|
||||||
return new ValidationFailure("ApiKey", "Invalid API Key");
|
return new ValidationFailure("ApiKey", "Invalid API Key");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user