Small refactorings
This commit is contained in:
parent
2e70764dd9
commit
b68a9912f8
|
@ -32,6 +32,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
||||||
_queued = new PutioTorrent
|
_queued = new PutioTorrent
|
||||||
{
|
{
|
||||||
Hash = "HASH",
|
Hash = "HASH",
|
||||||
|
Id = 1,
|
||||||
Status = PutioTorrentStatus.InQueue,
|
Status = PutioTorrentStatus.InQueue,
|
||||||
Name = _title,
|
Name = _title,
|
||||||
Size = 1000,
|
Size = 1000,
|
||||||
|
@ -42,6 +43,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
||||||
_downloading = new PutioTorrent
|
_downloading = new PutioTorrent
|
||||||
{
|
{
|
||||||
Hash = "HASH",
|
Hash = "HASH",
|
||||||
|
Id = 2,
|
||||||
Status = PutioTorrentStatus.Downloading,
|
Status = PutioTorrentStatus.Downloading,
|
||||||
Name = _title,
|
Name = _title,
|
||||||
Size = 1000,
|
Size = 1000,
|
||||||
|
@ -52,6 +54,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
||||||
_failed = new PutioTorrent
|
_failed = new PutioTorrent
|
||||||
{
|
{
|
||||||
Hash = "HASH",
|
Hash = "HASH",
|
||||||
|
Id = 3,
|
||||||
Status = PutioTorrentStatus.Error,
|
Status = PutioTorrentStatus.Error,
|
||||||
ErrorMessage = "Torrent has reached the maximum number of inactive days.",
|
ErrorMessage = "Torrent has reached the maximum number of inactive days.",
|
||||||
Name = _title,
|
Name = _title,
|
||||||
|
@ -64,6 +67,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
||||||
{
|
{
|
||||||
Hash = "HASH",
|
Hash = "HASH",
|
||||||
Status = PutioTorrentStatus.Completed,
|
Status = PutioTorrentStatus.Completed,
|
||||||
|
Id = 4,
|
||||||
Name = _title,
|
Name = _title,
|
||||||
Size = 1000,
|
Size = 1000,
|
||||||
Downloaded = 1000,
|
Downloaded = 1000,
|
||||||
|
@ -74,6 +78,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
||||||
_completed_different_parent = new PutioTorrent
|
_completed_different_parent = new PutioTorrent
|
||||||
{
|
{
|
||||||
Hash = "HASH",
|
Hash = "HASH",
|
||||||
|
Id = 5,
|
||||||
Status = PutioTorrentStatus.Completed,
|
Status = PutioTorrentStatus.Completed,
|
||||||
Name = _title,
|
Name = _title,
|
||||||
Size = 1000,
|
Size = 1000,
|
||||||
|
@ -85,10 +90,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
||||||
_seeding = new PutioTorrent
|
_seeding = new PutioTorrent
|
||||||
{
|
{
|
||||||
Hash = "HASH",
|
Hash = "HASH",
|
||||||
|
Id = 6,
|
||||||
Status = PutioTorrentStatus.Seeding,
|
Status = PutioTorrentStatus.Seeding,
|
||||||
Name = _title,
|
Name = _title,
|
||||||
Size = 1000,
|
Size = 1000,
|
||||||
Downloaded = 1000,
|
Downloaded = 1000,
|
||||||
|
Uploaded = 1300,
|
||||||
SaveParentId = 1,
|
SaveParentId = 1,
|
||||||
FileId = 2
|
FileId = 2
|
||||||
};
|
};
|
||||||
|
@ -137,17 +144,37 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
||||||
.Returns(torrents);
|
.Returns(torrents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void GivenMetadata(List<PutioTorrentMetadata> metadata)
|
||||||
|
{
|
||||||
|
metadata ??= new List<PutioTorrentMetadata>();
|
||||||
|
var result = new Dictionary<string, PutioTorrentMetadata>();
|
||||||
|
foreach (var item in metadata)
|
||||||
|
{
|
||||||
|
result.Add(item.Id.ToString(), item);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mocker.GetMock<IPutioProxy>()
|
||||||
|
.Setup(s => s.GetAllTorrentMetadata(It.IsAny<PutioSettings>()))
|
||||||
|
.Returns(result);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void getItems_contains_all_items()
|
public void getItems_contains_all_items()
|
||||||
{
|
{
|
||||||
GivenTorrents(new List<PutioTorrent>
|
GivenTorrents(new List<PutioTorrent>
|
||||||
{
|
{
|
||||||
_queued,
|
_queued,
|
||||||
_downloading,
|
_downloading,
|
||||||
_failed,
|
_failed,
|
||||||
_completed,
|
_completed,
|
||||||
_seeding,
|
_seeding,
|
||||||
_completed_different_parent
|
_completed_different_parent
|
||||||
|
});
|
||||||
|
GivenMetadata(new List<PutioTorrentMetadata>
|
||||||
|
{
|
||||||
|
PutioTorrentMetadata.fromTorrent(_completed, true),
|
||||||
|
PutioTorrentMetadata.fromTorrent(_seeding, true),
|
||||||
|
PutioTorrentMetadata.fromTorrent(_completed_different_parent, true),
|
||||||
});
|
});
|
||||||
|
|
||||||
var items = Subject.GetItems();
|
var items = Subject.GetItems();
|
||||||
|
@ -198,10 +225,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
||||||
{
|
{
|
||||||
_queued
|
_queued
|
||||||
});
|
});
|
||||||
|
GivenMetadata(new List<PutioTorrentMetadata> { PutioTorrentMetadata.fromTorrent(_queued, true) });
|
||||||
|
|
||||||
var item = Subject.GetItems().Single();
|
var item = Subject.GetItems().Single();
|
||||||
|
|
||||||
item.Status.Should().Be(expectedItemStatus);
|
item.Status.Should().Be(expectedItemStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void test_getItems_marks_non_existing_local_download_as_downloading()
|
||||||
|
{
|
||||||
|
GivenTorrents(new List<PutioTorrent> { _completed });
|
||||||
|
GivenMetadata(new List<PutioTorrentMetadata> { PutioTorrentMetadata.fromTorrent(_completed, false) });
|
||||||
|
|
||||||
|
var item = Subject.GetItems().Single();
|
||||||
|
VerifyDownloading(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
||||||
|
using NzbDrone.Core.Organizer;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
using NzbDrone.Core.RemotePathMappings;
|
using NzbDrone.Core.RemotePathMappings;
|
||||||
using NzbDrone.Core.Validation;
|
using NzbDrone.Core.Validation;
|
||||||
|
@ -54,24 +55,24 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
public override IEnumerable<DownloadClientItem> GetItems()
|
public override IEnumerable<DownloadClientItem> GetItems()
|
||||||
{
|
{
|
||||||
List<PutioTorrent> torrents;
|
List<PutioTorrent> torrents;
|
||||||
|
Dictionary<string, PutioTorrentMetadata> metadata;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
torrents = _proxy.GetTorrents(Settings);
|
torrents = _proxy.GetTorrents(Settings);
|
||||||
|
metadata = _proxy.GetAllTorrentMetadata(Settings);
|
||||||
}
|
}
|
||||||
catch (DownloadClientException ex)
|
catch (DownloadClientException ex)
|
||||||
{
|
{
|
||||||
_logger.Error(ex, ex.Message);
|
_logger.Error(ex, ex.Message);
|
||||||
return Enumerable.Empty<DownloadClientItem>();
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var items = new List<DownloadClientItem>();
|
|
||||||
|
|
||||||
foreach (var torrent in torrents)
|
foreach (var torrent in torrents)
|
||||||
{
|
{
|
||||||
// If totalsize == 0 the torrent is a magnet downloading metadata
|
|
||||||
if (torrent.Size == 0)
|
if (torrent.Size == 0)
|
||||||
{
|
{
|
||||||
|
// If totalsize == 0 the torrent is a magnet downloading metadata
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +89,11 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
Title = torrent.Name,
|
Title = torrent.Name,
|
||||||
TotalSize = torrent.Size,
|
TotalSize = torrent.Size,
|
||||||
RemainingSize = torrent.Size - torrent.Downloaded,
|
RemainingSize = torrent.Size - torrent.Downloaded,
|
||||||
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this)
|
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
|
||||||
|
SeedRatio = torrent.Ratio,
|
||||||
|
|
||||||
|
// Initial status, might change later
|
||||||
|
Status = GetDownloadItemStatus(torrent)
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -97,6 +102,10 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
{
|
{
|
||||||
// How needs the output path need to look if we have remote files?
|
// How needs the output path need to look if we have remote files?
|
||||||
|
|
||||||
|
// check if we need to download the torrent from the remote
|
||||||
|
var title = FileNameBuilder.CleanFileName(torrent.Name);
|
||||||
|
|
||||||
|
// _diskProvider.FileExists(new OsPath())
|
||||||
/*
|
/*
|
||||||
var file = _proxy.GetFile(torrent.FileId, Settings);
|
var file = _proxy.GetFile(torrent.FileId, Settings);
|
||||||
var torrentPath = "/completed/" + file.Name;
|
var torrentPath = "/completed/" + file.Name;
|
||||||
|
@ -126,21 +135,17 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
item.RemainingTime = TimeSpan.FromSeconds(torrent.EstimatedTime);
|
item.RemainingTime = TimeSpan.FromSeconds(torrent.EstimatedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
item.Status = GetStatus(torrent);
|
|
||||||
|
|
||||||
if (!torrent.ErrorMessage.IsNullOrWhiteSpace())
|
if (!torrent.ErrorMessage.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
item.Status = DownloadItemStatus.Warning;
|
item.Status = DownloadItemStatus.Warning;
|
||||||
item.Message = torrent.ErrorMessage;
|
item.Message = torrent.ErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
items.Add(item);
|
yield return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DownloadItemStatus GetStatus(PutioTorrent torrent)
|
private DownloadItemStatus GetDownloadItemStatus(PutioTorrent torrent)
|
||||||
{
|
{
|
||||||
if (torrent.Status == PutioTorrentStatus.Completed ||
|
if (torrent.Status == PutioTorrentStatus.Completed ||
|
||||||
torrent.Status == PutioTorrentStatus.Seeding)
|
torrent.Status == PutioTorrentStatus.Seeding)
|
||||||
|
@ -176,6 +181,7 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
|
|
||||||
protected override void Test(List<ValidationFailure> failures)
|
protected override void Test(List<ValidationFailure> failures)
|
||||||
{
|
{
|
||||||
|
failures.AddIfNotNull(TestFolder(Settings.DownloadPath, "DownloadPath"));
|
||||||
failures.AddIfNotNull(TestConnection());
|
failures.AddIfNotNull(TestConnection());
|
||||||
if (failures.Any())
|
if (failures.Any())
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,6 +15,8 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
void AddTorrentFromData(byte[] torrentData, PutioSettings settings);
|
void AddTorrentFromData(byte[] torrentData, PutioSettings settings);
|
||||||
void RemoveTorrent(string hash, PutioSettings settings);
|
void RemoveTorrent(string hash, PutioSettings settings);
|
||||||
void GetAccountSettings(PutioSettings settings);
|
void GetAccountSettings(PutioSettings settings);
|
||||||
|
public PutioTorrentMetadata GetTorrentMetadata(PutioTorrent torrent, PutioSettings settings);
|
||||||
|
public Dictionary<string, PutioTorrentMetadata> GetAllTorrentMetadata(PutioSettings settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PutioProxy : IPutioProxy
|
public class PutioProxy : IPutioProxy
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
public PutioSettings()
|
public PutioSettings()
|
||||||
{
|
{
|
||||||
Url = "https://api.put.io/v2";
|
Url = "https://api.put.io/v2";
|
||||||
|
DeleteImported = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Url { get; }
|
public string Url { get; }
|
||||||
|
@ -34,12 +35,12 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
[FieldDefinition(1, Label = "Save Parent Folder ID", Type = FieldType.Textbox, HelpText = "Adding a parent folder ID specific to Sonarr avoids conflicts with unrelated non-Sonarr downloads. Using a parent folder is optional, but strongly recommended.")]
|
[FieldDefinition(1, Label = "Save Parent Folder ID", Type = FieldType.Textbox, HelpText = "Adding a parent folder ID specific to Sonarr avoids conflicts with unrelated non-Sonarr downloads. Using a parent folder is optional, but strongly recommended.")]
|
||||||
public string SaveParentId { get; set; }
|
public string SaveParentId { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(2, Label = "Download completed transfers", Type = FieldType.Checkbox, HelpText = "If enabled, Sonarr will download completed files from Put.io. If you manually sync with rclone or similar, disable this")]
|
[FieldDefinition(2, Label = "Download Path", Type = FieldType.Path, HelpText = "Path were Sonarr will expect the files to get downloaded to. Note: This client does not download finished transfers automatically. Instead make sure that you download them outside of Sonarr e.g. with rclone")]
|
||||||
public bool DownloadFiles { get; set; }
|
|
||||||
|
|
||||||
[FieldDefinition(3, Label = "Download Path", Type = FieldType.Path, HelpText = "Path were Put.io is downloading to or if downloading is disabled where the mounts are expected")]
|
|
||||||
public string DownloadPath { get; set; }
|
public string DownloadPath { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(3, Label = "Delete imported files", Type = FieldType.Checkbox, HelpText = "Delete the files on put.io when Sonarr marks them as successfully imported")]
|
||||||
|
public bool DeleteImported { get; set; }
|
||||||
|
|
||||||
public NzbDroneValidationResult Validate()
|
public NzbDroneValidationResult Validate()
|
||||||
{
|
{
|
||||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||||
|
|
|
@ -4,39 +4,41 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
{
|
{
|
||||||
public class PutioTorrent
|
public class PutioTorrent
|
||||||
{
|
{
|
||||||
public long Downloaded { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "error_message")]
|
|
||||||
public string ErrorMessage { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "estimated_time")]
|
|
||||||
public long EstimatedTime { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "file_id")]
|
|
||||||
public long FileId { get; set; }
|
|
||||||
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public string Hash { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public long Downloaded { get; set; }
|
||||||
|
public long Uploaded { get; set; }
|
||||||
|
[JsonProperty(PropertyName = "error_message")]
|
||||||
|
public string ErrorMessage { get; set; }
|
||||||
|
[JsonProperty(PropertyName = "estimated_time")]
|
||||||
|
public long EstimatedTime { get; set; }
|
||||||
|
[JsonProperty(PropertyName = "file_id")]
|
||||||
|
public long FileId { get; set; }
|
||||||
[JsonProperty(PropertyName = "percent_done")]
|
[JsonProperty(PropertyName = "percent_done")]
|
||||||
public int PercentDone { get; set; }
|
public int PercentDone { get; set; }
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "seconds_seeding")]
|
[JsonProperty(PropertyName = "seconds_seeding")]
|
||||||
public long SecondsSeeding { get; set; }
|
public long SecondsSeeding { get; set; }
|
||||||
|
|
||||||
public long Size { get; set; }
|
public long Size { get; set; }
|
||||||
|
|
||||||
public string Status { get; set; }
|
public string Status { get; set; }
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "save_parent_id")]
|
[JsonProperty(PropertyName = "save_parent_id")]
|
||||||
public long SaveParentId { get; set; }
|
public long SaveParentId { get; set; }
|
||||||
|
[JsonProperty(PropertyName = "current_ratio")]
|
||||||
public string Hash { get; set; }
|
public double Ratio { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PutioTorrentMetadata
|
public class PutioTorrentMetadata
|
||||||
{
|
{
|
||||||
|
public static PutioTorrentMetadata fromTorrent(PutioTorrent torrent, bool downloaded = false)
|
||||||
|
{
|
||||||
|
return new PutioTorrentMetadata
|
||||||
|
{
|
||||||
|
Downloaded = downloaded,
|
||||||
|
Id = torrent.Id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public bool Downloaded { get; set; }
|
public bool Downloaded { get; set; }
|
||||||
|
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
Loading…
Reference in New Issue