Sonarr Pulls

'e4c341898
'5613ab05e
'372442af2
'28c45f941
'ea1616586
pull/94/head
Qstick 7 years ago
parent 482f8c1a61
commit ab9a9232cf

@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Linq;
using System.Net;
@ -99,6 +99,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
var result = Subject.GetItems().Single();
VerifyCompleted(result);
result.CanBeRemoved.Should().BeFalse();
result.CanMoveFiles.Should().BeFalse();
}
[Test]

@ -1,4 +1,4 @@

using System;
using System.IO;
using System.Linq;
@ -77,6 +77,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
var result = Subject.GetItems().Single();
VerifyCompleted(result);
result.CanBeRemoved.Should().BeTrue();
result.CanMoveFiles.Should().BeTrue();
}
[Test]

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using FluentAssertions;
@ -19,6 +19,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
protected DelugeTorrent _downloading;
protected DelugeTorrent _failed;
protected DelugeTorrent _completed;
protected DelugeTorrent _seeding;
[SetUp]
public void Setup()
@ -75,8 +76,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
Size = 1000,
BytesDownloaded = 1000,
Progress = 100.0,
DownloadPath = "somepath"
};
DownloadPath = "somepath",
IsAutoManaged = true,
StopAtRatio = true,
StopRatio = 1.0,
Ratio = 1.5
};
Mocker.GetMock<ITorrentFileInfoReader>()
.Setup(s => s.GetHashFromTorrentFile(It.IsAny<byte[]>()))
@ -189,6 +194,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
PrepareClientToReturnCompletedItem();
var item = Subject.GetItems().Single();
VerifyCompleted(item);
item.CanBeRemoved.Should().BeTrue();
item.CanMoveFiles.Should().BeTrue();
}
[Test]
@ -248,11 +256,11 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
item.Status.Should().Be(expectedItemStatus);
}
[TestCase(DelugeTorrentStatus.Paused, DownloadItemStatus.Completed, true)]
[TestCase(DelugeTorrentStatus.Checking, DownloadItemStatus.Downloading, true)]
[TestCase(DelugeTorrentStatus.Queued, DownloadItemStatus.Completed, true)]
[TestCase(DelugeTorrentStatus.Seeding, DownloadItemStatus.Completed, true)]
public void GetItems_should_return_completed_item_as_downloadItemStatus(string apiStatus, DownloadItemStatus expectedItemStatus, bool expectedReadOnly)
[TestCase(DelugeTorrentStatus.Paused, DownloadItemStatus.Completed)]
[TestCase(DelugeTorrentStatus.Checking, DownloadItemStatus.Downloading)]
[TestCase(DelugeTorrentStatus.Queued, DownloadItemStatus.Completed)]
[TestCase(DelugeTorrentStatus.Seeding, DownloadItemStatus.Completed)]
public void GetItems_should_return_completed_item_as_downloadItemStatus(string apiStatus, DownloadItemStatus expectedItemStatus)
{
_completed.State = apiStatus;
@ -261,24 +269,25 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
var item = Subject.GetItems().Single();
item.Status.Should().Be(expectedItemStatus);
item.IsReadOnly.Should().Be(expectedReadOnly);
}
[Test]
public void GetItems_should_check_share_ratio_for_readonly()
[TestCase(0.5, false)]
[TestCase(1.01, true)]
public void GetItems_should_check_share_ratio_for_moveFiles_and_remove(double ratio, bool canBeRemoved)
{
_completed.State = DelugeTorrentStatus.Paused;
_completed.IsAutoManaged = true;
_completed.StopAtRatio = true;
_completed.StopRatio = 1.0;
_completed.Ratio = 1.01;
_completed.Ratio = ratio;
PrepareClientToReturnCompletedItem();
var item = Subject.GetItems().Single();
item.Status.Should().Be(DownloadItemStatus.Completed);
item.IsReadOnly.Should().BeFalse();
item.CanMoveFiles.Should().Be(canBeRemoved);
item.CanBeRemoved.Should().Be(canBeRemoved);
}
[Test]

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
@ -576,11 +576,11 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
items.Should().OnlyContain(v => !v.OutputPath.IsEmpty);
}
[TestCase(DownloadStationTaskStatus.Downloading, DownloadItemStatus.Downloading, true)]
[TestCase(DownloadStationTaskStatus.Finished, DownloadItemStatus.Completed, false)]
[TestCase(DownloadStationTaskStatus.Seeding, DownloadItemStatus.Completed, true)]
[TestCase(DownloadStationTaskStatus.Waiting, DownloadItemStatus.Queued, true)]
public void GetItems_should_return_readonly_expected(DownloadStationTaskStatus apiStatus, DownloadItemStatus expectedItemStatus, bool readOnlyExpected)
[TestCase(DownloadStationTaskStatus.Downloading, false, false)]
[TestCase(DownloadStationTaskStatus.Finished, true, true)]
[TestCase(DownloadStationTaskStatus.Seeding, true, false)]
[TestCase(DownloadStationTaskStatus.Waiting, false, false)]
public void GetItems_should_return_canBeMoved_and_canBeDeleted_as_expected(DownloadStationTaskStatus apiStatus, bool canMoveFilesExpected, bool canBeRemovedExpected)
{
GivenSerialNumber();
GivenSharedFolder();
@ -592,7 +592,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var items = Subject.GetItems();
items.Should().HaveCount(1);
items.First().IsReadOnly.Should().Be(readOnlyExpected);
var item = items.First();
item.CanBeRemoved.Should().Be(canBeRemovedExpected);
item.CanMoveFiles.Should().Be(canMoveFilesExpected);
}
[TestCase(DownloadStationTaskStatus.Downloading, DownloadItemStatus.Downloading)]

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
@ -408,24 +408,6 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
items.Should().OnlyContain(v => !v.OutputPath.IsEmpty);
}
[TestCase(DownloadStationTaskStatus.Downloading, DownloadItemStatus.Downloading, true)]
[TestCase(DownloadStationTaskStatus.Finished, DownloadItemStatus.Completed, false)]
[TestCase(DownloadStationTaskStatus.Waiting, DownloadItemStatus.Queued, true)]
public void GetItems_should_return_readonly_expected(DownloadStationTaskStatus apiStatus, DownloadItemStatus expectedItemStatus, bool readOnlyExpected)
{
GivenSerialNumber();
GivenSharedFolder();
_queued.Status = apiStatus;
GivenTasks(new List<DownloadStationTask>() { _queued });
var items = Subject.GetItems();
items.Should().HaveCount(1);
items.First().IsReadOnly.Should().Be(readOnlyExpected);
}
[TestCase(DownloadStationTaskStatus.Downloading, DownloadItemStatus.Downloading)]
[TestCase(DownloadStationTaskStatus.Error, DownloadItemStatus.Failed)]
[TestCase(DownloadStationTaskStatus.Extracting, DownloadItemStatus.Downloading)]

@ -1,4 +1,4 @@
using Moq;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Http;
using NzbDrone.Core.Download;
@ -190,6 +190,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests
PrepareClientToReturnCompletedItem();
var item = Subject.GetItems().Single();
VerifyCompleted(item);
item.CanBeRemoved.Should().BeTrue();
item.CanMoveFiles.Should().BeTrue();
}
[Test]

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using FluentAssertions;
@ -139,6 +139,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbVortexTests
var result = Subject.GetItems().Single();
VerifyCompleted(result);
result.CanBeRemoved.Should().BeTrue();
result.CanMoveFiles.Should().BeTrue();
}
[Test]

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using FluentAssertions;
@ -204,6 +204,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
var result = Subject.GetItems().Single();
VerifyCompleted(result);
result.CanBeRemoved.Should().BeTrue();
result.CanMoveFiles.Should().BeTrue();
}
[Test]

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using FluentAssertions;
@ -311,7 +311,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
}
[Test]
public void should_be_read_only_if_max_ratio_not_reached()
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_not_reached()
{
GivenMaxRatio(1.0f);
@ -330,11 +330,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
GivenTorrents(new List<QBittorrentTorrent> { torrent });
var item = Subject.GetItems().Single();
item.IsReadOnly.Should().BeTrue();
item.CanBeRemoved.Should().BeFalse();
item.CanMoveFiles.Should().BeFalse();
}
[Test]
public void should_be_read_only_if_max_ratio_reached_and_not_paused()
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_reached_and_not_paused()
{
GivenMaxRatio(1.0f);
@ -353,11 +354,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
GivenTorrents(new List<QBittorrentTorrent> { torrent });
var item = Subject.GetItems().Single();
item.IsReadOnly.Should().BeTrue();
item.CanBeRemoved.Should().BeFalse();
item.CanMoveFiles.Should().BeFalse();
}
[Test]
public void should_be_read_only_if_max_ratio_is_not_set()
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_is_not_set()
{
GivenMaxRatio(1.0f, false);
@ -376,11 +378,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
GivenTorrents(new List<QBittorrentTorrent> { torrent });
var item = Subject.GetItems().Single();
item.IsReadOnly.Should().BeTrue();
item.CanBeRemoved.Should().BeFalse();
item.CanMoveFiles.Should().BeFalse();
}
[Test]
public void should_not_be_read_only_if_max_ratio_reached_and_paused()
public void should_be_removable_and_should_allow_move_files_if_max_ratio_reached_and_paused()
{
GivenMaxRatio(1.0f);
@ -399,7 +402,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
GivenTorrents(new List<QBittorrentTorrent> { torrent });
var item = Subject.GetItems().Single();
item.IsReadOnly.Should().BeFalse();
item.CanBeRemoved.Should().BeTrue();
item.CanMoveFiles.Should().BeTrue();
}
[Test]

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using FizzWare.NBuilder;
@ -239,6 +239,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
var result = Subject.GetItems().Single();
VerifyCompleted(result);
result.CanBeRemoved.Should().BeTrue();
result.CanMoveFiles.Should().BeTrue();
}
[Test]

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Moq;
@ -41,6 +41,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
PrepareClientToReturnCompletedItem();
var item = Subject.GetItems().Single();
VerifyCompleted(item);
item.CanBeRemoved.Should().BeTrue();
item.CanMoveFiles.Should().BeTrue();
}
[Test]
@ -172,13 +175,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
item.Status.Should().Be(expectedItemStatus);
}
[TestCase(TransmissionTorrentStatus.Stopped, DownloadItemStatus.Completed, false)]
[TestCase(TransmissionTorrentStatus.CheckWait, DownloadItemStatus.Downloading, true)]
[TestCase(TransmissionTorrentStatus.Check, DownloadItemStatus.Downloading, true)]
[TestCase(TransmissionTorrentStatus.Queued, DownloadItemStatus.Completed, true)]
[TestCase(TransmissionTorrentStatus.SeedingWait, DownloadItemStatus.Completed, true)]
[TestCase(TransmissionTorrentStatus.Seeding, DownloadItemStatus.Completed, true)]
public void GetItems_should_return_completed_item_as_downloadItemStatus(TransmissionTorrentStatus apiStatus, DownloadItemStatus expectedItemStatus, bool expectedReadOnly)
[TestCase(TransmissionTorrentStatus.Stopped, DownloadItemStatus.Completed, true)]
[TestCase(TransmissionTorrentStatus.CheckWait, DownloadItemStatus.Downloading, false)]
[TestCase(TransmissionTorrentStatus.Check, DownloadItemStatus.Downloading, false)]
[TestCase(TransmissionTorrentStatus.Queued, DownloadItemStatus.Completed, false)]
[TestCase(TransmissionTorrentStatus.SeedingWait, DownloadItemStatus.Completed, false)]
[TestCase(TransmissionTorrentStatus.Seeding, DownloadItemStatus.Completed, false)]
public void GetItems_should_return_completed_item_as_downloadItemStatus(TransmissionTorrentStatus apiStatus, DownloadItemStatus expectedItemStatus, bool expectedValue)
{
_completed.Status = apiStatus;
@ -187,7 +190,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var item = Subject.GetItems().Single();
item.Status.Should().Be(expectedItemStatus);
item.IsReadOnly.Should().Be(expectedReadOnly);
item.CanBeRemoved.Should().Be(expectedValue);
item.CanMoveFiles.Should().Be(expectedValue);
}
[Test]

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using FluentAssertions;
@ -222,6 +222,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
PrepareClientToReturnCompletedItem();
var item = Subject.GetItems().Single();
VerifyCompleted(item);
item.CanBeRemoved.Should().BeTrue();
item.CanMoveFiles.Should().BeTrue();
}
[Test]
@ -292,12 +295,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
item.Status.Should().Be(expectedItemStatus);
}
[TestCase(UTorrentTorrentStatus.Loaded | UTorrentTorrentStatus.Checking, DownloadItemStatus.Queued, false)]
[TestCase(UTorrentTorrentStatus.Loaded | UTorrentTorrentStatus.Checked, DownloadItemStatus.Completed, false)]
[TestCase(UTorrentTorrentStatus.Loaded | UTorrentTorrentStatus.Checked | UTorrentTorrentStatus.Queued, DownloadItemStatus.Completed, true)]
[TestCase(UTorrentTorrentStatus.Loaded | UTorrentTorrentStatus.Checked | UTorrentTorrentStatus.Started, DownloadItemStatus.Completed, true)]
[TestCase(UTorrentTorrentStatus.Loaded | UTorrentTorrentStatus.Checked | UTorrentTorrentStatus.Queued | UTorrentTorrentStatus.Paused, DownloadItemStatus.Completed, true)]
public void GetItems_should_return_completed_item_as_downloadItemStatus(UTorrentTorrentStatus apiStatus, DownloadItemStatus expectedItemStatus, bool expectedReadOnly)
[TestCase(UTorrentTorrentStatus.Loaded | UTorrentTorrentStatus.Checking, DownloadItemStatus.Queued, true)]
[TestCase(UTorrentTorrentStatus.Loaded | UTorrentTorrentStatus.Checked, DownloadItemStatus.Completed, true)]
[TestCase(UTorrentTorrentStatus.Loaded | UTorrentTorrentStatus.Checked | UTorrentTorrentStatus.Queued, DownloadItemStatus.Completed, false)]
[TestCase(UTorrentTorrentStatus.Loaded | UTorrentTorrentStatus.Checked | UTorrentTorrentStatus.Started, DownloadItemStatus.Completed, false)]
[TestCase(UTorrentTorrentStatus.Loaded | UTorrentTorrentStatus.Checked | UTorrentTorrentStatus.Queued | UTorrentTorrentStatus.Paused, DownloadItemStatus.Completed, false)]
public void GetItems_should_return_completed_item_as_downloadItemStatus(UTorrentTorrentStatus apiStatus, DownloadItemStatus expectedItemStatus, bool expectedValue)
{
_completed.Status = apiStatus;
@ -306,7 +309,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
var item = Subject.GetItems().Single();
item.Status.Should().Be(expectedItemStatus);
item.IsReadOnly.Should().Be(expectedReadOnly);
item.CanBeRemoved.Should().Be(expectedValue);
item.CanMoveFiles.Should().Be(expectedValue);
}
[Test]

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Moq;
@ -43,6 +43,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
PrepareClientToReturnCompletedItem();
var item = Subject.GetItems().Single();
VerifyCompleted(item);
item.CanBeRemoved.Should().BeTrue();
item.CanMoveFiles.Should().BeTrue();
}
[Test]
@ -174,13 +177,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
item.Status.Should().Be(expectedItemStatus);
}
[TestCase(TransmissionTorrentStatus.Stopped, DownloadItemStatus.Completed, false)]
[TestCase(TransmissionTorrentStatus.CheckWait, DownloadItemStatus.Downloading, true)]
[TestCase(TransmissionTorrentStatus.Check, DownloadItemStatus.Downloading, true)]
[TestCase(TransmissionTorrentStatus.Queued, DownloadItemStatus.Completed, true)]
[TestCase(TransmissionTorrentStatus.SeedingWait, DownloadItemStatus.Completed, true)]
[TestCase(TransmissionTorrentStatus.Seeding, DownloadItemStatus.Completed, true)]
public void GetItems_should_return_completed_item_as_downloadItemStatus(TransmissionTorrentStatus apiStatus, DownloadItemStatus expectedItemStatus, bool expectedReadOnly)
[TestCase(TransmissionTorrentStatus.Stopped, DownloadItemStatus.Completed, true)]
[TestCase(TransmissionTorrentStatus.CheckWait, DownloadItemStatus.Downloading, false)]
[TestCase(TransmissionTorrentStatus.Check, DownloadItemStatus.Downloading, false)]
[TestCase(TransmissionTorrentStatus.Queued, DownloadItemStatus.Completed, false)]
[TestCase(TransmissionTorrentStatus.SeedingWait, DownloadItemStatus.Completed, false)]
[TestCase(TransmissionTorrentStatus.Seeding, DownloadItemStatus.Completed, false)]
public void GetItems_should_return_completed_item_as_downloadItemStatus(TransmissionTorrentStatus apiStatus, DownloadItemStatus expectedItemStatus, bool expectedValue)
{
_completed.Status = apiStatus;
@ -189,7 +192,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
var item = Subject.GetItems().Single();
item.Status.Should().Be(expectedItemStatus);
item.IsReadOnly.Should().Be(expectedReadOnly);
item.CanBeRemoved.Should().Be(expectedValue);
item.CanMoveFiles.Should().Be(expectedValue);
}
[Test]
@ -312,4 +316,4 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
}
}
}
}

@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test.HistoryTests
Path = @"C:\Test\Unsorted\Series.s01e01.mkv"
};
Subject.Handle(new EpisodeImportedEvent(localEpisode, episodeFile, true, "sab", "abcd", true));
Subject.Handle(new EpisodeImportedEvent(localEpisode, episodeFile, true, "sab", "abcd"));
Mocker.GetMock<IHistoryRepository>()
.Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localEpisode.Path))));

@ -1,5 +1,6 @@
using System;
using System;
using System.Linq;
using System.Net;
using FluentAssertions;
using Moq;
using NUnit.Framework;
@ -7,6 +8,7 @@ using NzbDrone.Common.Http;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
{
@ -69,5 +71,27 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
Subject.PageSize.Should().Be(25);
}
}
[Test]
public void should_record_indexer_failure_if_caps_throw()
{
var request = new HttpRequest("http://my.indexer.com");
var response = new HttpResponse(request, new HttpHeader(), new byte[0], (HttpStatusCode)429);
response.Headers["Retry-After"] = "300";
Mocker.GetMock<INewznabCapabilitiesProvider>()
.Setup(v => v.GetCapabilities(It.IsAny<NewznabSettings>()))
.Throws(new TooManyRequestsException(request, response));
_caps.MaxPageSize = 30;
_caps.DefaultPageSize = 25;
Subject.FetchRecent().Should().BeEmpty();
Mocker.GetMock<IIndexerStatusService>()
.Verify(v => v.RecordFailure(It.IsAny<int>(), TimeSpan.FromMinutes(5.0)), Times.Once());
ExceptionVerification.ExpectedWarns(1);
}
}
}

@ -231,9 +231,9 @@ namespace NzbDrone.Core.Test.MediaFiles
}
[Test]
public void should_copy_readonly_downloads()
public void should_copy_when_cannot_move_files_downloads()
{
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, new DownloadClientItem { Title = "30.Rock.S01E01", IsReadOnly = true });
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, new DownloadClientItem { Title = "30.Rock.S01E01", CanMoveFiles = false });
Mocker.GetMock<IUpgradeMediaFiles>()
.Verify(v => v.UpgradeTrackFile(It.IsAny<TrackFile>(), _approvedDecisions.First().LocalTrack, true), Times.Once());
@ -242,7 +242,7 @@ namespace NzbDrone.Core.Test.MediaFiles
[Test]
public void should_use_override_importmode()
{
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, new DownloadClientItem { Title = "30.Rock.S01E01", IsReadOnly = true }, ImportMode.Move);
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, new DownloadClientItem { Title = "30.Rock.S01E01", CanMoveFiles = false }, ImportMode.Move);
Mocker.GetMock<IUpgradeMediaFiles>()
.Verify(v => v.UpgradeTrackFile(It.IsAny<TrackFile>(), _approvedDecisions.First().LocalTrack, false), Times.Once());

@ -1,4 +1,5 @@
using System.Linq;
using System.IO;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Marr.Data;
@ -36,6 +37,10 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true);
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetParentFolder(It.IsAny<string>()))
.Returns<string>(c => Path.GetDirectoryName(c));
}
private void GivenSingleTrackWithSingleTrackFile()

@ -127,6 +127,7 @@ namespace NzbDrone.Core.Test.ParserTests
[TestCase("this.is.not.happening.2015.0308-yestv", "this is not happening 2015", 3, 8)]
[TestCase("Jeopardy - S2016E231", "Jeopardy", 2016, 231)]
[TestCase("Jeopardy - 2016x231", "Jeopardy", 2016, 231)]
[TestCase("Shortland.Street.S26E022.HDTV.x264-FiHTV", "Shortland Street", 26, 22)]
//[TestCase("", "", 0, 0)]
public void should_parse_single_episode(string postTitle, string title, int seasonNumber, int episodeNumber)
{

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
@ -103,7 +103,8 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
Status = item.Status,
IsReadOnly = Settings.ReadOnly
CanMoveFiles = !Settings.ReadOnly,
CanBeRemoved = !Settings.ReadOnly
};
}
}

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using FluentValidation.Results;
@ -68,7 +68,10 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
OutputPath = item.OutputPath,
Status = item.Status
Status = item.Status,
CanBeRemoved = true,
CanMoveFiles = true
};
}
}

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using NzbDrone.Common.Disk;
@ -138,14 +138,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
}
// Here we detect if Deluge is managing the torrent and whether the seed criteria has been met. This allows drone to delete the torrent as appropriate.
if (torrent.IsAutoManaged && torrent.StopAtRatio && torrent.Ratio >= torrent.StopRatio && torrent.State == DelugeTorrentStatus.Paused)
{
item.IsReadOnly = false;
}
else
{
item.IsReadOnly = true;
}
item.CanMoveFiles = item.CanBeRemoved = (torrent.IsAutoManaged && torrent.StopAtRatio && torrent.Ratio >= torrent.StopRatio && torrent.State == DelugeTorrentStatus.Paused);
items.Add(item);
}

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -90,7 +90,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
RemainingTime = GetRemainingTime(torrent),
Status = GetStatus(torrent),
Message = GetMessage(torrent),
IsReadOnly = !IsFinished(torrent)
CanMoveFiles = IsCompleted(torrent),
CanBeRemoved = IsFinished(torrent)
};
if (item.Status == DownloadItemStatus.Completed || item.Status == DownloadItemStatus.Failed)
@ -199,7 +200,12 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
return torrent.Status == DownloadStationTaskStatus.Finished;
}
protected string GetMessage(DownloadStationTask torrent)
protected bool IsCompleted(DownloadStationTask torrent)
{
return torrent.Status == DownloadStationTaskStatus.Seeding || IsFinished(torrent) || (torrent.Status == DownloadStationTaskStatus.Waiting && torrent.Size != 0 && GetRemainingSize(torrent) <= 0);
}
protected string GetMessage(DownloadStationTask torrent)
{
if (torrent.StatusExtra != null)
{

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
@ -99,7 +99,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
RemainingSize = taskRemainingSize,
Status = GetStatus(nzb),
Message = GetMessage(nzb),
IsReadOnly = !IsFinished(nzb)
CanBeRemoved = true,
CanMoveFiles = true
};
if (item.Status != DownloadItemStatus.Paused)
@ -291,11 +292,6 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
return null;
}
protected bool IsFinished(DownloadStationTask task)
{
return task.Status == DownloadStationTaskStatus.Finished;
}
protected string GetMessage(DownloadStationTask task)
{
if (task.StatusExtra != null)

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation.Results;
@ -97,14 +97,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
item.Status = DownloadItemStatus.Downloading;
}
if (torrent.IsFinished && torrent.State == HadoukenTorrentState.Paused)
{
item.IsReadOnly = false;
}
else
{
item.IsReadOnly = true;
}
item.CanMoveFiles = item.CanBeRemoved = (torrent.IsFinished && torrent.State == HadoukenTorrentState.Paused);
items.Add(item);
}
@ -170,7 +163,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
if (version < new Version("5.1"))
{
return new ValidationFailure(string.Empty, "Old Hadouken client with unsupported API, need 5.1 or higher");
return new ValidationFailure(string.Empty, "Old Hadouken client with unsupported API, need 5.1 or higher");
}
}
catch (DownloadClientAuthenticationException ex)

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -72,7 +72,10 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex
queueItem.TotalSize = vortexQueueItem.TotalDownloadSize;
queueItem.RemainingSize = vortexQueueItem.TotalDownloadSize - vortexQueueItem.DownloadedSize;
queueItem.RemainingTime = null;
queueItem.CanBeRemoved = true;
queueItem.CanMoveFiles = true;
if (vortexQueueItem.IsPaused)
{
queueItem.Status = DownloadItemStatus.Paused;
@ -132,7 +135,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex
{
_proxy.Remove(queueItem.Id, deleteData, Settings);
}
}
}
}
protected List<NzbVortexGroup> GetGroups()
@ -256,4 +259,4 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex
return new OsPath(Path.Combine(outputPath.FullPath, filesResponse.First().FileName));
}
}
}
}

@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
@ -145,6 +145,8 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
historyItem.Message = $"PAR Status: {item.ParStatus} - Unpack Status: {item.UnpackStatus} - Move Status: {item.MoveStatus} - Script Status: {item.ScriptStatus} - Delete Status: {item.DeleteStatus} - Mark Status: {item.MarkStatus}";
historyItem.Status = DownloadItemStatus.Completed;
historyItem.RemainingTime = TimeSpan.Zero;
historyItem.CanMoveFiles = true;
historyItem.CanBeRemoved = true;
if (item.DeleteStatus == "MANUAL")
{

@ -72,6 +72,9 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
DownloadId = GetDownloadClientId(file),
Title = title,
CanBeRemoved = true,
CanMoveFiles = true,
TotalSize = _diskProvider.GetFileSize(file),
OutputPath = new OsPath(file)

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using NzbDrone.Common.Disk;
@ -106,7 +106,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
// Avoid removing torrents that haven't reached the global max ratio.
// Removal also requires the torrent to be paused, in case a higher max ratio was set on the torrent itself (which is not exposed by the api).
item.IsReadOnly = (config.MaxRatioEnabled && config.MaxRatio > torrent.Ratio) || torrent.State != "pausedUP";
item.CanMoveFiles = item.CanBeRemoved = (!config.MaxRatioEnabled || config.MaxRatio <= torrent.Ratio) && torrent.State == "pausedUP";
if (!item.OutputPath.IsEmpty && item.OutputPath.FileName != torrent.Name)
{

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
@ -160,6 +160,8 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
else if (sabHistoryItem.Status == SabnzbdDownloadStatus.Completed)
{
historyItem.Status = DownloadItemStatus.Completed;
historyItem.CanBeRemoved = true;
historyItem.CanMoveFiles = true;
}
else // Verifying/Moving etc
{

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
@ -105,7 +105,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission
item.Status = DownloadItemStatus.Downloading;
}
item.IsReadOnly = torrent.Status != TransmissionTorrentStatus.Stopped;
item.CanMoveFiles = item.CanBeRemoved = torrent.Status == TransmissionTorrentStatus.Stopped;
items.Add(item);
}
@ -246,4 +246,4 @@ namespace NzbDrone.Core.Download.Clients.Transmission
return null;
}
}
}
}

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading;
@ -107,19 +107,31 @@ namespace NzbDrone.Core.Download.Clients.RTorrent
item.RemainingSize = torrent.RemainingSize;
item.Category = torrent.Category;
if (torrent.DownRate > 0) {
if (torrent.DownRate > 0)
{
var secondsLeft = torrent.RemainingSize / torrent.DownRate;
item.RemainingTime = TimeSpan.FromSeconds(secondsLeft);
} else {
}
else
{
item.RemainingTime = TimeSpan.Zero;
}
if (torrent.IsFinished) item.Status = DownloadItemStatus.Completed;
else if (torrent.IsActive) item.Status = DownloadItemStatus.Downloading;
else if (!torrent.IsActive) item.Status = DownloadItemStatus.Paused;
if (torrent.IsFinished)
{
item.Status = DownloadItemStatus.Completed;
}
else if (torrent.IsActive)
{
item.Status = DownloadItemStatus.Downloading;
}
else if (!torrent.IsActive)
{
item.Status = DownloadItemStatus.Paused;
}
// No stop ratio data is present, so do not delete
item.IsReadOnly = true;
item.CanMoveFiles = item.CanBeRemoved = false;
items.Add(item);
}

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using NzbDrone.Common.Disk;
@ -165,7 +165,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
}
// 'Started' without 'Queued' is when the torrent is 'forced seeding'
item.IsReadOnly = torrent.Status.HasFlag(UTorrentTorrentStatus.Queued) || torrent.Status.HasFlag(UTorrentTorrentStatus.Started);
item.CanMoveFiles = item.CanBeRemoved = (!torrent.Status.HasFlag(UTorrentTorrentStatus.Queued) && !torrent.Status.HasFlag(UTorrentTorrentStatus.Started));
queueItems.Add(item);
}

@ -25,8 +25,6 @@ namespace NzbDrone.Core.Download
public bool CanMoveFiles { get; set; }
public bool CanBeRemoved { get; set; }
public bool IsReadOnly { get; set; }
public bool Removed { get; set; }
}
}

@ -1,4 +1,4 @@
using System;
using System;
using NLog;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Configuration;
@ -37,7 +37,7 @@ namespace NzbDrone.Core.Download
{
if (!_configService.RemoveCompletedDownloads ||
message.TrackedDownload.DownloadItem.Removed ||
message.TrackedDownload.DownloadItem.IsReadOnly ||
!message.TrackedDownload.DownloadItem.CanBeRemoved ||
message.TrackedDownload.DownloadItem.Status == DownloadItemStatus.Downloading)
{
return;
@ -50,7 +50,7 @@ namespace NzbDrone.Core.Download
{
var trackedDownload = message.TrackedDownload;
if (trackedDownload == null || trackedDownload.DownloadItem.IsReadOnly || _configService.RemoveFailedDownloads == false)
if (trackedDownload == null || !trackedDownload.DownloadItem.CanBeRemoved || _configService.RemoveFailedDownloads == false)
{
return;
}
@ -78,4 +78,4 @@ namespace NzbDrone.Core.Download
}
}
}
}
}

@ -109,7 +109,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
private void RemoveCompletedDownloads(List<TrackedDownload> trackedDownloads)
{
foreach (var trackedDownload in trackedDownloads.Where(c => !c.DownloadItem.IsReadOnly && c.State == TrackedDownloadStage.Imported))
foreach (var trackedDownload in trackedDownloads.Where(c => c.DownloadItem.CanBeRemoved && c.State == TrackedDownloadStage.Imported))
{
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
}

@ -46,9 +46,7 @@ namespace NzbDrone.Core.Indexers
return new List<ReleaseInfo>();
}
var generator = GetRequestGenerator();
return FetchReleases(generator.GetRecentRequests(), true);
return FetchReleases(g => g.GetRecentRequests(), true);
}
public override IList<ReleaseInfo> Fetch(AlbumSearchCriteria searchCriteria)
@ -58,9 +56,7 @@ namespace NzbDrone.Core.Indexers
return new List<ReleaseInfo>();
}
var generator = GetRequestGenerator();
return FetchReleases(generator.GetSearchRequests(searchCriteria));
return FetchReleases(g => g.GetSearchRequests(searchCriteria));
}
public override IList<ReleaseInfo> Fetch(ArtistSearchCriteria searchCriteria)
@ -70,20 +66,22 @@ namespace NzbDrone.Core.Indexers
return new List<ReleaseInfo>();
}
var generator = GetRequestGenerator();
return FetchReleases(generator.GetSearchRequests(searchCriteria));
return FetchReleases(g => g.GetSearchRequests(searchCriteria));
}
protected virtual IList<ReleaseInfo> FetchReleases(IndexerPageableRequestChain pageableRequestChain, bool isRecent = false)
protected virtual IList<ReleaseInfo> FetchReleases(Func<IIndexerRequestGenerator, IndexerPageableRequestChain> pageableRequestChainSelector, bool isRecent = false)
{
var releases = new List<ReleaseInfo>();
var url = string.Empty;
var parser = GetParser();
try
{
var generator = GetRequestGenerator();
var parser = GetParser();
var pageableRequestChain = pageableRequestChainSelector(generator);
var fullyUpdated = false;
ReleaseInfo lastReleaseInfo = null;
if (isRecent)
@ -186,18 +184,22 @@ namespace NzbDrone.Core.Indexers
_logger.Warn("{0} {1} {2}", this, url, webException.Message);
}
}
catch (HttpException httpException)
catch (TooManyRequestsException ex)
{
if ((int)httpException.Response.StatusCode == 429)
if (ex.RetryAfter != TimeSpan.Zero)
{
_indexerStatusService.RecordFailure(Definition.Id, TimeSpan.FromHours(1));
_logger.Warn("API Request Limit reached for {0}", this);
_indexerStatusService.RecordFailure(Definition.Id, ex.RetryAfter);
}
else
{
_indexerStatusService.RecordFailure(Definition.Id);
_logger.Warn("{0} {1}", this, httpException.Message);
_indexerStatusService.RecordFailure(Definition.Id, TimeSpan.FromHours(1));
}
_logger.Warn("API Request Limit reached for {0}", this);
}
catch (HttpException ex)
{
_indexerStatusService.RecordFailure(Definition.Id);
_logger.Warn("{0} {1}", this, ex.Message);
}
catch (RequestLimitReachedException)
{

@ -199,7 +199,7 @@ namespace NzbDrone.Core.MediaFiles
var decisions = _importDecisionMaker.GetImportDecisions(audioFiles.ToList(), artist, trackInfo);
var importResults = _importApprovedTracks.Import(decisions, true, downloadClientItem, importMode);
if ((downloadClientItem == null || !downloadClientItem.IsReadOnly) &&
if ((downloadClientItem == null || downloadClientItem.CanMoveFiles) &&
importResults.Any(i => i.Result == ImportResultType.Imported) &&
ShouldDeleteFolder(directoryInfo, artist))
{

@ -1,4 +1,4 @@
using NzbDrone.Common.Messaging;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.Events
@ -10,7 +10,6 @@ namespace NzbDrone.Core.MediaFiles.Events
public bool NewDownload { get; private set; }
public string DownloadClient { get; private set; }
public string DownloadId { get; private set; }
public bool IsReadOnly { get; set; }
public EpisodeImportedEvent(LocalEpisode episodeInfo, EpisodeFile importedEpisode, bool newDownload)
{
@ -19,14 +18,13 @@ namespace NzbDrone.Core.MediaFiles.Events
NewDownload = newDownload;
}
public EpisodeImportedEvent(LocalEpisode episodeInfo, EpisodeFile importedEpisode, bool newDownload, string downloadClient, string downloadId, bool isReadOnly)
public EpisodeImportedEvent(LocalEpisode episodeInfo, EpisodeFile importedEpisode, bool newDownload, string downloadClient, string downloadId)
{
EpisodeInfo = episodeInfo;
ImportedEpisode = importedEpisode;
NewDownload = newDownload;
DownloadClient = downloadClient;
DownloadId = downloadId;
IsReadOnly = isReadOnly;
}
}
}
}

@ -1,4 +1,4 @@
using NzbDrone.Common.Messaging;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Parser.Model;
using System;
using System.Collections.Generic;
@ -14,7 +14,6 @@ namespace NzbDrone.Core.MediaFiles.Events
public bool NewDownload { get; private set; }
public string DownloadClient { get; private set; }
public string DownloadId { get; private set; }
public bool IsReadOnly { get; set; }
public TrackImportedEvent(LocalTrack trackInfo, TrackFile importedTrack, bool newDownload)
{
@ -23,14 +22,13 @@ namespace NzbDrone.Core.MediaFiles.Events
NewDownload = newDownload;
}
public TrackImportedEvent(LocalTrack trackInfo, TrackFile importedTrack, bool newDownload, string downloadClient, string downloadId, bool isReadOnly)
public TrackImportedEvent(LocalTrack trackInfo, TrackFile importedTrack, bool newDownload, string downloadClient, string downloadId)
{
TrackInfo = trackInfo;
ImportedTrack = importedTrack;
NewDownload = newDownload;
DownloadClient = downloadClient;
DownloadId = downloadId;
IsReadOnly = isReadOnly;
}
}
}

@ -94,7 +94,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
{
default:
case ImportMode.Auto:
copyOnly = downloadClientItem != null && downloadClientItem.IsReadOnly;
copyOnly = downloadClientItem != null && !downloadClientItem.CanMoveFiles;
break;
case ImportMode.Move:
copyOnly = false;
@ -126,7 +126,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
if (downloadClientItem != null)
{
_eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, newDownload, downloadClientItem.DownloadClient, downloadClientItem.DownloadId, downloadClientItem.IsReadOnly));
_eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, newDownload, downloadClientItem.DownloadClient, downloadClientItem.DownloadId));
}
else
{

@ -263,7 +263,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
{
if (_downloadedEpisodesImportService.ShouldDeleteFolder(
new DirectoryInfo(trackedDownload.DownloadItem.OutputPath.FullPath),
trackedDownload.RemoteAlbum.Artist) && !trackedDownload.DownloadItem.IsReadOnly)
trackedDownload.RemoteAlbum.Artist) && trackedDownload.DownloadItem.CanMoveFiles)
{
_diskProvider.DeleteFolder(trackedDownload.DownloadItem.OutputPath.FullPath, true);
}

Loading…
Cancel
Save