uTorrent initial state feature (#2192)

* New: Initial state for torrents added to UTorrent

Closes #409

(cherry picked from commit 19a4d3536bde8103c4e0f7414cc1819b2083ffb2)

* Change default port

* Rename TvCategory to MovieCategory
pull/2/head
James White 7 years ago committed by Devin Buhl
parent 5337f79281
commit dffa50a82f

@ -30,7 +30,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Port = 2222,
Username = "admin",
Password = "pass",
TvCategory = "tv"
MovieCategory = "movie"
};
_queued = new UTorrentTorrent
@ -41,7 +41,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Size = 1000,
Remaining = 1000,
Progress = 0,
Label = "tv",
Label = "movie",
DownloadUrl = _downloadUrl,
RootDownloadPath = "somepath"
};
@ -54,7 +54,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Size = 1000,
Remaining = 100,
Progress = 0.9,
Label = "tv",
Label = "movie",
DownloadUrl = _downloadUrl,
RootDownloadPath = "somepath"
};
@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Size = 1000,
Remaining = 100,
Progress = 0.9,
Label = "tv",
Label = "movie",
DownloadUrl = _downloadUrl,
RootDownloadPath = "somepath"
};
@ -80,7 +80,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Size = 1000,
Remaining = 0,
Progress = 1.0,
Label = "tv",
Label = "movie",
DownloadUrl = _downloadUrl,
RootDownloadPath = "somepath"
};

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using NzbDrone.Common.Disk;
@ -49,7 +49,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
protected override string AddFromMagnetLink(RemoteMovie remoteMovie, string hash, string magnetLink)
{
_proxy.AddTorrentFromUrl(magnetLink, Settings);
_proxy.SetTorrentLabel(hash, Settings.TvCategory, Settings);
_proxy.SetTorrentLabel(hash, Settings.MovieCategory, Settings);
/*var isRecentEpisode = remoteEpisode.IsRecentEpisode();
@ -59,13 +59,15 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
_proxy.MoveTorrentToTopInQueue(hash, Settings);
}*/
_proxy.SetState(hash, (UTorrentState)Settings.IntialState, Settings);
return hash;
}
protected override string AddFromTorrentFile(RemoteMovie remoteMovie, string hash, string filename, byte[] fileContent)
{
_proxy.AddTorrentFromFile(filename, fileContent, Settings);
_proxy.SetTorrentLabel(hash, Settings.TvCategory, Settings);
_proxy.SetTorrentLabel(hash, Settings.MovieCategory, Settings);
/*var isRecentEpisode = remoteEpisode.IsRecentEpisode();
@ -75,6 +77,8 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
_proxy.MoveTorrentToTopInQueue(hash, Settings);
}*/
_proxy.SetState(hash, (UTorrentState)Settings.IntialState, Settings);
return hash;
}
@ -86,7 +90,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
try
{
var cacheKey = string.Format("{0}:{1}:{2}", Settings.Host, Settings.Port, Settings.TvCategory);
var cacheKey = string.Format("{0}:{1}:{2}", Settings.Host, Settings.Port, Settings.MovieCategory);
var cache = _torrentCache.Find(cacheKey);
var response = _proxy.GetTorrents(cache == null ? null : cache.CacheID, Settings);
@ -123,7 +127,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
foreach (var torrent in torrents)
{
if (torrent.Label != Settings.TvCategory)
if (torrent.Label != Settings.MovieCategory)
{
continue;
}
@ -205,7 +209,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
if (config.GetValueOrDefault("dir_add_label") == "true")
{
destDir = destDir + Settings.TvCategory;
destDir = destDir + Settings.MovieCategory;
}
}

@ -22,6 +22,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
void RemoveTorrent(string hash, bool removeData, UTorrentSettings settings);
void SetTorrentLabel(string hash, string label, UTorrentSettings settings);
void MoveTorrentToTopInQueue(string hash, UTorrentSettings settings);
void SetState(string hash, UTorrentState state, UTorrentSettings settings);
}
public class UTorrentProxy : IUTorrentProxy
@ -157,6 +158,15 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
ProcessRequest(requestBuilder, settings);
}
public void SetState(string hash, UTorrentState state, UTorrentSettings settings)
{
var requestBuilder = BuildRequest(settings)
.AddQueryParam("action", state.ToString().ToLowerInvariant())
.AddQueryParam("hash", hash);
ProcessRequest(requestBuilder, settings);
}
private HttpRequestBuilder BuildRequest(UTorrentSettings settings)
{
var requestBuilder = new HttpRequestBuilder(false, settings.Host, settings.Port)

@ -11,7 +11,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
{
RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.TvCategory).NotEmpty();
RuleFor(c => c.MovieCategory).NotEmpty();
}
}
@ -22,8 +22,8 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
public UTorrentSettings()
{
Host = "localhost";
Port = 9091;
TvCategory = "radarr";
Port = 8080;
MovieCategory = "radarr";
}
[FieldDefinition(0, Label = "Host", Type = FieldType.Textbox)]
@ -39,7 +39,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
public string Password { get; set; }
[FieldDefinition(4, Label = "Category", Type = FieldType.Textbox, HelpText = "Adding a category specific to Radarr avoids conflicts with unrelated downloads, but it's optional")]
public string TvCategory { get; set; }
public string MovieCategory { get; set; }
[FieldDefinition(5, Label = "Recent Priority", Type = FieldType.Select, SelectOptions = typeof(UTorrentPriority), HelpText = "Priority to use when grabbing releases that aired within the last 14 days")]
public int RecentTvPriority { get; set; }
@ -47,6 +47,9 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
[FieldDefinition(6, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(UTorrentPriority), HelpText = "Priority to use when grabbing releases that aired over 14 days ago")]
public int OlderTvPriority { get; set; }
[FieldDefinition(7, Label = "Initial State", Type = FieldType.Select, SelectOptions = typeof(UTorrentState), HelpText = "Initial state for torrents added to uTorrent")]
public int IntialState { get; set; }
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));

@ -0,0 +1,10 @@
namespace NzbDrone.Core.Download.Clients.UTorrent
{
public enum UTorrentState
{
Start = 0,
ForceStart = 1,
Pause = 2,
Stop = 3
}
}

@ -556,6 +556,7 @@
<Compile Include="Download\Clients\uTorrent\UTorrentProxy.cs" />
<Compile Include="Download\Clients\uTorrent\UTorrentResponse.cs" />
<Compile Include="Download\Clients\uTorrent\UTorrentSettings.cs" />
<Compile Include="Download\Clients\uTorrent\UtorrentState.cs" />
<Compile Include="Download\Clients\uTorrent\UTorrentTorrent.cs" />
<Compile Include="Download\Clients\uTorrent\UTorrentTorrentCache.cs" />
<Compile Include="Download\Clients\uTorrent\UTorrentTorrentStatus.cs" />

Loading…
Cancel
Save