New: Remove completed torrents from qBittorrent

Fixes #1316
This commit is contained in:
Casey Bodley 2016-10-27 23:07:42 -04:00 committed by Mark McDowall
parent cdce65a922
commit 25a3f83ebc
6 changed files with 48 additions and 21 deletions

View File

@ -253,13 +253,14 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
[Test]
public void should_return_status_with_outputdirs()
{
var configItems = new Dictionary<string, Object>();
configItems.Add("save_path", @"C:\Downloads\Finished\QBittorrent".AsOsAgnostic());
var config = new QBittorrentPreferences
{
SavePath = @"C:\Downloads\Finished\QBittorrent".AsOsAgnostic()
};
Mocker.GetMock<IQBittorrentProxy>()
.Setup(v => v.GetConfig(It.IsAny<QBittorrentSettings>()))
.Returns(configItems);
.Returns(config);
var result = Subject.GetStatus();

View File

@ -80,20 +80,14 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
}
}
public override ProviderMessage Message
{
get
{
return new ProviderMessage("Sonarr is unable to remove torrents that have finished seeding when using qBittorrent", ProviderMessageType.Warning);
}
}
public override IEnumerable<DownloadClientItem> GetItems()
{
QBittorrentPreferences config;
List<QBittorrentTorrent> torrents;
try
{
config = _proxy.GetConfig(Settings);
torrents = _proxy.GetTorrents(Settings);
}
catch (DownloadClientException ex)
@ -116,11 +110,10 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
item.RemainingTime = TimeSpan.FromSeconds(torrent.Eta);
item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.SavePath));
// At the moment there isn't an easy way to detect if the torrent has
// reached the seeding limit, We would need to check the preferences
// and still not be completely sure if that torrent has a limit set for it
item.IsReadOnly = true;
// Avoid removing torrents that haven't reached the global max ratio.
// Removal also requires the torrent to be paused, in case a higher max ratio was set on the torrent itself (which is not exposed by the api).
item.IsReadOnly = (config.MaxRatioEnabled && config.MaxRatio > torrent.Ratio) || torrent.State != "pausedUP";
if (!item.OutputPath.IsEmpty && item.OutputPath.FileName != torrent.Name)
{
@ -178,7 +171,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
{
var config = _proxy.GetConfig(Settings);
var destDir = new OsPath((string)config.GetValueOrDefault("save_path"));
var destDir = new OsPath(config.SavePath);
return new DownloadClientStatus
{
@ -227,6 +220,16 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
DetailedDescription = "Sonarr will not attempt to import completed downloads without a category."
};
}
// Complain if qBittorrent is configured to remove torrents on max ratio
var config = _proxy.GetConfig(Settings);
if (config.MaxRatioEnabled && config.RemoveOnMaxRatio)
{
return new NzbDroneValidationFailure(String.Empty, "QBittorrent is configured to remove torrents when they reach their Share Ratio Limit")
{
DetailedDescription = "Sonarr will be unable to perform Completed Download Handling as configured. You can fix this in qBittorrent ('Tools -> Options...' in the menu) by changing 'Options -> BitTorrent -> Share Ratio Limiting' from 'Remove them' to 'Pause them'."
};
}
}
catch (DownloadClientAuthenticationException ex)
{

View File

@ -0,0 +1,20 @@
using Newtonsoft.Json;
namespace NzbDrone.Core.Download.Clients.QBittorrent
{
// qbittorrent settings from the list returned by /query/preferences
public class QBittorrentPreferences
{
[JsonProperty(PropertyName = "save_path")]
public string SavePath { get; set; } // Default save path for torrents, separated by slashes
[JsonProperty(PropertyName = "max_ratio_enabled")]
public bool MaxRatioEnabled { get; set; } // True if share ratio limit is enabled
[JsonProperty(PropertyName = "max_ratio")]
public float MaxRatio { get; set; } // Get the global share ratio limit
[JsonProperty(PropertyName = "max_ratio_act")]
public bool RemoveOnMaxRatio { get; set; } // Action performed when a torrent reaches the maximum share ratio. [false = pause, true = remove]
}
}

View File

@ -14,7 +14,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
public interface IQBittorrentProxy
{
int GetVersion(QBittorrentSettings settings);
Dictionary<string, Object> GetConfig(QBittorrentSettings settings);
QBittorrentPreferences GetConfig(QBittorrentSettings settings);
List<QBittorrentTorrent> GetTorrents(QBittorrentSettings settings);
void AddTorrentFromUrl(string torrentUrl, QBittorrentSettings settings);
@ -47,10 +47,10 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
return response;
}
public Dictionary<string, object> GetConfig(QBittorrentSettings settings)
public QBittorrentPreferences GetConfig(QBittorrentSettings settings)
{
var request = BuildRequest(settings).Resource("/query/preferences");
var response = ProcessRequest<Dictionary<string, object>>(request, settings);
var response = ProcessRequest<QBittorrentPreferences>(request, settings);
return response;
}

View File

@ -21,5 +21,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
[JsonProperty(PropertyName = "save_path")]
public string SavePath { get; set; } // Torrent save path
public float Ratio { get; set; } // Torrent share ratio
}
}

View File

@ -401,6 +401,7 @@
<Compile Include="Download\Clients\NzbVortex\Responses\NzbVortexVersionResponse.cs" />
<Compile Include="Download\Clients\Pneumatic\Pneumatic.cs" />
<Compile Include="Download\Clients\Pneumatic\PneumaticSettings.cs" />
<Compile Include="Download\Clients\QBittorrent\QBittorrentPreferences.cs" />
<Compile Include="Download\Clients\rTorrent\RTorrentDirectoryValidator.cs" />
<Compile Include="Download\Clients\QBittorrent\QBittorrent.cs" />
<Compile Include="Download\Clients\QBittorrent\QBittorrentPriority.cs" />