mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-04-24 05:47:22 -04:00
New: (Orpheus) Add options to prevent downloads without FL tokens
This commit is contained in:
parent
7dd289b5f9
commit
93c81bb7d3
1 changed files with 56 additions and 13 deletions
|
@ -10,6 +10,7 @@ using NzbDrone.Common.Extensions;
|
|||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.Indexers.Definitions.Gazelle;
|
||||
using NzbDrone.Core.Indexers.Exceptions;
|
||||
using NzbDrone.Core.Indexers.Settings;
|
||||
|
@ -80,40 +81,70 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|||
.SetHeader("Authorization", $"token {Settings.Apikey}")
|
||||
.Build();
|
||||
|
||||
var downloadBytes = Array.Empty<byte>();
|
||||
byte[] fileData;
|
||||
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.ExecuteProxiedAsync(request, Definition);
|
||||
downloadBytes = response.ResponseData;
|
||||
fileData = response.ResponseData;
|
||||
|
||||
if (downloadBytes.Length >= 1
|
||||
&& downloadBytes[0] != 'd' // simple test for torrent vs HTML content
|
||||
if (Settings.UseFreeleechToken == (int)OrpheusUseFreeleechTokens.Preferred
|
||||
&& fileData.Length >= 1
|
||||
&& fileData[0] != 'd' // simple test for torrent vs HTML content
|
||||
&& link.Query.Contains("usetoken=1"))
|
||||
{
|
||||
var html = Encoding.GetString(downloadBytes);
|
||||
var html = Encoding.GetString(fileData);
|
||||
|
||||
if (html.Contains("You do not have any freeleech tokens left.")
|
||||
|| html.Contains("You do not have enough freeleech tokens")
|
||||
|| html.Contains("This torrent is too large.")
|
||||
|| html.Contains("You cannot use tokens here"))
|
||||
{
|
||||
// download again without usetoken
|
||||
// Try to download again without usetoken
|
||||
request.Url = new HttpUri(link.ToString().Replace("&usetoken=1", ""));
|
||||
|
||||
response = await _httpClient.ExecuteProxiedAsync(request, Definition);
|
||||
downloadBytes = response.ResponseData;
|
||||
fileData = response.ResponseData;
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Debug("Downloaded for release finished ({0} bytes from {1})", fileData.Length, link.AbsoluteUri);
|
||||
}
|
||||
catch (HttpException ex)
|
||||
{
|
||||
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
_logger.Error(ex, "Downloading file for release failed since it no longer exists ({0})", link.AbsoluteUri);
|
||||
throw new ReleaseUnavailableException("Download failed", ex);
|
||||
}
|
||||
|
||||
if (ex.Response.StatusCode == HttpStatusCode.TooManyRequests)
|
||||
{
|
||||
_logger.Error("API Grab Limit reached for {0}", link.AbsoluteUri);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Error(ex, "Downloading for release failed ({0})", link.AbsoluteUri);
|
||||
}
|
||||
|
||||
throw new ReleaseDownloadException("Download failed", ex);
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
_logger.Error(ex, "Downloading for release failed ({0})", link.AbsoluteUri);
|
||||
|
||||
throw new ReleaseDownloadException("Download failed", ex);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_indexerStatusService.RecordFailure(Definition.Id);
|
||||
_logger.Error("Download failed");
|
||||
throw;
|
||||
}
|
||||
|
||||
ValidateDownloadData(downloadBytes);
|
||||
ValidateDownloadData(fileData);
|
||||
|
||||
return downloadBytes;
|
||||
return fileData;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,7 +406,7 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|||
.AddQueryParam("id", torrentId);
|
||||
|
||||
// Orpheus fails to download if usetoken=0 so we need to only add if we will use one
|
||||
if (_settings.UseFreeleechToken)
|
||||
if (_settings.UseFreeleechToken is (int)OrpheusUseFreeleechTokens.Preferred or (int)OrpheusUseFreeleechTokens.Required)
|
||||
{
|
||||
url = url.AddQueryParam("usetoken", "1");
|
||||
}
|
||||
|
@ -409,18 +440,30 @@ namespace NzbDrone.Core.Indexers.Definitions
|
|||
public OrpheusSettings()
|
||||
{
|
||||
Apikey = "";
|
||||
UseFreeleechToken = false;
|
||||
UseFreeleechToken = (int)OrpheusUseFreeleechTokens.Never;
|
||||
}
|
||||
|
||||
[FieldDefinition(2, Label = "API Key", HelpText = "API Key from the Site (Found in Settings => Access Settings)", Privacy = PrivacyLevel.ApiKey)]
|
||||
public string Apikey { get; set; }
|
||||
|
||||
[FieldDefinition(3, Label = "Use Freeleech Tokens", HelpText = "Use freeleech tokens when available", Type = FieldType.Checkbox)]
|
||||
public bool UseFreeleechToken { get; set; }
|
||||
[FieldDefinition(3, Type = FieldType.Select, Label = "Use Freeleech Tokens", SelectOptions = typeof(OrpheusUseFreeleechTokens), HelpText = "When to use freeleech tokens")]
|
||||
public int UseFreeleechToken { get; set; }
|
||||
|
||||
public override NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
}
|
||||
}
|
||||
|
||||
public enum OrpheusUseFreeleechTokens
|
||||
{
|
||||
[FieldOption(Label = "Never", Hint = "Do not use tokens")]
|
||||
Never = 0,
|
||||
|
||||
[FieldOption(Label = "Preferred", Hint = "Use token if possible")]
|
||||
Preferred = 1,
|
||||
|
||||
[FieldOption(Label = "Required", Hint = "Abort download if unable to use token")]
|
||||
Required = 2,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue