From 8bd6a313b768639e3abd73b007e2c4dc5dff0c59 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 10 Jun 2023 23:32:06 +0300 Subject: [PATCH] Fixed: (FreeboxDownload) Set seed limits in client --- .../FreeboxDownload/FreeboxDownloadProxy.cs | 20 +++++++---- .../FreeboxDownloadSettings.cs | 4 +-- .../FreeboxDownload/TorrentFreeboxDownload.cs | 33 +++++++++++-------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/FreeboxDownload/FreeboxDownloadProxy.cs b/src/NzbDrone.Core/Download/Clients/FreeboxDownload/FreeboxDownloadProxy.cs index 1c40a3832..ae952e2b9 100644 --- a/src/NzbDrone.Core/Download/Clients/FreeboxDownload/FreeboxDownloadProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/FreeboxDownload/FreeboxDownloadProxy.cs @@ -14,8 +14,8 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload public interface IFreeboxDownloadProxy { void Authenticate(FreeboxDownloadSettings settings); - string AddTaskFromUrl(string url, string directory, bool addPaused, bool addFirst, FreeboxDownloadSettings settings); - string AddTaskFromFile(string fileName, byte[] fileContent, 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, double? seedRatio, FreeboxDownloadSettings settings); void DeleteTask(string id, bool deleteData, FreeboxDownloadSettings settings); FreeboxDownloadConfiguration GetDownloadConfiguration(FreeboxDownloadSettings settings); List 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(); request.Headers.ContentType = "application/x-www-form-urlencoded"; @@ -60,12 +60,12 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload var response = ProcessRequest(request.Build(), settings); - SetTorrentSettings(response.Result.Id, addPaused, addFirst, settings); + SetTorrentSettings(response.Result.Id, addPaused, addFirst, seedRatio, settings); 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(); @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload var response = ProcessRequest(request.Build(), settings); - SetTorrentSettings(response.Result.Id, addPaused, addFirst, settings); + SetTorrentSettings(response.Result.Id, addPaused, addFirst, seedRatio, settings); return response.Result.Id; } @@ -118,7 +118,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload 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(); @@ -136,6 +136,12 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload body.Add("queue_pos", "1"); } + if (seedRatio != null) + { + // 0 means unlimited seeding + body.Add("stop_ratio", seedRatio); + } + if (body.Count == 0) { return; diff --git a/src/NzbDrone.Core/Download/Clients/FreeboxDownload/FreeboxDownloadSettings.cs b/src/NzbDrone.Core/Download/Clients/FreeboxDownload/FreeboxDownloadSettings.cs index 3810f8e7e..ee0fff8e1 100644 --- a/src/NzbDrone.Core/Download/Clients/FreeboxDownload/FreeboxDownloadSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/FreeboxDownload/FreeboxDownloadSettings.cs @@ -36,7 +36,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload public class FreeboxDownloadSettings : IProviderConfig { - private static readonly FreeboxDownloadSettingsValidator Validator = new FreeboxDownloadSettingsValidator(); + private static readonly FreeboxDownloadSettingsValidator Validator = new (); 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")] 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 NzbDroneValidationResult Validate() diff --git a/src/NzbDrone.Core/Download/Clients/FreeboxDownload/TorrentFreeboxDownload.cs b/src/NzbDrone.Core/Download/Clients/FreeboxDownload/TorrentFreeboxDownload.cs index 8f23e93b6..cec808592 100644 --- a/src/NzbDrone.Core/Download/Clients/FreeboxDownload/TorrentFreeboxDownload.cs +++ b/src/NzbDrone.Core/Download/Clients/FreeboxDownload/TorrentFreeboxDownload.cs @@ -1,12 +1,10 @@ -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using System.Text.RegularExpressions; using FluentValidation.Results; using NLog; using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; -using NzbDrone.Core.Download.Clients.FreeboxDownload.Responses; using NzbDrone.Core.Indexers; using NzbDrone.Core.Parser.Model; @@ -28,20 +26,15 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload } public override string Name => "Freebox Download"; - public override bool SupportsCategories => true; - protected IEnumerable GetTorrents() - { - return _proxy.GetTasks(Settings).Where(v => v.Type.ToLower() == FreeboxDownloadTaskType.Bt.ToString().ToLower()); - } - protected override string AddFromMagnetLink(TorrentInfo release, string hash, string magnetLink) { return _proxy.AddTaskFromUrl(magnetLink, GetDownloadDirectory(release).EncodeBase64(), ToBePaused(), ToBeQueuedFirst(), + GetSeedRatio(release), Settings); } @@ -52,6 +45,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload GetDownloadDirectory(release).EncodeBase64(), ToBePaused(), ToBeQueuedFirst(), + GetSeedRatio(release), Settings); } @@ -61,6 +55,7 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload GetDownloadDirectory(release).EncodeBase64(), ToBePaused(), ToBeQueuedFirst(), + GetSeedRatio(release), Settings); } @@ -108,16 +103,21 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload 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}"; } return destDir; } + private bool ToBePaused() + { + return Settings.AddPaused; + } + private bool ToBeQueuedFirst() { if (Settings.Priority == (int)FreeboxDownloadPriority.First) @@ -128,9 +128,14 @@ namespace NzbDrone.Core.Download.Clients.FreeboxDownload 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; } } }