New: Remove completed torrents from qBittorrent

Fixes #1316
pull/6/head
Casey Bodley 8 years ago committed by Mark McDowall
parent cdce65a922
commit 25a3f83ebc

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

@ -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() public override IEnumerable<DownloadClientItem> GetItems()
{ {
QBittorrentPreferences config;
List<QBittorrentTorrent> torrents; List<QBittorrentTorrent> torrents;
try try
{ {
config = _proxy.GetConfig(Settings);
torrents = _proxy.GetTorrents(Settings); torrents = _proxy.GetTorrents(Settings);
} }
catch (DownloadClientException ex) catch (DownloadClientException ex)
@ -116,11 +110,10 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
item.RemainingTime = TimeSpan.FromSeconds(torrent.Eta); item.RemainingTime = TimeSpan.FromSeconds(torrent.Eta);
item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.SavePath)); 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 // Avoid removing torrents that haven't reached the global max ratio.
// reached the seeding limit, We would need to check the preferences // 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).
// and still not be completely sure if that torrent has a limit set for it item.IsReadOnly = (config.MaxRatioEnabled && config.MaxRatio > torrent.Ratio) || torrent.State != "pausedUP";
item.IsReadOnly = true;
if (!item.OutputPath.IsEmpty && item.OutputPath.FileName != torrent.Name) 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 config = _proxy.GetConfig(Settings);
var destDir = new OsPath((string)config.GetValueOrDefault("save_path")); var destDir = new OsPath(config.SavePath);
return new DownloadClientStatus 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." 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) catch (DownloadClientAuthenticationException ex)
{ {

@ -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]
}
}

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

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

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

Loading…
Cancel
Save