Fixed: Sab Removing and DS Various

This commit is contained in:
Qstick 2021-12-24 16:25:17 -06:00
commit 7ea4e4070e
33 changed files with 215 additions and 123 deletions

View file

@ -218,7 +218,7 @@ namespace Lidarr.Api.V1.Queue
throw new BadRequestException(); throw new BadRequestException();
} }
downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true); downloadClient.RemoveItem(trackedDownload.DownloadItem, true);
} }
if (blocklist) if (blocklist)

View file

@ -4,6 +4,7 @@ using System.IO;
using System.IO.Abstractions; using System.IO.Abstractions;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
@ -26,6 +27,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
protected string _blackholeFolder; protected string _blackholeFolder;
protected string _filePath; protected string _filePath;
protected string _magnetFilePath; protected string _magnetFilePath;
protected DownloadClientItem _downloadClientItem;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -33,6 +35,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
_completedDownloadFolder = @"c:\blackhole\completed".AsOsAgnostic(); _completedDownloadFolder = @"c:\blackhole\completed".AsOsAgnostic();
_blackholeFolder = @"c:\blackhole\torrent".AsOsAgnostic(); _blackholeFolder = @"c:\blackhole\torrent".AsOsAgnostic();
_filePath = (@"c:\blackhole\torrent\" + _title + ".torrent").AsOsAgnostic(); _filePath = (@"c:\blackhole\torrent\" + _title + ".torrent").AsOsAgnostic();
_magnetFilePath = Path.ChangeExtension(_filePath, ".magnet");
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew()
.With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0")
.With(d => d.OutputPath = new OsPath(Path.Combine(_completedDownloadFolder, _title)))
.Build();
Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>()); Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>());
@ -248,7 +257,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.FileExists(It.IsAny<string>())) .Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Once()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Once());
@ -263,7 +272,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.FolderExists(It.IsAny<string>())) .Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Once()); .Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Once());
@ -272,7 +281,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
[Test] [Test]
public void RemoveItem_should_ignore_if_unknown_item() public void RemoveItem_should_ignore_if_unknown_item()
{ {
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());
@ -286,7 +295,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{ {
GivenCompletedItem(); GivenCompletedItem();
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", false)); Assert.Throws<NotSupportedException>(() => Subject.RemoveItem(_downloadClientItem, false));
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());

View file

@ -4,6 +4,7 @@ using System.IO;
using System.IO.Abstractions; using System.IO.Abstractions;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
@ -22,6 +23,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
protected string _completedDownloadFolder; protected string _completedDownloadFolder;
protected string _blackholeFolder; protected string _blackholeFolder;
protected string _filePath; protected string _filePath;
protected DownloadClientItem _downloadClientItem;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -30,6 +32,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
_blackholeFolder = @"c:\blackhole\nzb".AsOsAgnostic(); _blackholeFolder = @"c:\blackhole\nzb".AsOsAgnostic();
_filePath = (@"c:\blackhole\nzb\" + _title + ".nzb").AsOsAgnostic(); _filePath = (@"c:\blackhole\nzb\" + _title + ".nzb").AsOsAgnostic();
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew()
.With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0")
.With(d => d.OutputPath = new OsPath(Path.Combine(_completedDownloadFolder, _title)))
.Build();
Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>()); Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>());
Subject.Definition = new DownloadClientDefinition(); Subject.Definition = new DownloadClientDefinition();
@ -147,7 +155,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.FileExists(It.IsAny<string>())) .Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Once()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Once());
@ -162,7 +170,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.FolderExists(It.IsAny<string>())) .Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Once()); .Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Once());
@ -171,7 +179,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
[Test] [Test]
public void RemoveItem_should_ignore_if_unknown_item() public void RemoveItem_should_ignore_if_unknown_item()
{ {
Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());
@ -185,7 +193,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{ {
GivenCompletedItem(); GivenCompletedItem();
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem("_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0", false)); Assert.Throws<NotSupportedException>(() => Subject.RemoveItem(_downloadClientItem, false));
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never()); .Verify(c => c.DeleteFile(It.IsAny<string>()), Times.Never());

View file

@ -66,7 +66,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
Detail = new Dictionary<string, string> Detail = new Dictionary<string, string>
{ {
{ "destination", "shared/folder" }, { "destination", "shared/folder" },
{ "uri", FileNameBuilder.CleanFileName(_remoteAlbum.Release.Title) + ".nzb" } { "uri", CleanFileName(_remoteAlbum.Release.Title) }
}, },
Transfer = new Dictionary<string, string> Transfer = new Dictionary<string, string>
{ {
@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
Detail = new Dictionary<string, string> Detail = new Dictionary<string, string>
{ {
{ "destination", "shared/folder" }, { "destination", "shared/folder" },
{ "uri", FileNameBuilder.CleanFileName(_remoteAlbum.Release.Title) + ".nzb" } { "uri", CleanFileName(_remoteAlbum.Release.Title) }
}, },
Transfer = new Dictionary<string, string> Transfer = new Dictionary<string, string>
{ {
@ -112,7 +112,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
Detail = new Dictionary<string, string> Detail = new Dictionary<string, string>
{ {
{ "destination", "shared/folder" }, { "destination", "shared/folder" },
{ "uri", FileNameBuilder.CleanFileName(_remoteAlbum.Release.Title) + ".nzb" } { "uri", CleanFileName(_remoteAlbum.Release.Title) }
}, },
Transfer = new Dictionary<string, string> Transfer = new Dictionary<string, string>
{ {
@ -135,7 +135,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
Detail = new Dictionary<string, string> Detail = new Dictionary<string, string>
{ {
{ "destination", "shared/folder" }, { "destination", "shared/folder" },
{ "uri", FileNameBuilder.CleanFileName(_remoteAlbum.Release.Title) + ".nzb" } { "uri", CleanFileName(_remoteAlbum.Release.Title) }
}, },
Transfer = new Dictionary<string, string> Transfer = new Dictionary<string, string>
{ {
@ -158,7 +158,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
Detail = new Dictionary<string, string> Detail = new Dictionary<string, string>
{ {
{ "destination", "shared/folder" }, { "destination", "shared/folder" },
{ "uri", FileNameBuilder.CleanFileName(_remoteAlbum.Release.Title) + ".nzb" } { "uri", CleanFileName(_remoteAlbum.Release.Title) }
}, },
Transfer = new Dictionary<string, string> Transfer = new Dictionary<string, string>
{ {
@ -261,6 +261,11 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
.Returns(tasks); .Returns(tasks);
} }
protected static string CleanFileName(string name)
{
return FileNameBuilder.CleanFileName(name) + ".nzb";
}
[Test] [Test]
public void Download_with_TvDirectory_should_force_directory() public void Download_with_TvDirectory_should_force_directory()
{ {

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
@ -20,6 +21,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
private NzbgetHistoryItem _failed; private NzbgetHistoryItem _failed;
private NzbgetHistoryItem _completed; private NzbgetHistoryItem _completed;
private Dictionary<string, string> _configItems; private Dictionary<string, string> _configItems;
private DownloadClientItem _downloadClientItem;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -74,6 +76,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
MarkStatus = "NONE" MarkStatus = "NONE"
}; };
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew()
.With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0")
.With(d => d.OutputPath = new OsPath("/remote/mount/tv/Droned.S01E01.Pilot.1080p.WEB-DL-DRONE".AsOsAgnostic()))
.Build();
Mocker.GetMock<INzbgetProxy>() Mocker.GetMock<INzbgetProxy>()
.Setup(s => s.GetGlobalStatus(It.IsAny<NzbgetSettings>())) .Setup(s => s.GetGlobalStatus(It.IsAny<NzbgetSettings>()))
.Returns(new NzbgetGlobalStatus .Returns(new NzbgetGlobalStatus
@ -155,7 +163,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
.Setup(v => v.FolderExists(It.IsAny<string>())) .Setup(v => v.FolderExists(It.IsAny<string>()))
.Returns(true); .Returns(true);
Subject.RemoveItem("id", true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Once()); .Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Once());

View file

@ -1,6 +1,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
using FizzWare.NBuilder;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
@ -21,6 +22,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
private string _strmFolder; private string _strmFolder;
private string _nzbPath; private string _nzbPath;
private RemoteAlbum _remoteAlbum; private RemoteAlbum _remoteAlbum;
private DownloadClientItem _downloadClientItem;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -37,6 +39,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
_remoteAlbum.ParsedAlbumInfo = new ParsedAlbumInfo(); _remoteAlbum.ParsedAlbumInfo = new ParsedAlbumInfo();
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0")
.Build();
Subject.Definition = new DownloadClientDefinition(); Subject.Definition = new DownloadClientDefinition();
Subject.Definition.Settings = new PneumaticSettings Subject.Definition.Settings = new PneumaticSettings
{ {
@ -78,7 +84,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
[Test] [Test]
public void should_throw_item_is_removed() public void should_throw_item_is_removed()
{ {
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem("", true)); Assert.Throws<NotSupportedException>(() => Subject.RemoveItem(_downloadClientItem, true));
} }
[Test] [Test]

View file

@ -24,6 +24,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
private SabnzbdHistory _completed; private SabnzbdHistory _completed;
private SabnzbdConfig _config; private SabnzbdConfig _config;
private SabnzbdFullStatus _fullStatus; private SabnzbdFullStatus _fullStatus;
private DownloadClientItem _downloadClientItem;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -101,6 +102,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
} }
}; };
_downloadClientItem = Builder<DownloadClientItem>
.CreateNew()
.With(d => d.Status = DownloadItemStatus.Completed)
.With(d => d.DownloadId = _completed.Items.First().Id)
.Build();
Mocker.GetMock<ISabnzbdProxy>() Mocker.GetMock<ISabnzbdProxy>()
.Setup(v => v.GetVersion(It.IsAny<SabnzbdSettings>())) .Setup(v => v.GetVersion(It.IsAny<SabnzbdSettings>()))
.Returns("1.2.3"); .Returns("1.2.3");
@ -583,6 +590,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
public void should_remove_output_path_folder_when_deleting_a_completed_item_and_delete_data_is_true() public void should_remove_output_path_folder_when_deleting_a_completed_item_and_delete_data_is_true()
{ {
var path = @"C:\Test\Series.Title.S01E01".AsOsAgnostic(); var path = @"C:\Test\Series.Title.S01E01".AsOsAgnostic();
_downloadClientItem.OutputPath = new OsPath(path);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(path)) .Setup(s => s.FolderExists(path))
@ -593,7 +601,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
GivenQueue(null); GivenQueue(null);
GivenHistory(_completed); GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(path, true), Times.Once); .Verify(v => v.DeleteFolder(path, true), Times.Once);
@ -606,6 +614,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
public void should_remove_output_path_file_when_deleting_a_completed_item_and_delete_data_is_true() public void should_remove_output_path_file_when_deleting_a_completed_item_and_delete_data_is_true()
{ {
var path = @"C:\Test\Series.Title.S01E01.mkv".AsOsAgnostic(); var path = @"C:\Test\Series.Title.S01E01.mkv".AsOsAgnostic();
_downloadClientItem.OutputPath = new OsPath(path);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(path)) .Setup(s => s.FolderExists(path))
@ -620,7 +629,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
GivenQueue(null); GivenQueue(null);
GivenHistory(_completed); GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(path, true), Times.Never); .Verify(v => v.DeleteFolder(path, true), Times.Never);
@ -647,7 +656,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
GivenQueue(null); GivenQueue(null);
GivenHistory(_completed); GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, true); Subject.RemoveItem(_downloadClientItem, true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(path, true), Times.Never); .Verify(v => v.DeleteFolder(path, true), Times.Never);
@ -674,7 +683,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
GivenQueue(null); GivenQueue(null);
GivenHistory(_completed); GivenHistory(_completed);
Subject.RemoveItem(_completed.Items.First().Id, false); Subject.RemoveItem(_downloadClientItem, false);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(v => v.FolderExists(path), Times.Never); .Verify(v => v.FolderExists(path), Times.Never);

View file

@ -152,10 +152,10 @@ namespace NzbDrone.Core.Download.Clients.Aria2
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
// Aria2 doesn't support file deletion: https://github.com/aria2/aria2/issues/728 // Aria2 doesn't support file deletion: https://github.com/aria2/aria2/issues/728
var hash = downloadId.ToLower(); var hash = item.DownloadId.ToLower();
var aria2Item = _proxy.GetTorrents(Settings).FirstOrDefault(t => t.InfoHash?.ToLower() == hash); var aria2Item = _proxy.GetTorrents(Settings).FirstOrDefault(t => t.InfoHash?.ToLower() == hash);
if (aria2Item == null) if (aria2Item == null)
@ -187,7 +187,7 @@ namespace NzbDrone.Core.Download.Clients.Aria2
if (deleteData) if (deleteData)
{ {
DeleteItemData(downloadId); DeleteItemData(item);
} }
} }

View file

@ -105,14 +105,14 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (!deleteData) if (!deleteData)
{ {
throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring."); throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring.");
} }
DeleteItemData(downloadId); DeleteItemData(item);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View file

@ -77,14 +77,14 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (!deleteData) if (!deleteData)
{ {
throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring."); throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring.");
} }
DeleteItemData(downloadId); DeleteItemData(item);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View file

@ -188,9 +188,9 @@ namespace NzbDrone.Core.Download.Clients.Deluge
return items; return items;
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
_proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings); _proxy.RemoveTorrent(item.DownloadId.ToLower(), deleteData, Settings);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View file

@ -7,6 +7,7 @@
DownloadStationInfo, DownloadStationInfo,
DownloadStationTask, DownloadStationTask,
DownloadStation2Task, DownloadStation2Task,
DownloadStation2SettingsLocation,
FileStationList, FileStationList,
DSMInfo, DSMInfo,
} }

View file

@ -25,7 +25,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
public override string ToString() public override string ToString()
{ {
return this.Title; return Title;
} }
} }
} }

View file

@ -36,21 +36,21 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
[FieldDefinition(1, Label = "Port", Type = FieldType.Textbox)] [FieldDefinition(1, Label = "Port", Type = FieldType.Textbox)]
public int Port { get; set; } public int Port { get; set; }
[FieldDefinition(2, Label = "Username", Type = FieldType.Textbox, Privacy = PrivacyLevel.UserName)] [FieldDefinition(2, Label = "Use SSL", Type = FieldType.Checkbox, HelpText = "Use secure connection when connecting to Download Station")]
public bool UseSsl { get; set; }
[FieldDefinition(3, Label = "Username", Type = FieldType.Textbox, Privacy = PrivacyLevel.UserName)]
public string Username { get; set; } public string Username { get; set; }
[FieldDefinition(3, Label = "Password", Type = FieldType.Password, Privacy = PrivacyLevel.Password)] [FieldDefinition(4, Label = "Password", Type = FieldType.Password, Privacy = PrivacyLevel.Password)]
public string Password { get; set; } public string Password { get; set; }
[FieldDefinition(4, Label = "Category", Type = FieldType.Textbox, HelpText = "Adding a category specific to Lidarr avoids conflicts with unrelated downloads, but it's optional. Creates a [category] subdirectory in the output directory.")] [FieldDefinition(5, Label = "Category", Type = FieldType.Textbox, HelpText = "Adding a category specific to Lidarr avoids conflicts with unrelated downloads, but it's optional. Creates a [category] subdirectory in the output directory.")]
public string MusicCategory { get; set; } public string MusicCategory { get; set; }
[FieldDefinition(5, Label = "Directory", Type = FieldType.Textbox, HelpText = "Optional shared folder to put downloads into, leave blank to use the default Download Station location")] [FieldDefinition(6, Label = "Directory", Type = FieldType.Textbox, HelpText = "Optional shared folder to put downloads into, leave blank to use the default Download Station location")]
public string TvDirectory { get; set; } public string TvDirectory { get; set; }
[FieldDefinition(6, Label = "Use SSL", Type = FieldType.Checkbox)]
public bool UseSsl { get; set; }
public DownloadStationSettings() public DownloadStationSettings()
{ {
Host = "127.0.0.1"; Host = "127.0.0.1";

View file

@ -0,0 +1,31 @@
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Http;
using NzbDrone.Core.Download.Clients.DownloadStation.Responses;
namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{
public interface IDownloadStation2SettingsLocationProxy
{
string GetDefaultDestination(DownloadStationSettings settings);
}
public class DownloadStation2SettingsLocationProxy : DiskStationProxyBase, IDownloadStation2SettingsLocationProxy
{
public DownloadStation2SettingsLocationProxy(IHttpClient httpClient, ICacheManager cacheManager, Logger logger)
: base(DiskStationApi.DownloadStation2SettingsLocation, "SYNO.DownloadStation2.Settings.Location", httpClient, cacheManager, logger)
{
}
public string GetDefaultDestination(DownloadStationSettings settings)
{
var info = GetApiInfo(settings);
var requestBuilder = BuildRequest(settings, "get", info.MinVersion);
var response = ProcessRequest<DownloadStation2SettingsLocationResponse>(requestBuilder, "get default destination folder", settings);
return response.Data.Default_Destination;
}
}
}

View file

@ -10,9 +10,12 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{ {
public class DownloadStationTaskProxyV2 : DiskStationProxyBase, IDownloadStationTaskProxy public class DownloadStationTaskProxyV2 : DiskStationProxyBase, IDownloadStationTaskProxy
{ {
private readonly IDownloadStation2SettingsLocationProxy _defaultDestinationProxy;
public DownloadStationTaskProxyV2(IHttpClient httpClient, ICacheManager cacheManager, Logger logger) public DownloadStationTaskProxyV2(IHttpClient httpClient, ICacheManager cacheManager, Logger logger)
: base(DiskStationApi.DownloadStation2Task, "SYNO.DownloadStation2.Task", httpClient, cacheManager, logger) : base(DiskStationApi.DownloadStation2Task, "SYNO.DownloadStation2.Task", httpClient, cacheManager, logger)
{ {
_defaultDestinationProxy = new DownloadStation2SettingsLocationProxy(httpClient, cacheManager, logger);
} }
public bool IsApiSupported(DownloadStationSettings settings) public bool IsApiSupported(DownloadStationSettings settings)
@ -32,6 +35,21 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{ {
requestBuilder.AddFormParameter("destination", $"\"{downloadDirectory}\""); requestBuilder.AddFormParameter("destination", $"\"{downloadDirectory}\"");
} }
else
{
_logger.Trace("No directory configured in settings; falling back to client default destination folder.");
string defaultDestination = _defaultDestinationProxy.GetDefaultDestination(settings);
if (defaultDestination.IsNotNullOrWhiteSpace())
{
_logger.Trace($"Default destination folder found: {defaultDestination}.");
requestBuilder.AddFormParameter("destination", $"\"{defaultDestination}\"");
}
else
{
_logger.Error("Unable to get default destination folder from DownloadStation.");
}
}
requestBuilder.AddFormUpload("fileData", filename, data); requestBuilder.AddFormUpload("fileData", filename, data);
@ -50,6 +68,21 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{ {
requestBuilder.AddQueryParam("destination", downloadDirectory); requestBuilder.AddQueryParam("destination", downloadDirectory);
} }
else
{
_logger.Trace("No directory configured in settings; falling back to client default destination folder.");
string defaultDestination = _defaultDestinationProxy.GetDefaultDestination(settings);
if (defaultDestination.IsNotNullOrWhiteSpace())
{
_logger.Trace($"Default destination folder found: {defaultDestination}.");
requestBuilder.AddQueryParam("destination", $"\"{defaultDestination}\"");
}
else
{
_logger.Error("Unable to get default destination folder from DownloadStation.");
}
}
ProcessRequest<object>(requestBuilder, $"add task from url {url}", settings); ProcessRequest<object>(requestBuilder, $"add task from url {url}", settings);
} }

View file

@ -0,0 +1,7 @@
namespace NzbDrone.Core.Download.Clients.DownloadStation.Responses
{
public class DownloadStation2SettingsLocationResponse
{
public string Default_Destination { get; set; }
}
}

View file

@ -116,14 +116,17 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
try try
{ {
var serialNumber = _serialNumberProvider.GetSerialNumber(Settings); var serialNumber = _serialNumberProvider.GetSerialNumber(Settings);
var sharedFolder = GetDownloadDirectory() ?? GetDefaultDir();
var outputPath = new OsPath($"/{sharedFolder.TrimStart('/')}"); // Download station returns the path without the leading `/`, but the leading
var path = _sharedFolderResolver.RemapToFullPath(outputPath, Settings, serialNumber); // slash is required to get the full path back from download station.
var path = new OsPath($"/{GetDownloadDirectory()}");
var fullPath = _sharedFolderResolver.RemapToFullPath(path, Settings, serialNumber);
return new DownloadClientInfo return new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost",
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, path) } OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, fullPath) }
}; };
} }
catch (DownloadClientException e) catch (DownloadClientException e)
@ -134,15 +137,15 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (deleteData) if (deleteData)
{ {
DeleteItemData(downloadId); DeleteItemData(item);
} }
DsTaskProxy.RemoveTask(ParseDownloadId(downloadId), Settings); DsTaskProxy.RemoveTask(ParseDownloadId(item.DownloadId), Settings);
_logger.Debug("{0} removed correctly", downloadId); _logger.Debug("{0} removed correctly", item.DownloadId);
} }
protected OsPath GetOutputPath(OsPath outputPath, DownloadStationTask torrent, string serialNumber) protected OsPath GetOutputPath(OsPath outputPath, DownloadStationTask torrent, string serialNumber)

View file

@ -140,14 +140,17 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
try try
{ {
var serialNumber = _serialNumberProvider.GetSerialNumber(Settings); var serialNumber = _serialNumberProvider.GetSerialNumber(Settings);
var sharedFolder = GetDownloadDirectory() ?? GetDefaultDir();
var outputPath = new OsPath($"/{sharedFolder.TrimStart('/')}"); // Download station returns the path without the leading `/`, but the leading
var path = _sharedFolderResolver.RemapToFullPath(outputPath, Settings, serialNumber); // slash is required to get the full path back from download station.
var path = new OsPath($"/{GetDownloadDirectory()}");
var fullPath = _sharedFolderResolver.RemapToFullPath(path, Settings, serialNumber);
return new DownloadClientInfo return new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost",
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, path) } OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, fullPath) }
}; };
} }
catch (DownloadClientException e) catch (DownloadClientException e)
@ -158,15 +161,15 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (deleteData) if (deleteData)
{ {
DeleteItemData(downloadId); DeleteItemData(item);
} }
DsTaskProxy.RemoveTask(ParseDownloadId(downloadId), Settings); DsTaskProxy.RemoveTask(ParseDownloadId(item.DownloadId), Settings);
_logger.Debug("{0} removed correctly", downloadId); _logger.Debug("{0} removed correctly", item.DownloadId);
} }
protected override string AddFromNzbFile(RemoteAlbum remoteAlbum, string filename, byte[] fileContent) protected override string AddFromNzbFile(RemoteAlbum remoteAlbum, string filename, byte[] fileContent)

View file

@ -193,9 +193,9 @@ namespace NzbDrone.Core.Download.Clients.Flood
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
_proxy.DeleteTorrent(downloadId, deleteData, Settings); _proxy.DeleteTorrent(item.DownloadId, deleteData, Settings);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View file

@ -96,15 +96,15 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
return items; return items;
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (deleteData) if (deleteData)
{ {
_proxy.RemoveTorrentAndData(Settings, downloadId); _proxy.RemoveTorrentAndData(Settings, item.DownloadId);
} }
else else
{ {
_proxy.RemoveTorrent(Settings, downloadId); _proxy.RemoveTorrent(Settings, item.DownloadId);
} }
} }

View file

@ -110,19 +110,19 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex
return queueItems; return queueItems;
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
// Try to find the download by numerical ID, otherwise try by AddUUID // Try to find the download by numerical ID, otherwise try by AddUUID
int id; int id;
if (int.TryParse(downloadId, out id)) if (int.TryParse(item.DownloadId, out id))
{ {
_proxy.Remove(id, deleteData, Settings); _proxy.Remove(id, deleteData, Settings);
} }
else else
{ {
var queue = _proxy.GetQueue(30, Settings); var queue = _proxy.GetQueue(30, Settings);
var queueItem = queue.FirstOrDefault(c => c.AddUUID == downloadId); var queueItem = queue.FirstOrDefault(c => c.AddUUID == item.DownloadId);
if (queueItem != null) if (queueItem != null)
{ {

View file

@ -192,14 +192,14 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
return GetQueue().Concat(GetHistory()).Where(downloadClientItem => downloadClientItem.Category == Settings.MusicCategory); return GetQueue().Concat(GetHistory()).Where(downloadClientItem => downloadClientItem.Category == Settings.MusicCategory);
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (deleteData) if (deleteData)
{ {
DeleteItemData(downloadId); DeleteItemData(item);
} }
_proxy.RemoveItem(downloadId, Settings); _proxy.RemoveItem(item.DownloadId, Settings);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View file

@ -97,7 +97,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }

View file

@ -318,9 +318,9 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
return queueItems; return queueItems;
} }
public override void RemoveItem(string hash, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
Proxy.RemoveTorrent(hash.ToLower(), deleteData, Settings); Proxy.RemoveTorrent(item.DownloadId.ToLower(), deleteData, Settings);
} }
public override DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt) public override DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt)

View file

@ -192,47 +192,22 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
} }
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
var historyItem = GetHistory().SingleOrDefault(v => v.DownloadId == downloadId); var queueClientItem = GetQueue().SingleOrDefault(v => v.DownloadId == item.DownloadId);
if (historyItem == null) if (queueClientItem == null)
{ {
_proxy.RemoveFrom("queue", downloadId, deleteData, Settings); if (deleteData && item.Status == DownloadItemStatus.Completed)
{
DeleteItemData(item);
}
_proxy.RemoveFrom("history", item.DownloadId, deleteData, Settings);
} }
else else
{ {
_proxy.RemoveFrom("history", downloadId, deleteData, Settings); _proxy.RemoveFrom("queue", item.DownloadId, deleteData, Settings);
// Completed items in SAB's history do not remove the files from the file system when deleted, even if instructed to.
// If the output path is valid delete the file(s), otherwise warn that they cannot be deleted.
if (deleteData && historyItem.Status == DownloadItemStatus.Completed)
{
if (ValidatePath(historyItem))
{
var outputPath = historyItem.OutputPath;
try
{
if (_diskProvider.FolderExists(outputPath.FullPath))
{
_diskProvider.DeleteFolder(outputPath.FullPath.ToString(), true);
}
else if (_diskProvider.FileExists(outputPath.FullPath))
{
_diskProvider.DeleteFile(outputPath.FullPath.ToString());
}
}
catch (Exception)
{
_logger.Error("Unable to delete output path: '{0}'. Delete file(s) manually", outputPath.FullPath);
}
}
else
{
_logger.Warn("Invalid path '{0}'. Delete file(s) manually");
}
}
} }
} }

View file

@ -157,9 +157,9 @@ namespace NzbDrone.Core.Download.Clients.Transmission
return false; return false;
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
_proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings); _proxy.RemoveTorrent(item.DownloadId.ToLower(), deleteData, Settings);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View file

@ -24,9 +24,9 @@ namespace NzbDrone.Core.Download.Clients.Vuze
{ {
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
_proxy.RemoveTorrent(downloadId, deleteData, Settings); _proxy.RemoveTorrent(item.DownloadId, deleteData, Settings);
} }
protected override OsPath GetOutputPath(OsPath outputPath, TransmissionTorrent torrent) protected override OsPath GetOutputPath(OsPath outputPath, TransmissionTorrent torrent)

View file

@ -161,14 +161,14 @@ namespace NzbDrone.Core.Download.Clients.RTorrent
return items; return items;
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
if (deleteData) if (deleteData)
{ {
DeleteItemData(downloadId); DeleteItemData(item);
} }
_proxy.RemoveTorrent(downloadId, Settings); _proxy.RemoveTorrent(item.DownloadId, Settings);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View file

@ -206,9 +206,9 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
return torrents; return torrents;
} }
public override void RemoveItem(string downloadId, bool deleteData) public override void RemoveItem(DownloadClientItem item, bool deleteData)
{ {
_proxy.RemoveTorrent(downloadId, deleteData, Settings); _proxy.RemoveTorrent(item.DownloadId, deleteData, Settings);
} }
public override DownloadClientInfo GetStatus() public override DownloadClientInfo GetStatus()

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FluentValidation.Results; using FluentValidation.Results;
@ -68,20 +68,14 @@ namespace NzbDrone.Core.Download
return item; return item;
} }
public abstract void RemoveItem(string downloadId, bool deleteData); public abstract void RemoveItem(DownloadClientItem item, bool deleteData);
public abstract DownloadClientInfo GetStatus(); public abstract DownloadClientInfo GetStatus();
protected virtual void DeleteItemData(string downloadId) protected virtual void DeleteItemData(DownloadClientItem item)
{ {
if (downloadId.IsNullOrWhiteSpace())
{
return;
}
var item = GetItems().FirstOrDefault(v => v.DownloadId == downloadId);
if (item == null) if (item == null)
{ {
_logger.Trace("DownloadItem {0} in {1} history not found, skipping delete data.", downloadId, Name); _logger.Trace("DownloadItem {0} in {1} history not found, skipping delete data.", item.DownloadId, Name);
return; return;
} }

View file

@ -62,7 +62,7 @@ namespace NzbDrone.Core.Download
try try
{ {
_logger.Debug("[{0}] Removing download from {1} history", trackedDownload.DownloadItem.Title, trackedDownload.DownloadItem.DownloadClientInfo.Name); _logger.Debug("[{0}] Removing download from {1} history", trackedDownload.DownloadItem.Title, trackedDownload.DownloadItem.DownloadClientInfo.Name);
downloadClient.RemoveItem(trackedDownload.DownloadItem.DownloadId, true); downloadClient.RemoveItem(trackedDownload.DownloadItem, true);
trackedDownload.DownloadItem.Removed = true; trackedDownload.DownloadItem.Removed = true;
} }
catch (NotSupportedException) catch (NotSupportedException)

View file

@ -12,7 +12,7 @@ namespace NzbDrone.Core.Download
string Download(RemoteAlbum remoteAlbum); string Download(RemoteAlbum remoteAlbum);
IEnumerable<DownloadClientItem> GetItems(); IEnumerable<DownloadClientItem> GetItems();
DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt); DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt);
void RemoveItem(string downloadId, bool deleteData); void RemoveItem(DownloadClientItem item, bool deleteData);
DownloadClientInfo GetStatus(); DownloadClientInfo GetStatus();
void MarkItemAsImported(DownloadClientItem downloadClientItem); void MarkItemAsImported(DownloadClientItem downloadClientItem);
} }