mirror of https://github.com/lidarr/Lidarr
Fixed: Handling of priority setting when queueing is disabled in qBittorrent
Sonarr f8b8fcfb8
This commit is contained in:
parent
d99fd151e3
commit
4c6313c9e2
|
@ -89,7 +89,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|||
});
|
||||
}
|
||||
|
||||
protected void GivenMaxRatio(float maxRatio, bool removeOnMaxRatio = true)
|
||||
protected void GivenHighPriority()
|
||||
{
|
||||
Subject.Definition.Settings.As<QBittorrentSettings>().OlderTvPriority = (int) QBittorrentPriority.First;
|
||||
Subject.Definition.Settings.As<QBittorrentSettings>().RecentTvPriority = (int) QBittorrentPriority.First;
|
||||
}
|
||||
|
||||
protected void GivenMaxRatio(float maxRatio, bool removeOnMaxRatio = true)
|
||||
{
|
||||
Mocker.GetMock<IQBittorrentProxy>()
|
||||
.Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>()))
|
||||
|
@ -266,6 +272,39 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_set_top_priority()
|
||||
{
|
||||
GivenHighPriority();
|
||||
GivenSuccessfulDownload();
|
||||
|
||||
var remoteAlbum = CreateRemoteAlbum();
|
||||
|
||||
var id = Subject.Download(remoteAlbum);
|
||||
|
||||
Mocker.GetMock<IQBittorrentProxy>()
|
||||
.Verify(v => v.MoveTorrentToTopInQueue(It.IsAny<string>(), It.IsAny<QBittorrentSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_not_fail_if_top_priority_not_available()
|
||||
{
|
||||
GivenHighPriority();
|
||||
GivenSuccessfulDownload();
|
||||
|
||||
Mocker.GetMock<IQBittorrentProxy>()
|
||||
.Setup(v => v.MoveTorrentToTopInQueue(It.IsAny<string>(), It.IsAny<QBittorrentSettings>()))
|
||||
.Throws(new HttpException(new HttpResponse(new HttpRequest("http://me.local/"), new HttpHeader(), new byte[0], System.Net.HttpStatusCode.Forbidden)));
|
||||
|
||||
var remoteAlbum = CreateRemoteAlbum();
|
||||
|
||||
var id = Subject.Download(remoteAlbum);
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_status_with_outputdirs()
|
||||
{
|
||||
var config = new QBittorrentPreferences
|
||||
|
|
|
@ -55,17 +55,31 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
|
|||
{
|
||||
_proxy.AddTorrentFromFile(filename, fileContent, Settings);
|
||||
|
||||
if (Settings.TvCategory.IsNotNullOrWhiteSpace())
|
||||
try
|
||||
{
|
||||
_proxy.SetTorrentLabel(hash.ToLower(), Settings.TvCategory, Settings);
|
||||
if (Settings.TvCategory.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
_proxy.SetTorrentLabel(hash.ToLower(), Settings.TvCategory, Settings);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Failed to set the torrent label for {0}.", filename);
|
||||
}
|
||||
|
||||
var isRecentEpisode = remoteAlbum.IsRecentAlbum();
|
||||
|
||||
if (isRecentEpisode && Settings.RecentTvPriority == (int)QBittorrentPriority.First ||
|
||||
!isRecentEpisode && Settings.OlderTvPriority == (int)QBittorrentPriority.First)
|
||||
try
|
||||
{
|
||||
_proxy.MoveTorrentToTopInQueue(hash.ToLower(), Settings);
|
||||
var isRecentAlbum = remoteAlbum.IsRecentAlbum();
|
||||
|
||||
if (isRecentAlbum && Settings.RecentTvPriority == (int)QBittorrentPriority.First ||
|
||||
!isRecentAlbum && Settings.OlderTvPriority == (int)QBittorrentPriority.First)
|
||||
{
|
||||
_proxy.MoveTorrentToTopInQueue(hash.ToLower(), Settings);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Failed to set the torrent priority for {0}.", filename);
|
||||
}
|
||||
|
||||
return hash;
|
||||
|
@ -177,6 +191,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
|
|||
{
|
||||
failures.AddIfNotNull(TestConnection());
|
||||
if (failures.Any()) return;
|
||||
failures.AddIfNotNull(TestPrioritySupport());
|
||||
failures.AddIfNotNull(TestGetTorrents());
|
||||
}
|
||||
|
||||
|
@ -253,6 +268,41 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
|
|||
return null;
|
||||
}
|
||||
|
||||
private ValidationFailure TestPrioritySupport()
|
||||
{
|
||||
var recentPriorityDefault = Settings.RecentTvPriority == (int)QBittorrentPriority.Last;
|
||||
var olderPriorityDefault = Settings.OlderTvPriority == (int)QBittorrentPriority.Last;
|
||||
|
||||
if (olderPriorityDefault && recentPriorityDefault)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var config = _proxy.GetConfig(Settings);
|
||||
|
||||
if (!config.QueueingEnabled)
|
||||
{
|
||||
if (!recentPriorityDefault)
|
||||
{
|
||||
return new NzbDroneValidationFailure(nameof(Settings.RecentTvPriority), "Queueing not enabled") { DetailedDescription = "Torrent Queueing is not enabled in your qBittorrent settings. Enable it in qBittorrent or select 'Last' as priority." };
|
||||
}
|
||||
else if (!olderPriorityDefault)
|
||||
{
|
||||
return new NzbDroneValidationFailure(nameof(Settings.OlderTvPriority), "Queueing not enabled") { DetailedDescription = "Torrent Queueing is not enabled in your qBittorrent settings. Enable it in qBittorrent or select 'Last' as priority." };
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex);
|
||||
return new NzbDroneValidationFailure(String.Empty, "Unknown exception: " + ex.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ValidationFailure TestGetTorrents()
|
||||
{
|
||||
try
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NzbDrone.Core.Download.Clients.QBittorrent
|
||||
{
|
||||
|
@ -16,5 +16,8 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
|
|||
|
||||
[JsonProperty(PropertyName = "max_ratio_act")]
|
||||
public bool RemoveOnMaxRatio { get; set; } // Action performed when a torrent reaches the maximum share ratio. [false = pause, true = remove]
|
||||
|
||||
[JsonProperty(PropertyName = "queueing_enabled")]
|
||||
public bool QueueingEnabled { get; set; } = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue