1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-26 09:49:00 +00:00

Added pre-search check for EpisodeSearch to see if an upgrade is possible, before attempting.

This commit is contained in:
Mark McDowall 2012-01-17 23:45:21 -08:00
parent d1262f1ced
commit 20c1639ada
9 changed files with 151 additions and 12 deletions

View file

@ -102,6 +102,7 @@
<Compile Include="JobTests\BacklogSearchJobTest.cs" />
<Compile Include="JobTests\BannerDownloadJobTest.cs" />
<Compile Include="JobTests\RecentBacklogSearchJobTest.cs" />
<Compile Include="ProviderTests\InventoryProviderTests\IsUpgradePossibleFixture.cs" />
<Compile Include="ProviderTests\MediaFileProviderTests\CleanUpDatabaseFixture.cs" />
<Compile Include="ProviderTests\ReferenceDataProviderTest.cs" />
<Compile Include="ProviderTests\NotificationProviderTests\NotificationProviderFixture.cs" />
@ -123,7 +124,7 @@
<Compile Include="ProviderTests\UpdateProviderTests\GetAvilableUpdateFixture.cs" />
<Compile Include="SortHelperTest.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\MisnamedProviderTest.cs" />
<Compile Include="JobTests\SeasonSearchJobTest.cs" />
@ -137,16 +138,16 @@
<Compile Include="FluentTest.cs" />
<Compile Include="ProviderTests\LogProviderTests\LogProviderFixture.cs" />
<Compile Include="ProviderTests\UpcomingEpisodesProviderTest.cs" />
<Compile Include="ProviderTests\MediaFileProvider_GetNewFilenameTest.cs" />
<Compile Include="ProviderTests\MediaFileProviderTests\GetNewFilenameFixture.cs" />
<Compile Include="dbBenchmark.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="EpisodeStatusTest.cs" />
<Compile Include="JobTests\ImportNewSeriesJobTest.cs" />
<Compile Include="JobTests\DiskScanJobTest.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="QualityTest.cs" />
<Compile Include="ProviderTests\RootDirProviderTest.cs" />

View file

@ -14,11 +14,11 @@
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests
namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class InventoryProvider_IsAcceptableSizeTest : CoreTest
public class IsAcceptableSizeTestFixture : CoreTest
{
private EpisodeParseResult parseResultMulti;
private EpisodeParseResult parseResultSingle;

View file

@ -14,11 +14,11 @@
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests
namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class InventoryProvider_IsMonitoredTest : CoreTest
public class IsMonitoredFixture : CoreTest
{
private EpisodeParseResult parseResultMulti;
private Series series;

View file

@ -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();
}
}
}

View file

@ -14,11 +14,11 @@
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests
namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class InventoryProvider_QualityNeededTest : CoreTest
public class QualityNeededFixture : CoreTest
{
private Episode episode;
private Episode episode2;

View file

@ -11,7 +11,7 @@
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests
namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming

View file

@ -192,6 +192,9 @@ public void EpisodeSearch_should_skip_if_air_date_is_null()
episode.AirDate = null;
episode.Series = _series;
Mocker.GetMock<InventoryProvider>().Setup(s => s.IsUpgradePossible(It.IsAny<Episode>()))
.Returns(true);
Mocker.GetMock<EpisodeProvider>().Setup(s => s.GetEpisode(episode.EpisodeId))
.Returns(episode);

View file

@ -15,17 +15,20 @@ public class InventoryProvider
private readonly EpisodeProvider _episodeProvider;
private readonly HistoryProvider _historyProvider;
private readonly QualityTypeProvider _qualityTypeProvider;
private readonly QualityProvider _qualityProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
[Inject]
public InventoryProvider(SeriesProvider seriesProvider, EpisodeProvider episodeProvider,
HistoryProvider historyProvider, QualityTypeProvider qualityTypeProvider)
HistoryProvider historyProvider, QualityTypeProvider qualityTypeProvider,
QualityProvider qualityProvider)
{
_seriesProvider = seriesProvider;
_episodeProvider = episodeProvider;
_historyProvider = historyProvider;
_qualityTypeProvider = qualityTypeProvider;
_qualityProvider = qualityProvider;
}
public InventoryProvider()
@ -179,5 +182,23 @@ public virtual bool IsAcceptableSize(EpisodeParseResult parseResult)
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;
}
}
}

View file

@ -129,6 +129,14 @@ public virtual bool EpisodeSearch(ProgressNotification notification, int episode
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;
if (episode.Series.IsDaily && !episode.AirDate.HasValue)