Fixed: (FreeboxDownload) Set seed limits in client

cardigann-contains
Bogdan 1 year ago
parent 7cb465787e
commit 8bd6a313b7

@ -14,8 +14,8 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
public interface IFreeboxDownloadProxy public interface IFreeboxDownloadProxy
{ {
void Authenticate(FreeboxDownloadSettings settings); void Authenticate(FreeboxDownloadSettings settings);
string AddTaskFromUrl(string url, string directory, bool addPaused, bool addFirst, FreeboxDownloadSettings settings); string AddTaskFromUrl(string url, string directory, bool addPaused, bool addFirst, double? seedRatio, FreeboxDownloadSettings settings);
string AddTaskFromFile(string fileName, byte[] fileContent, string directory, bool addPaused, bool addFirst, FreeboxDownloadSettings settings); string AddTaskFromFile(string fileName, byte[] fileContent, string directory, bool addPaused, bool addFirst, double? seedRatio, FreeboxDownloadSettings settings);
void DeleteTask(string id, bool deleteData, FreeboxDownloadSettings settings); void DeleteTask(string id, bool deleteData, FreeboxDownloadSettings settings);
FreeboxDownloadConfiguration GetDownloadConfiguration(FreeboxDownloadSettings settings); FreeboxDownloadConfiguration GetDownloadConfiguration(FreeboxDownloadSettings settings);
List<FreeboxDownloadTask> GetTasks(FreeboxDownloadSettings settings); List<FreeboxDownloadTask> GetTasks(FreeboxDownloadSettings settings);
@ -46,7 +46,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
} }
} }
public string AddTaskFromUrl(string url, string directory, bool addPaused, bool addFirst, FreeboxDownloadSettings settings) public string AddTaskFromUrl(string url, string directory, bool addPaused, bool addFirst, double? seedRatio, FreeboxDownloadSettings settings)
{ {
var request = BuildRequest(settings).Resource("/downloads/add").Post(); var request = BuildRequest(settings).Resource("/downloads/add").Post();
request.Headers.ContentType = "application/x-www-form-urlencoded"; request.Headers.ContentType = "application/x-www-form-urlencoded";
@ -60,12 +60,12 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
var response = ProcessRequest<FreeboxDownloadTask>(request.Build(), settings); var response = ProcessRequest<FreeboxDownloadTask>(request.Build(), settings);
SetTorrentSettings(response.Result.Id, addPaused, addFirst, settings); SetTorrentSettings(response.Result.Id, addPaused, addFirst, seedRatio, settings);
return response.Result.Id; return response.Result.Id;
} }
public string AddTaskFromFile(string fileName, byte[] fileContent, string directory, bool addPaused, bool addFirst, FreeboxDownloadSettings settings) public string AddTaskFromFile(string fileName, byte[] fileContent, string directory, bool addPaused, bool addFirst, double? seedRatio, FreeboxDownloadSettings settings)
{ {
var request = BuildRequest(settings).Resource("/downloads/add").Post(); var request = BuildRequest(settings).Resource("/downloads/add").Post();
@ -78,7 +78,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
var response = ProcessRequest<FreeboxDownloadTask>(request.Build(), settings); var response = ProcessRequest<FreeboxDownloadTask>(request.Build(), settings);
SetTorrentSettings(response.Result.Id, addPaused, addFirst, settings); SetTorrentSettings(response.Result.Id, addPaused, addFirst, seedRatio, settings);
return response.Result.Id; return response.Result.Id;
} }
@ -118,7 +118,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
return $"{settings.Host}:{settings.AppId}:{settings.AppToken}"; return $"{settings.Host}:{settings.AppId}:{settings.AppToken}";
} }
private void SetTorrentSettings(string id, bool addPaused, bool addFirst, FreeboxDownloadSettings settings) private void SetTorrentSettings(string id, bool addPaused, bool addFirst, double? seedRatio, FreeboxDownloadSettings settings)
{ {
var request = BuildRequest(settings).Resource("/downloads/" + id).Build(); var request = BuildRequest(settings).Resource("/downloads/" + id).Build();
@ -136,6 +136,12 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
body.Add("queue_pos", "1"); body.Add("queue_pos", "1");
} }
if (seedRatio != null)
{
// 0 means unlimited seeding
body.Add("stop_ratio", seedRatio);
}
if (body.Count == 0) if (body.Count == 0)
{ {
return; return;

@ -36,7 +36,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
public class FreeboxDownloadSettings : IProviderConfig public class FreeboxDownloadSettings : IProviderConfig
{ {
private static readonly FreeboxDownloadSettingsValidator Validator = new FreeboxDownloadSettingsValidator(); private static readonly FreeboxDownloadSettingsValidator Validator = new ();
public FreeboxDownloadSettings() public FreeboxDownloadSettings()
{ {
@ -73,7 +73,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
[FieldDefinition(8, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(FreeboxDownloadPriority), HelpText = "Priority to use when grabbing")] [FieldDefinition(8, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(FreeboxDownloadPriority), HelpText = "Priority to use when grabbing")]
public int Priority { get; set; } public int Priority { get; set; }
[FieldDefinition(10, Label = "Add Paused", Type = FieldType.Checkbox)] [FieldDefinition(9, Label = "Add Paused", Type = FieldType.Checkbox)]
public bool AddPaused { get; set; } public bool AddPaused { get; set; }
public NzbDroneValidationResult Validate() public NzbDroneValidationResult Validate()

@ -1,12 +1,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using FluentValidation.Results; using FluentValidation.Results;
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.Clients.FreeboxDownload.Responses;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -28,20 +26,15 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
} }
public override string Name => "Freebox Download"; public override string Name => "Freebox Download";
public override bool SupportsCategories => true; public override bool SupportsCategories => true;
protected IEnumerable<FreeboxDownloadTask> GetTorrents()
{
return _proxy.GetTasks(Settings).Where(v => v.Type.ToLower() == FreeboxDownloadTaskType.Bt.ToString().ToLower());
}
protected override string AddFromMagnetLink(TorrentInfo release, string hash, string magnetLink) protected override string AddFromMagnetLink(TorrentInfo release, string hash, string magnetLink)
{ {
return _proxy.AddTaskFromUrl(magnetLink, return _proxy.AddTaskFromUrl(magnetLink,
GetDownloadDirectory(release).EncodeBase64(), GetDownloadDirectory(release).EncodeBase64(),
ToBePaused(), ToBePaused(),
ToBeQueuedFirst(), ToBeQueuedFirst(),
GetSeedRatio(release),
Settings); Settings);
} }
@ -52,6 +45,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
GetDownloadDirectory(release).EncodeBase64(), GetDownloadDirectory(release).EncodeBase64(),
ToBePaused(), ToBePaused(),
ToBeQueuedFirst(), ToBeQueuedFirst(),
GetSeedRatio(release),
Settings); Settings);
} }
@ -61,6 +55,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
GetDownloadDirectory(release).EncodeBase64(), GetDownloadDirectory(release).EncodeBase64(),
ToBePaused(), ToBePaused(),
ToBeQueuedFirst(), ToBeQueuedFirst(),
GetSeedRatio(release),
Settings); Settings);
} }
@ -108,16 +103,21 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
var destDir = _proxy.GetDownloadConfiguration(Settings).DecodedDownloadDirectory.TrimEnd('/'); var destDir = _proxy.GetDownloadConfiguration(Settings).DecodedDownloadDirectory.TrimEnd('/');
if (Settings.Category.IsNotNullOrWhiteSpace()) var category = GetCategoryForRelease(release) ?? Settings.Category;
{
var category = GetCategoryForRelease(release) ?? Settings.Category;
if (category.IsNotNullOrWhiteSpace())
{
destDir = $"{destDir}/{category}"; destDir = $"{destDir}/{category}";
} }
return destDir; return destDir;
} }
private bool ToBePaused()
{
return Settings.AddPaused;
}
private bool ToBeQueuedFirst() private bool ToBeQueuedFirst()
{ {
if (Settings.Priority == (int)FreeboxDownloadPriority.First) if (Settings.Priority == (int)FreeboxDownloadPriority.First)
@ -128,9 +128,14 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload
return false; return false;
} }
private bool ToBePaused() private double? GetSeedRatio(TorrentInfo release)
{ {
return Settings.AddPaused; if (release.SeedConfiguration == null || release.SeedConfiguration.Ratio == null)
{
return null;
}
return release.SeedConfiguration.Ratio.Value * 100;
} }
} }
} }

Loading…
Cancel
Save