2013-04-15 01:41:39 +00:00
|
|
|
using System.Linq;
|
2013-04-07 07:30:37 +00:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-04-07 07:30:37 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
|
|
|
{
|
2013-08-07 03:18:05 +00:00
|
|
|
public class SingleEpisodeSearchMatchSpecification : IDecisionEngineSpecification
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
public SingleEpisodeSearchMatchSpecification(Logger logger)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string RejectionReason
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "Episode doesn't match";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 03:30:20 +00:00
|
|
|
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
2013-08-08 03:30:20 +00:00
|
|
|
if (searchCriteria == null)
|
2013-08-07 03:18:05 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-08 03:30:20 +00:00
|
|
|
var singleEpisodeSpec = searchCriteria as SingleEpisodeSearchCriteria;
|
2013-04-07 07:30:37 +00:00
|
|
|
if (singleEpisodeSpec == null) return true;
|
|
|
|
|
2013-04-28 19:46:13 +00:00
|
|
|
if (singleEpisodeSpec.SeasonNumber != remoteEpisode.ParsedEpisodeInfo.SeasonNumber)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
|
|
|
_logger.Trace("Season number does not match searched season number, skipping.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-14 17:34:33 +00:00
|
|
|
if (!remoteEpisode.ParsedEpisodeInfo.EpisodeNumbers.Contains(singleEpisodeSpec.EpisodeNumber))
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
|
|
|
_logger.Trace("Episode number does not match searched episode number, skipping.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|