Fixed: (FreeboxDownload) Set seed limits in client

cardigann-contains
Bogdan 11 months ago
parent 7cb465787e
commit 8bd6a313b7

@ -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<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();
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);
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<FreeboxDownloadTask>(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;

@ -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()

@ -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<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)
{
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;
}
}
}

Loading…
Cancel
Save