mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
renamed SearchDefinition to SearchCriteria
This commit is contained in:
parent
fe31476e47
commit
5d563f041e
@ -4,7 +4,7 @@
|
||||
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests
|
||||
{
|
||||
public class SearchDefinitionFixture : CoreTest<SingleEpisodeSearchDefinition>
|
||||
public class SearchDefinitionFixture : CoreTest<SingleEpisodeSearchCriteria>
|
||||
{
|
||||
[TestCase("Betty White's Off Their Rockers", Result = "Betty+Whites+Off+Their+Rockers")]
|
||||
[TestCase("Star Wars: The Clone Wars", Result = "Star+Wars+The+Clone+Wars")]
|
||||
|
@ -13,7 +13,7 @@ namespace NzbDrone.Core.DecisionEngine
|
||||
public interface IMakeDownloadDecision
|
||||
{
|
||||
List<DownloadDecision> GetRssDecision(IEnumerable<ReportInfo> reports);
|
||||
List<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchDefinitionBase searchDefinitionBase);
|
||||
List<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchCriteriaBase searchCriteriaBase);
|
||||
}
|
||||
|
||||
public class DownloadDecisionMaker : IMakeDownloadDecision
|
||||
@ -34,12 +34,12 @@ public List<DownloadDecision> GetRssDecision(IEnumerable<ReportInfo> reports)
|
||||
return GetDecisions(reports).ToList();
|
||||
}
|
||||
|
||||
public List<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchDefinitionBase searchDefinitionBase)
|
||||
public List<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchCriteriaBase searchCriteriaBase)
|
||||
{
|
||||
return GetDecisions(reports).ToList();
|
||||
}
|
||||
|
||||
private IEnumerable<DownloadDecision> GetDecisions(IEnumerable<ReportInfo> reports, SearchDefinitionBase searchDefinition = null)
|
||||
private IEnumerable<DownloadDecision> GetDecisions(IEnumerable<ReportInfo> reports, SearchCriteriaBase searchCriteria = null)
|
||||
{
|
||||
foreach (var report in reports)
|
||||
{
|
||||
@ -56,7 +56,7 @@ private IEnumerable<DownloadDecision> GetDecisions(IEnumerable<ReportInfo> repor
|
||||
|
||||
if (remoteEpisode.Series != null)
|
||||
{
|
||||
decision = GetDecisionForReport(remoteEpisode, searchDefinition);
|
||||
decision = GetDecisionForReport(remoteEpisode, searchCriteria);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -77,15 +77,15 @@ private IEnumerable<DownloadDecision> GetDecisions(IEnumerable<ReportInfo> repor
|
||||
|
||||
}
|
||||
|
||||
private DownloadDecision GetDecisionForReport(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinition = null)
|
||||
private DownloadDecision GetDecisionForReport(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria = null)
|
||||
{
|
||||
var reasons = _specifications.Select(c => EvaluateSpec(c, remoteEpisode, searchDefinition))
|
||||
var reasons = _specifications.Select(c => EvaluateSpec(c, remoteEpisode, searchCriteria))
|
||||
.Where(c => !string.IsNullOrWhiteSpace(c));
|
||||
|
||||
return new DownloadDecision(remoteEpisode, reasons.ToArray());
|
||||
}
|
||||
|
||||
private string EvaluateSpec(IRejectWithReason spec, RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase = null)
|
||||
private string EvaluateSpec(IRejectWithReason spec, RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteriaBase = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -95,9 +95,9 @@ private string EvaluateSpec(IRejectWithReason spec, RemoteEpisode remoteEpisode,
|
||||
}
|
||||
|
||||
var searchSpecification = spec as IDecisionEngineSearchSpecification;
|
||||
if (searchSpecification != null && searchDefinitionBase != null)
|
||||
if (searchSpecification != null && searchCriteriaBase != null)
|
||||
{
|
||||
if (!searchSpecification.IsSatisfiedBy(remoteEpisode, searchDefinitionBase))
|
||||
if (!searchSpecification.IsSatisfiedBy(remoteEpisode, searchCriteriaBase))
|
||||
{
|
||||
return spec.RejectionReason;
|
||||
}
|
||||
@ -113,7 +113,7 @@ private string EvaluateSpec(IRejectWithReason spec, RemoteEpisode remoteEpisode,
|
||||
{
|
||||
e.Data.Add("report", remoteEpisode.Report.ToJson());
|
||||
e.Data.Add("parsed", remoteEpisode.ParsedEpisodeInfo.ToJson());
|
||||
_logger.ErrorException("Couldn't evaluate decision", e);
|
||||
_logger.ErrorException("Couldn't evaluate decision on " + remoteEpisode.Report.Title, e);
|
||||
return string.Format("{0}: {1}", spec.GetType().Name, e.Message);
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,9 @@ public string RejectionReason
|
||||
return "Episode doesn't match";
|
||||
}
|
||||
}
|
||||
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase)
|
||||
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteriaBase)
|
||||
{
|
||||
var dailySearchSpec = searchDefinitionBase as DailyEpisodeSearchDefinition;
|
||||
var dailySearchSpec = searchCriteriaBase as DailyEpisodeSearchCriteria;
|
||||
|
||||
if (dailySearchSpec == null) return true;
|
||||
|
||||
|
@ -8,6 +8,6 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
||||
{
|
||||
public interface IDecisionEngineSearchSpecification : IRejectWithReason
|
||||
{
|
||||
bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase);
|
||||
bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteriaBase);
|
||||
}
|
||||
}
|
@ -21,9 +21,9 @@ public string RejectionReason
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase)
|
||||
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteriaBase)
|
||||
{
|
||||
var singleEpisodeSpec = searchDefinitionBase as SeasonSearchDefinition;
|
||||
var singleEpisodeSpec = searchCriteriaBase as SeasonSearchCriteria;
|
||||
if (singleEpisodeSpec == null) return true;
|
||||
|
||||
if (singleEpisodeSpec.SeasonNumber != remoteEpisode.ParsedEpisodeInfo.SeasonNumber)
|
||||
|
@ -22,9 +22,9 @@ public string RejectionReason
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase)
|
||||
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteriaBase)
|
||||
{
|
||||
var singleEpisodeSpec = searchDefinitionBase as SingleEpisodeSearchDefinition;
|
||||
var singleEpisodeSpec = searchCriteriaBase as SingleEpisodeSearchCriteria;
|
||||
if (singleEpisodeSpec == null) return true;
|
||||
|
||||
if (singleEpisodeSpec.SeasonNumber != remoteEpisode.ParsedEpisodeInfo.SeasonNumber)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace NzbDrone.Core.IndexerSearch.Definitions
|
||||
{
|
||||
public class DailyEpisodeSearchDefinition : SearchDefinitionBase
|
||||
public class DailyEpisodeSearchCriteria : SearchCriteriaBase
|
||||
{
|
||||
public DateTime Airtime { get; set; }
|
||||
|
@ -1,10 +1,10 @@
|
||||
namespace NzbDrone.Core.IndexerSearch.Definitions
|
||||
{
|
||||
public class PartialSeasonSearchDefinition : SeasonSearchDefinition
|
||||
public class PartialSeasonSearchCriteria : SeasonSearchCriteria
|
||||
{
|
||||
public int Prefix { get; set; }
|
||||
|
||||
public PartialSeasonSearchDefinition(SeasonSearchDefinition seasonSearch, int prefix)
|
||||
public PartialSeasonSearchCriteria(SeasonSearchCriteria seasonSearch, int prefix)
|
||||
{
|
||||
Prefix = prefix;
|
||||
SceneTitle = seasonSearch.SceneTitle;
|
@ -3,7 +3,7 @@
|
||||
|
||||
namespace NzbDrone.Core.IndexerSearch.Definitions
|
||||
{
|
||||
public abstract class SearchDefinitionBase
|
||||
public abstract class SearchCriteriaBase
|
||||
{
|
||||
private static readonly Regex NoneWord = new Regex(@"[\W]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
private static readonly Regex BeginningThe = new Regex(@"^the\s", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
@ -1,6 +1,6 @@
|
||||
namespace NzbDrone.Core.IndexerSearch.Definitions
|
||||
{
|
||||
public class SeasonSearchDefinition : SearchDefinitionBase
|
||||
public class SeasonSearchCriteria : SearchCriteriaBase
|
||||
{
|
||||
public int SeasonNumber { get; set; }
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace NzbDrone.Core.IndexerSearch.Definitions
|
||||
{
|
||||
public class SingleEpisodeSearchDefinition : SearchDefinitionBase
|
||||
public class SingleEpisodeSearchCriteria : SearchCriteriaBase
|
||||
{
|
||||
//TODO make sure these are populated with scene if required
|
||||
public int EpisodeNumber { get; set; }
|
@ -42,7 +42,7 @@ public NzbSearchService(IIndexerService indexerService, IFetchFeedFromIndexers f
|
||||
|
||||
public List<DownloadDecision> SearchSingle(int seriesId, int seasonNumber, int episodeNumber)
|
||||
{
|
||||
var searchSpec = Get<SingleEpisodeSearchDefinition>(seriesId, seasonNumber);
|
||||
var searchSpec = Get<SingleEpisodeSearchCriteria>(seriesId, seasonNumber);
|
||||
|
||||
if (_seriesService.GetSeries(seriesId).UseSceneNumbering)
|
||||
{
|
||||
@ -61,7 +61,7 @@ public List<DownloadDecision> SearchSingle(int seriesId, int seasonNumber, int e
|
||||
|
||||
public List<DownloadDecision> SearchDaily(int seriesId, DateTime airDate)
|
||||
{
|
||||
var searchSpec = Get<DailyEpisodeSearchDefinition>(seriesId);
|
||||
var searchSpec = Get<DailyEpisodeSearchCriteria>(seriesId);
|
||||
searchSpec.Airtime = airDate;
|
||||
|
||||
return Dispatch(indexer => _feedFetcher.Fetch(indexer, searchSpec), searchSpec);
|
||||
@ -69,19 +69,19 @@ public List<DownloadDecision> SearchDaily(int seriesId, DateTime airDate)
|
||||
|
||||
public List<DownloadDecision> SearchSeason(int seriesId, int seasonNumber)
|
||||
{
|
||||
var searchSpec = Get<SeasonSearchDefinition>(seriesId, seasonNumber);
|
||||
var searchSpec = Get<SeasonSearchCriteria>(seriesId, seasonNumber);
|
||||
searchSpec.SeasonNumber = seasonNumber;
|
||||
|
||||
return Dispatch(indexer => _feedFetcher.Fetch(indexer, searchSpec), searchSpec);
|
||||
}
|
||||
|
||||
private List<DownloadDecision> PartialSeasonSearch(SeasonSearchDefinition search)
|
||||
private List<DownloadDecision> PartialSeasonSearch(SeasonSearchCriteria search)
|
||||
{
|
||||
var episodesNumbers = _episodeService.GetEpisodesBySeason(search.SeriesId, search.SeasonNumber).Select(c => c.EpisodeNumber);
|
||||
var prefixes = episodesNumbers
|
||||
.Select(i => i / 10)
|
||||
.Distinct()
|
||||
.Select(prefix => new PartialSeasonSearchDefinition(search, prefix));
|
||||
.Select(prefix => new PartialSeasonSearchCriteria(search, prefix));
|
||||
|
||||
var result = new List<DownloadDecision>();
|
||||
|
||||
@ -95,7 +95,7 @@ private List<DownloadDecision> PartialSeasonSearch(SeasonSearchDefinition search
|
||||
return result;
|
||||
}
|
||||
|
||||
private TSpec Get<TSpec>(int seriesId, int seasonNumber = -1) where TSpec : SearchDefinitionBase, new()
|
||||
private TSpec Get<TSpec>(int seriesId, int seasonNumber = -1) where TSpec : SearchCriteriaBase, new()
|
||||
{
|
||||
var spec = new TSpec();
|
||||
|
||||
@ -107,7 +107,7 @@ private List<DownloadDecision> PartialSeasonSearch(SeasonSearchDefinition search
|
||||
return spec;
|
||||
}
|
||||
|
||||
private List<DownloadDecision> Dispatch(Func<IIndexer, IEnumerable<ReportInfo>> searchAction, SearchDefinitionBase definitionBase)
|
||||
private List<DownloadDecision> Dispatch(Func<IIndexer, IEnumerable<ReportInfo>> searchAction, SearchCriteriaBase criteriaBase)
|
||||
{
|
||||
var indexers = _indexerService.GetAvailableIndexers().ToList();
|
||||
var reports = new List<ReportInfo>();
|
||||
@ -133,16 +133,16 @@ private List<DownloadDecision> Dispatch(Func<IIndexer, IEnumerable<ReportInfo>>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("Error while searching for " + definitionBase, e);
|
||||
_logger.ErrorException("Error while searching for " + criteriaBase, e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Task.WaitAll(taskList.ToArray());
|
||||
|
||||
_logger.Debug("Total of {0} reports were found for {1} in {2} indexers", reports.Count, definitionBase, indexers.Count);
|
||||
_logger.Debug("Total of {0} reports were found for {1} in {2} indexers", reports.Count, criteriaBase, indexers.Count);
|
||||
|
||||
return _makeDownloadDecision.GetSearchDecision(reports, definitionBase).ToList();
|
||||
return _makeDownloadDecision.GetSearchDecision(reports, criteriaBase).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -14,10 +14,10 @@ public interface IFetchFeedFromIndexers
|
||||
{
|
||||
IList<ReportInfo> FetchRss(IIndexer indexer);
|
||||
|
||||
IList<ReportInfo> Fetch(IIndexer indexer, SeasonSearchDefinition searchDefinition);
|
||||
IList<ReportInfo> Fetch(IIndexer indexer, SingleEpisodeSearchDefinition searchDefinition);
|
||||
IList<ReportInfo> Fetch(IIndexer indexer, PartialSeasonSearchDefinition searchDefinition);
|
||||
IList<ReportInfo> Fetch(IIndexer indexer, DailyEpisodeSearchDefinition searchDefinition);
|
||||
IList<ReportInfo> Fetch(IIndexer indexer, SeasonSearchCriteria searchCriteria);
|
||||
IList<ReportInfo> Fetch(IIndexer indexer, SingleEpisodeSearchCriteria searchCriteria);
|
||||
IList<ReportInfo> Fetch(IIndexer indexer, PartialSeasonSearchCriteria searchCriteria);
|
||||
IList<ReportInfo> Fetch(IIndexer indexer, DailyEpisodeSearchCriteria searchCriteria);
|
||||
}
|
||||
|
||||
public class FetchFeedService : IFetchFeedFromIndexers
|
||||
@ -44,51 +44,51 @@ public virtual IList<ReportInfo> FetchRss(IIndexer indexer)
|
||||
return result;
|
||||
}
|
||||
|
||||
public IList<ReportInfo> Fetch(IIndexer indexer, SeasonSearchDefinition searchDefinition)
|
||||
public IList<ReportInfo> Fetch(IIndexer indexer, SeasonSearchCriteria searchCriteria)
|
||||
{
|
||||
_logger.Debug("Searching for {0}", searchDefinition);
|
||||
_logger.Debug("Searching for {0}", searchCriteria);
|
||||
|
||||
var searchUrls = indexer.GetSeasonSearchUrls(searchDefinition.SceneTitle, searchDefinition.SeasonNumber);
|
||||
var searchUrls = indexer.GetSeasonSearchUrls(searchCriteria.SceneTitle, searchCriteria.SeasonNumber);
|
||||
var result = Fetch(indexer, searchUrls);
|
||||
|
||||
|
||||
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchDefinition, result.Count);
|
||||
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
|
||||
return result;
|
||||
}
|
||||
|
||||
public IList<ReportInfo> Fetch(IIndexer indexer, SingleEpisodeSearchDefinition searchDefinition)
|
||||
public IList<ReportInfo> Fetch(IIndexer indexer, SingleEpisodeSearchCriteria searchCriteria)
|
||||
{
|
||||
_logger.Debug("Searching for {0}", searchDefinition);
|
||||
_logger.Debug("Searching for {0}", searchCriteria);
|
||||
|
||||
var searchUrls = indexer.GetEpisodeSearchUrls(searchDefinition.SceneTitle, searchDefinition.SeasonNumber, searchDefinition.EpisodeNumber);
|
||||
var searchUrls = indexer.GetEpisodeSearchUrls(searchCriteria.SceneTitle, searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber);
|
||||
var result = Fetch(indexer, searchUrls);
|
||||
|
||||
|
||||
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchDefinition, result.Count);
|
||||
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public IList<ReportInfo> Fetch(IIndexer indexer, PartialSeasonSearchDefinition searchDefinition)
|
||||
public IList<ReportInfo> Fetch(IIndexer indexer, PartialSeasonSearchCriteria searchCriteria)
|
||||
{
|
||||
_logger.Debug("Searching for {0}", searchDefinition);
|
||||
_logger.Debug("Searching for {0}", searchCriteria);
|
||||
|
||||
var searchUrls = indexer.GetSeasonSearchUrls(searchDefinition.SceneTitle, searchDefinition.SeasonNumber);
|
||||
var searchUrls = indexer.GetSeasonSearchUrls(searchCriteria.SceneTitle, searchCriteria.SeasonNumber);
|
||||
var result = Fetch(indexer, searchUrls);
|
||||
|
||||
|
||||
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchDefinition, result.Count);
|
||||
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
|
||||
return result;
|
||||
}
|
||||
|
||||
public IList<ReportInfo> Fetch(IIndexer indexer, DailyEpisodeSearchDefinition searchDefinition)
|
||||
public IList<ReportInfo> Fetch(IIndexer indexer, DailyEpisodeSearchCriteria searchCriteria)
|
||||
{
|
||||
_logger.Debug("Searching for {0}", searchDefinition);
|
||||
_logger.Debug("Searching for {0}", searchCriteria);
|
||||
|
||||
var searchUrls = indexer.GetDailyEpisodeSearchUrls(searchDefinition.SceneTitle, searchDefinition.Airtime);
|
||||
var searchUrls = indexer.GetDailyEpisodeSearchUrls(searchCriteria.SceneTitle, searchCriteria.Airtime);
|
||||
var result = Fetch(indexer, searchUrls);
|
||||
|
||||
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchDefinition, result.Count);
|
||||
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -270,11 +270,11 @@
|
||||
<Compile Include="Fluent.cs" />
|
||||
<Compile Include="Helpers\SortHelper.cs" />
|
||||
<Compile Include="History\HistoryRepository.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\DailyEpisodeSearchDefinition.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\PartialSeasonSearchDefinition.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\SearchDefinitionBase.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\SeasonSearchDefinition.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\SingleEpisodeSearchDefinition.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\DailyEpisodeSearchCriteria.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\PartialSeasonSearchCriteria.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\SearchCriteriaBase.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\SeasonSearchCriteria.cs" />
|
||||
<Compile Include="IndexerSearch\Definitions\SingleEpisodeSearchCriteria.cs" />
|
||||
<Compile Include="IndexerSearch\NzbSearchService.cs" />
|
||||
<Compile Include="IndexerSearch\SearchAndDownloadService.cs" />
|
||||
<Compile Include="Indexers\BasicRssParser.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user