Added pre-search check for EpisodeSearch to see if an upgrade is possible, before attempting.
This commit is contained in:
parent
d1262f1ced
commit
20c1639ada
|
@ -102,6 +102,7 @@
|
||||||
<Compile Include="JobTests\BacklogSearchJobTest.cs" />
|
<Compile Include="JobTests\BacklogSearchJobTest.cs" />
|
||||||
<Compile Include="JobTests\BannerDownloadJobTest.cs" />
|
<Compile Include="JobTests\BannerDownloadJobTest.cs" />
|
||||||
<Compile Include="JobTests\RecentBacklogSearchJobTest.cs" />
|
<Compile Include="JobTests\RecentBacklogSearchJobTest.cs" />
|
||||||
|
<Compile Include="ProviderTests\InventoryProviderTests\IsUpgradePossibleFixture.cs" />
|
||||||
<Compile Include="ProviderTests\MediaFileProviderTests\CleanUpDatabaseFixture.cs" />
|
<Compile Include="ProviderTests\MediaFileProviderTests\CleanUpDatabaseFixture.cs" />
|
||||||
<Compile Include="ProviderTests\ReferenceDataProviderTest.cs" />
|
<Compile Include="ProviderTests\ReferenceDataProviderTest.cs" />
|
||||||
<Compile Include="ProviderTests\NotificationProviderTests\NotificationProviderFixture.cs" />
|
<Compile Include="ProviderTests\NotificationProviderTests\NotificationProviderFixture.cs" />
|
||||||
|
@ -123,7 +124,7 @@
|
||||||
<Compile Include="ProviderTests\UpdateProviderTests\GetAvilableUpdateFixture.cs" />
|
<Compile Include="ProviderTests\UpdateProviderTests\GetAvilableUpdateFixture.cs" />
|
||||||
<Compile Include="SortHelperTest.cs" />
|
<Compile Include="SortHelperTest.cs" />
|
||||||
<Compile Include="ProviderTests\EpisodeProviderTest_DeleteInvalidEpisodes.cs" />
|
<Compile Include="ProviderTests\EpisodeProviderTest_DeleteInvalidEpisodes.cs" />
|
||||||
<Compile Include="ProviderTests\InventoryProvider_IsAcceptableSizeTest.cs" />
|
<Compile Include="ProviderTests\InventoryProviderTests\IsAcceptableSizeTestFixture.cs" />
|
||||||
<Compile Include="ProviderTests\QualityTypeProviderTest.cs" />
|
<Compile Include="ProviderTests\QualityTypeProviderTest.cs" />
|
||||||
<Compile Include="ProviderTests\MisnamedProviderTest.cs" />
|
<Compile Include="ProviderTests\MisnamedProviderTest.cs" />
|
||||||
<Compile Include="JobTests\SeasonSearchJobTest.cs" />
|
<Compile Include="JobTests\SeasonSearchJobTest.cs" />
|
||||||
|
@ -137,16 +138,16 @@
|
||||||
<Compile Include="FluentTest.cs" />
|
<Compile Include="FluentTest.cs" />
|
||||||
<Compile Include="ProviderTests\LogProviderTests\LogProviderFixture.cs" />
|
<Compile Include="ProviderTests\LogProviderTests\LogProviderFixture.cs" />
|
||||||
<Compile Include="ProviderTests\UpcomingEpisodesProviderTest.cs" />
|
<Compile Include="ProviderTests\UpcomingEpisodesProviderTest.cs" />
|
||||||
<Compile Include="ProviderTests\MediaFileProvider_GetNewFilenameTest.cs" />
|
<Compile Include="ProviderTests\MediaFileProviderTests\GetNewFilenameFixture.cs" />
|
||||||
<Compile Include="dbBenchmark.cs" />
|
<Compile Include="dbBenchmark.cs" />
|
||||||
<Compile Include="Framework\CoreTest.cs" />
|
<Compile Include="Framework\CoreTest.cs" />
|
||||||
<Compile Include="ProviderTests\InventoryProvider_IsMonitoredTest.cs" />
|
<Compile Include="ProviderTests\InventoryProviderTests\IsMonitoredFixture.cs" />
|
||||||
<Compile Include="ProviderTests\DownloadProviderTest.cs" />
|
<Compile Include="ProviderTests\DownloadProviderTest.cs" />
|
||||||
<Compile Include="EpisodeStatusTest.cs" />
|
<Compile Include="EpisodeStatusTest.cs" />
|
||||||
<Compile Include="JobTests\ImportNewSeriesJobTest.cs" />
|
<Compile Include="JobTests\ImportNewSeriesJobTest.cs" />
|
||||||
<Compile Include="JobTests\DiskScanJobTest.cs" />
|
<Compile Include="JobTests\DiskScanJobTest.cs" />
|
||||||
<Compile Include="IndexerTests.cs" />
|
<Compile Include="IndexerTests.cs" />
|
||||||
<Compile Include="ProviderTests\InventoryProvider_QualityNeededTest.cs" />
|
<Compile Include="ProviderTests\InventoryProviderTests\QualityNeededFixture.cs" />
|
||||||
<Compile Include="ProviderTests\JobProviderTests\JobProviderFixture.cs" />
|
<Compile Include="ProviderTests\JobProviderTests\JobProviderFixture.cs" />
|
||||||
<Compile Include="QualityTest.cs" />
|
<Compile Include="QualityTest.cs" />
|
||||||
<Compile Include="ProviderTests\RootDirProviderTest.cs" />
|
<Compile Include="ProviderTests\RootDirProviderTest.cs" />
|
||||||
|
|
|
@ -14,11 +14,11 @@ using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common.AutoMoq;
|
using NzbDrone.Test.Common.AutoMoq;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class InventoryProvider_IsAcceptableSizeTest : CoreTest
|
public class IsAcceptableSizeTestFixture : CoreTest
|
||||||
{
|
{
|
||||||
private EpisodeParseResult parseResultMulti;
|
private EpisodeParseResult parseResultMulti;
|
||||||
private EpisodeParseResult parseResultSingle;
|
private EpisodeParseResult parseResultSingle;
|
|
@ -14,11 +14,11 @@ using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common.AutoMoq;
|
using NzbDrone.Test.Common.AutoMoq;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class InventoryProvider_IsMonitoredTest : CoreTest
|
public class IsMonitoredFixture : CoreTest
|
||||||
{
|
{
|
||||||
private EpisodeParseResult parseResultMulti;
|
private EpisodeParseResult parseResultMulti;
|
||||||
private Series series;
|
private Series series;
|
|
@ -0,0 +1,106 @@
|
||||||
|
// ReSharper disable RedundantUsingDirective
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Model;
|
||||||
|
using NzbDrone.Core.Providers;
|
||||||
|
using NzbDrone.Core.Repository;
|
||||||
|
using NzbDrone.Core.Repository.Quality;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common.AutoMoq;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
public class IsUpgradePossibleFixture : CoreTest
|
||||||
|
{
|
||||||
|
private void WithWebdlCutoff()
|
||||||
|
{
|
||||||
|
var profile = new QualityProfile { Cutoff = QualityTypes.WEBDL };
|
||||||
|
Mocker.GetMock<QualityProvider>().Setup(s => s.Get(It.IsAny<int>())).Returns(profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Series _series;
|
||||||
|
private EpisodeFile _episodeFile;
|
||||||
|
private Episode _episode;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
_series = Builder<Series>.CreateNew()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_episodeFile = Builder<EpisodeFile>.CreateNew()
|
||||||
|
.With(f => f.Quality = QualityTypes.SDTV)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_episode = Builder<Episode>.CreateNew()
|
||||||
|
.With(e => e.EpisodeFileId = 0)
|
||||||
|
.With(e => e.SeriesId = _series.SeriesId)
|
||||||
|
.With(e => e.Series = _series)
|
||||||
|
.With(e => e.EpisodeFileId = _episodeFile.EpisodeFileId)
|
||||||
|
.With(e => e.EpisodeFile = _episodeFile)
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IsUpgradePossible_should_return_true_if_no_episode_file_exists()
|
||||||
|
{
|
||||||
|
var episode = Builder<Episode>.CreateNew()
|
||||||
|
.With(e => e.EpisodeFileId = 0)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
//Act
|
||||||
|
bool result = Mocker.Resolve<InventoryProvider>().IsUpgradePossible(episode);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IsUpgradePossible_should_return_true_if_current_episode_is_less_than_cutoff()
|
||||||
|
{
|
||||||
|
WithWebdlCutoff();
|
||||||
|
|
||||||
|
//Act
|
||||||
|
bool result = Mocker.Resolve<InventoryProvider>().IsUpgradePossible(_episode);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IsUpgradePossible_should_return_false_if_current_episode_is_equal_to_cutoff()
|
||||||
|
{
|
||||||
|
WithWebdlCutoff();
|
||||||
|
|
||||||
|
_episodeFile.Quality = QualityTypes.WEBDL;
|
||||||
|
|
||||||
|
//Act
|
||||||
|
bool result = Mocker.Resolve<InventoryProvider>().IsUpgradePossible(_episode);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
result.Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IsUpgradePossible_should_return_false_if_current_episode_is_greater_than_cutoff()
|
||||||
|
{
|
||||||
|
WithWebdlCutoff();
|
||||||
|
|
||||||
|
_episodeFile.Quality = QualityTypes.Bluray720p;
|
||||||
|
|
||||||
|
//Act
|
||||||
|
bool result = Mocker.Resolve<InventoryProvider>().IsUpgradePossible(_episode);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
result.Should().BeFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,11 +14,11 @@ using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common.AutoMoq;
|
using NzbDrone.Test.Common.AutoMoq;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class InventoryProvider_QualityNeededTest : CoreTest
|
public class QualityNeededFixture : CoreTest
|
||||||
{
|
{
|
||||||
private Episode episode;
|
private Episode episode;
|
||||||
private Episode episode2;
|
private Episode episode2;
|
|
@ -11,7 +11,7 @@ using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common.AutoMoq;
|
using NzbDrone.Test.Common.AutoMoq;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
|
@ -192,6 +192,9 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
|
||||||
episode.AirDate = null;
|
episode.AirDate = null;
|
||||||
episode.Series = _series;
|
episode.Series = _series;
|
||||||
|
|
||||||
|
Mocker.GetMock<InventoryProvider>().Setup(s => s.IsUpgradePossible(It.IsAny<Episode>()))
|
||||||
|
.Returns(true);
|
||||||
|
|
||||||
Mocker.GetMock<EpisodeProvider>().Setup(s => s.GetEpisode(episode.EpisodeId))
|
Mocker.GetMock<EpisodeProvider>().Setup(s => s.GetEpisode(episode.EpisodeId))
|
||||||
.Returns(episode);
|
.Returns(episode);
|
||||||
|
|
||||||
|
|
|
@ -15,17 +15,20 @@ namespace NzbDrone.Core.Providers
|
||||||
private readonly EpisodeProvider _episodeProvider;
|
private readonly EpisodeProvider _episodeProvider;
|
||||||
private readonly HistoryProvider _historyProvider;
|
private readonly HistoryProvider _historyProvider;
|
||||||
private readonly QualityTypeProvider _qualityTypeProvider;
|
private readonly QualityTypeProvider _qualityTypeProvider;
|
||||||
|
private readonly QualityProvider _qualityProvider;
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
public InventoryProvider(SeriesProvider seriesProvider, EpisodeProvider episodeProvider,
|
public InventoryProvider(SeriesProvider seriesProvider, EpisodeProvider episodeProvider,
|
||||||
HistoryProvider historyProvider, QualityTypeProvider qualityTypeProvider)
|
HistoryProvider historyProvider, QualityTypeProvider qualityTypeProvider,
|
||||||
|
QualityProvider qualityProvider)
|
||||||
{
|
{
|
||||||
_seriesProvider = seriesProvider;
|
_seriesProvider = seriesProvider;
|
||||||
_episodeProvider = episodeProvider;
|
_episodeProvider = episodeProvider;
|
||||||
_historyProvider = historyProvider;
|
_historyProvider = historyProvider;
|
||||||
_qualityTypeProvider = qualityTypeProvider;
|
_qualityTypeProvider = qualityTypeProvider;
|
||||||
|
_qualityProvider = qualityProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryProvider()
|
public InventoryProvider()
|
||||||
|
@ -179,5 +182,23 @@ namespace NzbDrone.Core.Providers
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool IsUpgradePossible(Episode episode)
|
||||||
|
{
|
||||||
|
//Used to check if the existing episode can be upgraded by searching (Before we search)
|
||||||
|
|
||||||
|
//If no episode file exists on disk, then an upgrade is possible
|
||||||
|
if (episode.EpisodeFileId == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
//Get the quality profile for the series
|
||||||
|
var profile = _qualityProvider.Get(episode.Series.QualityProfileId);
|
||||||
|
|
||||||
|
//If the current episode file meets or exceeds the cutoff, do not attempt upgrade
|
||||||
|
if (episode.EpisodeFile.Quality >= profile.Cutoff)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -129,6 +129,14 @@ namespace NzbDrone.Core.Providers
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Check to see if an upgrade is possible before attempting
|
||||||
|
if (!_inventoryProvider.IsUpgradePossible(episode))
|
||||||
|
{
|
||||||
|
Logger.Info("Search for {0} was aborted, file in disk meets or exceeds Profile's Cutoff", episode);
|
||||||
|
notification.CurrentMessage = String.Format("Aborting search for {0}, Upgrade is not possible", episode);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
notification.CurrentMessage = "Searching for " + episode;
|
notification.CurrentMessage = "Searching for " + episode;
|
||||||
|
|
||||||
if (episode.Series.IsDaily && !episode.AirDate.HasValue)
|
if (episode.Series.IsDaily && !episode.AirDate.HasValue)
|
||||||
|
|
Loading…
Reference in New Issue