1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-09-20 00:11:46 +02:00

uTorrent initial state feature (#2192)

* New: Initial state for torrents added to UTorrent

Closes #409

(cherry picked from commit 19a4d3536b)

* Change default port

* Rename TvCategory to MovieCategory
This commit is contained in:
James White 2017-10-23 01:51:07 +01:00 committed by Devin Buhl
parent 5337f79281
commit dffa50a82f
6 changed files with 43 additions and 15 deletions

View File

@ -30,7 +30,7 @@ public void Setup()
Port = 2222, Port = 2222,
Username = "admin", Username = "admin",
Password = "pass", Password = "pass",
TvCategory = "tv" MovieCategory = "movie"
}; };
_queued = new UTorrentTorrent _queued = new UTorrentTorrent
@ -41,7 +41,7 @@ public void Setup()
Size = 1000, Size = 1000,
Remaining = 1000, Remaining = 1000,
Progress = 0, Progress = 0,
Label = "tv", Label = "movie",
DownloadUrl = _downloadUrl, DownloadUrl = _downloadUrl,
RootDownloadPath = "somepath" RootDownloadPath = "somepath"
}; };
@ -54,7 +54,7 @@ public void Setup()
Size = 1000, Size = 1000,
Remaining = 100, Remaining = 100,
Progress = 0.9, Progress = 0.9,
Label = "tv", Label = "movie",
DownloadUrl = _downloadUrl, DownloadUrl = _downloadUrl,
RootDownloadPath = "somepath" RootDownloadPath = "somepath"
}; };
@ -67,7 +67,7 @@ public void Setup()
Size = 1000, Size = 1000,
Remaining = 100, Remaining = 100,
Progress = 0.9, Progress = 0.9,
Label = "tv", Label = "movie",
DownloadUrl = _downloadUrl, DownloadUrl = _downloadUrl,
RootDownloadPath = "somepath" RootDownloadPath = "somepath"
}; };
@ -80,7 +80,7 @@ public void Setup()
Size = 1000, Size = 1000,
Remaining = 0, Remaining = 0,
Progress = 1.0, Progress = 1.0,
Label = "tv", Label = "movie",
DownloadUrl = _downloadUrl, DownloadUrl = _downloadUrl,
RootDownloadPath = "somepath" RootDownloadPath = "somepath"
}; };

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -49,7 +49,7 @@ protected override string AddFromTorrentFile(RemoteEpisode remoteEpisode, string
protected override string AddFromMagnetLink(RemoteMovie remoteMovie, string hash, string magnetLink) protected override string AddFromMagnetLink(RemoteMovie remoteMovie, string hash, string magnetLink)
{ {
_proxy.AddTorrentFromUrl(magnetLink, Settings); _proxy.AddTorrentFromUrl(magnetLink, Settings);
_proxy.SetTorrentLabel(hash, Settings.TvCategory, Settings); _proxy.SetTorrentLabel(hash, Settings.MovieCategory, Settings);
/*var isRecentEpisode = remoteEpisode.IsRecentEpisode(); /*var isRecentEpisode = remoteEpisode.IsRecentEpisode();
@ -59,13 +59,15 @@ protected override string AddFromMagnetLink(RemoteMovie remoteMovie, string hash
_proxy.MoveTorrentToTopInQueue(hash, Settings); _proxy.MoveTorrentToTopInQueue(hash, Settings);
}*/ }*/
_proxy.SetState(hash, (UTorrentState)Settings.IntialState, Settings);
return hash; return hash;
} }
protected override string AddFromTorrentFile(RemoteMovie remoteMovie, string hash, string filename, byte[] fileContent) protected override string AddFromTorrentFile(RemoteMovie remoteMovie, string hash, string filename, byte[] fileContent)
{ {
_proxy.AddTorrentFromFile(filename, fileContent, Settings); _proxy.AddTorrentFromFile(filename, fileContent, Settings);
_proxy.SetTorrentLabel(hash, Settings.TvCategory, Settings); _proxy.SetTorrentLabel(hash, Settings.MovieCategory, Settings);
/*var isRecentEpisode = remoteEpisode.IsRecentEpisode(); /*var isRecentEpisode = remoteEpisode.IsRecentEpisode();
@ -75,6 +77,8 @@ protected override string AddFromTorrentFile(RemoteMovie remoteMovie, string has
_proxy.MoveTorrentToTopInQueue(hash, Settings); _proxy.MoveTorrentToTopInQueue(hash, Settings);
}*/ }*/
_proxy.SetState(hash, (UTorrentState)Settings.IntialState, Settings);
return hash; return hash;
} }
@ -86,7 +90,7 @@ public override IEnumerable<DownloadClientItem> GetItems()
try 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 cache = _torrentCache.Find(cacheKey);
var response = _proxy.GetTorrents(cache == null ? null : cache.CacheID, Settings); var response = _proxy.GetTorrents(cache == null ? null : cache.CacheID, Settings);
@ -123,7 +127,7 @@ public override IEnumerable<DownloadClientItem> GetItems()
foreach (var torrent in torrents) foreach (var torrent in torrents)
{ {
if (torrent.Label != Settings.TvCategory) if (torrent.Label != Settings.MovieCategory)
{ {
continue; continue;
} }
@ -205,7 +209,7 @@ public override DownloadClientStatus GetStatus()
if (config.GetValueOrDefault("dir_add_label") == "true") if (config.GetValueOrDefault("dir_add_label") == "true")
{ {
destDir = destDir + Settings.TvCategory; destDir = destDir + Settings.MovieCategory;
} }
} }

View File

@ -22,6 +22,7 @@ public interface IUTorrentProxy
void RemoveTorrent(string hash, bool removeData, UTorrentSettings settings); void RemoveTorrent(string hash, bool removeData, UTorrentSettings settings);
void SetTorrentLabel(string hash, string label, UTorrentSettings settings); void SetTorrentLabel(string hash, string label, UTorrentSettings settings);
void MoveTorrentToTopInQueue(string hash, UTorrentSettings settings); void MoveTorrentToTopInQueue(string hash, UTorrentSettings settings);
void SetState(string hash, UTorrentState state, UTorrentSettings settings);
} }
public class UTorrentProxy : IUTorrentProxy public class UTorrentProxy : IUTorrentProxy
@ -157,6 +158,15 @@ public void MoveTorrentToTopInQueue(string hash, UTorrentSettings settings)
ProcessRequest(requestBuilder, settings); 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) private HttpRequestBuilder BuildRequest(UTorrentSettings settings)
{ {
var requestBuilder = new HttpRequestBuilder(false, settings.Host, settings.Port) var requestBuilder = new HttpRequestBuilder(false, settings.Host, settings.Port)

View File

@ -11,7 +11,7 @@ public UTorrentSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).InclusiveBetween(1, 65535); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.TvCategory).NotEmpty(); RuleFor(c => c.MovieCategory).NotEmpty();
} }
} }
@ -22,8 +22,8 @@ public class UTorrentSettings : IProviderConfig
public UTorrentSettings() public UTorrentSettings()
{ {
Host = "localhost"; Host = "localhost";
Port = 9091; Port = 8080;
TvCategory = "radarr"; MovieCategory = "radarr";
} }
[FieldDefinition(0, Label = "Host", Type = FieldType.Textbox)] [FieldDefinition(0, Label = "Host", Type = FieldType.Textbox)]
@ -39,7 +39,7 @@ public UTorrentSettings()
public string Password { get; set; } 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")] [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")] [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; } public int RecentTvPriority { get; set; }
@ -47,6 +47,9 @@ public UTorrentSettings()
[FieldDefinition(6, Label = "Older Priority", Type = FieldType.Select, SelectOptions = typeof(UTorrentPriority), HelpText = "Priority to use when grabbing releases that aired over 14 days ago")] [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; } 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() public NzbDroneValidationResult Validate()
{ {
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));

View File

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

View File

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