2013-04-07 10:30:37 +03:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2013-04-15 04:41:39 +03:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-04-07 10:30:37 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
|
|
|
{
|
2013-08-07 06:18:05 +03:00
|
|
|
public class DailyEpisodeMatchSpecification : IDecisionEngineSpecification
|
2013-04-07 10:30:37 +03:00
|
|
|
{
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly IEpisodeService _episodeService;
|
|
|
|
|
|
|
|
public DailyEpisodeMatchSpecification(Logger logger, IEpisodeService episodeService)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_episodeService = episodeService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string RejectionReason
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "Episode doesn't match";
|
|
|
|
}
|
|
|
|
}
|
2013-08-08 06:30:20 +03:00
|
|
|
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria)
|
2013-04-07 10:30:37 +03:00
|
|
|
{
|
2013-08-08 06:30:20 +03:00
|
|
|
if (searchCriteria == null)
|
2013-08-07 06:18:05 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-08 06:30:20 +03:00
|
|
|
var dailySearchSpec = searchCriteria as DailyEpisodeSearchCriteria;
|
2013-04-07 10:30:37 +03:00
|
|
|
|
|
|
|
if (dailySearchSpec == null) return true;
|
|
|
|
|
2013-09-15 06:49:58 +03:00
|
|
|
var episode = _episodeService.GetEpisode(dailySearchSpec.Series.Id, dailySearchSpec.Airtime);
|
2013-04-07 10:30:37 +03:00
|
|
|
|
2013-07-26 06:25:24 +03:00
|
|
|
if (!remoteEpisode.ParsedEpisodeInfo.AirDate.HasValue || remoteEpisode.ParsedEpisodeInfo.AirDate.Value.ToString(Episode.AIR_DATE_FORMAT) != episode.AirDate)
|
2013-04-07 10:30:37 +03:00
|
|
|
{
|
|
|
|
_logger.Trace("Episode AirDate does not match searched episode number, skipping.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|