Blacklist is now used when processing results

pull/2/head
Mark McDowall 11 years ago
parent 71c0a340e7
commit 1f5bcfeb75

@ -3,6 +3,8 @@ using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.Clients.Sabnzbd;
using NzbDrone.Core.History;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
@ -64,6 +66,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_notupgradableQuality);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(_notupgradableQuality);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(3)).Returns<QualityModel>(null);
Mocker.GetMock<IProvideDownloadClient>()
.Setup(c => c.GetDownloadClient()).Returns(Mocker.GetMock<IDownloadClient>().Object);
}
private void WithFirstReportUpgradable()
@ -76,7 +81,6 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(_upgradableQuality);
}
[Test]
public void should_be_upgradable_if_only_episode_is_upgradable()
{
@ -129,5 +133,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, new SeasonSearchCriteria()).Should().BeTrue();
}
[Test]
public void should_return_true_if_using_sabnzbd()
{
Mocker.GetMock<IProvideDownloadClient>()
.Setup(c => c.GetDownloadClient()).Returns(Mocker.Resolve<SabnzbdClient>());
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, new SeasonSearchCriteria()).Should().BeTrue();
}
}
}

@ -0,0 +1,15 @@
using System;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Blacklisting
{
public class Blacklist : ModelBase
{
public int EpisodeId { get; set; }
public int SeriesId { get; set; }
public string SourceTitle { get; set; }
public QualityModel Quality { get; set; }
public DateTime Date { get; set; }
}
}

@ -0,0 +1,23 @@
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Blacklisting
{
public interface IBlacklistRepository : IBasicRepository<Blacklist>
{
bool Blacklisted(string sourceTitle);
}
public class BlacklistRepository : BasicRepository<Blacklist>, IBlacklistRepository
{
public BlacklistRepository(IDatabase database, IEventAggregator eventAggregator) :
base(database, eventAggregator)
{
}
public bool Blacklisted(string sourceTitle)
{
return Query.Any(e => e.SourceTitle == sourceTitle);
}
}
}

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Core.Download;
using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Blacklisting
{
public interface IBlacklistService
{
bool Blacklisted(string sourceTitle);
}
public class BlacklistService : IBlacklistService, IHandle<DownloadFailedEvent>
{
private readonly IBlacklistRepository _blacklistRepository;
public BlacklistService(IBlacklistRepository blacklistRepository)
{
_blacklistRepository = blacklistRepository;
}
public bool Blacklisted(string sourceTitle)
{
return _blacklistRepository.Blacklisted(sourceTitle);
}
public void Handle(DownloadFailedEvent message)
{
var blacklist = new Blacklist
{
SeriesId = message.Series.Id,
EpisodeId = message.Episode.Id,
SourceTitle = message.SourceTitle,
Quality = message.Quality,
Date = DateTime.UtcNow
};
_blacklistRepository.Insert(blacklist);
}
}
}

@ -0,0 +1,19 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(28)]
public class add_blacklist_table : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Create.TableForModel("Blacklist")
.WithColumn("SeriesId").AsInt32()
.WithColumn("EpisodeId").AsInt32()
.WithColumn("SourceTitle").AsString()
.WithColumn("Quality").AsString()
.WithColumn("Date").AsDateTime();
}
}
}

@ -4,6 +4,7 @@ using System.Linq;
using Marr.Data;
using Marr.Data.Mapping;
using NzbDrone.Common.Reflection;
using NzbDrone.Core.Blacklisting;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.DataAugmentation.Scene;
using NzbDrone.Core.Datastore.Converters;
@ -67,6 +68,8 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<NamingConfig>().RegisterModel("NamingConfig");
Mapper.Entity<SeriesStatistics>().MapResultSet();
Mapper.Entity<Blacklist>().RegisterModel("Blacklist");
}
private static void RegisterMappers()

@ -0,0 +1,39 @@
using System.Linq;
using NLog;
using NzbDrone.Core.Blacklisting;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications
{
public class BlacklistSpecification : IDecisionEngineSpecification
{
private readonly IBlacklistService _blacklistService;
private readonly Logger _logger;
public BlacklistSpecification(IBlacklistService blacklistService, Logger logger)
{
_blacklistService = blacklistService;
_logger = logger;
}
public string RejectionReason
{
get
{
return "Release is blacklisted";
}
}
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (_blacklistService.Blacklisted(subject.Release.Title))
{
_logger.Trace("Release is blacklisted");
return false;
}
return true;
}
}
}

@ -1,4 +1,6 @@
using NLog;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.Clients.Sabnzbd;
using NzbDrone.Core.History;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
@ -9,12 +11,17 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{
private readonly IHistoryService _historyService;
private readonly QualityUpgradableSpecification _qualityUpgradableSpecification;
private readonly IProvideDownloadClient _downloadClientProvider;
private readonly Logger _logger;
public UpgradeHistorySpecification(IHistoryService historyService, QualityUpgradableSpecification qualityUpgradableSpecification, Logger logger)
public UpgradeHistorySpecification(IHistoryService historyService,
QualityUpgradableSpecification qualityUpgradableSpecification,
IProvideDownloadClient downloadClientProvider,
Logger logger)
{
_historyService = historyService;
_qualityUpgradableSpecification = qualityUpgradableSpecification;
_downloadClientProvider = downloadClientProvider;
_logger = logger;
}
@ -34,6 +41,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
return true;
}
if (_downloadClientProvider.GetDownloadClient().GetType() == typeof (SabnzbdClient))
{
_logger.Trace("Skipping history check in favour of blacklist");
return true;
}
foreach (var episode in subject.Episodes)
{
var bestQualityInHistory = _historyService.GetBestQualityInHistory(episode.Id);

@ -23,7 +23,6 @@ namespace NzbDrone.Core.History
public Dictionary<string, string> Data { get; set; }
}
public enum HistoryEventType
{
Unknown = 0,
@ -32,5 +31,4 @@ namespace NzbDrone.Core.History
DownloadFolderImported = 3,
DownloadFailed = 4
}
}

@ -119,6 +119,9 @@
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Annotations\FieldDefinitionAttribute.cs" />
<Compile Include="Blacklisting\Blacklist.cs" />
<Compile Include="Blacklisting\BlacklistRepository.cs" />
<Compile Include="Blacklisting\BlacklistService.cs" />
<Compile Include="Configuration\Config.cs" />
<Compile Include="Configuration\ConfigFileProvider.cs" />
<Compile Include="Configuration\ConfigRepository.cs" />
@ -181,6 +184,7 @@
<Compile Include="Datastore\Migration\027_fix_omgwtfnzbs.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Datastore\Migration\028_add_blacklist_table.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />
@ -200,6 +204,7 @@
<Compile Include="Datastore\PagingSpecExtensions.cs" />
<Compile Include="Datastore\RelationshipExtensions.cs" />
<Compile Include="Datastore\TableMapping.cs" />
<Compile Include="DecisionEngine\Specifications\BlacklistSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\DownloadDecision.cs" />
<Compile Include="DecisionEngine\IRejectWithReason.cs" />
<Compile Include="DecisionEngine\IDecisionEngineSpecification.cs" />

Loading…
Cancel
Save