2013-03-06 16:19:49 -08:00
|
|
|
using System.Linq;
|
2012-02-06 21:08:07 -08:00
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Model;
|
2013-03-06 16:19:49 -08:00
|
|
|
using NzbDrone.Core.Tv;
|
2012-02-06 21:08:07 -08:00
|
|
|
|
2013-03-06 16:19:49 -08:00
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
2012-02-06 21:08:07 -08:00
|
|
|
{
|
2013-04-07 00:30:37 -07:00
|
|
|
public class MonitoredEpisodeSpecification : IDecisionEngineSpecification
|
2012-02-06 21:08:07 -08:00
|
|
|
{
|
2013-02-21 16:47:09 -08:00
|
|
|
private readonly IEpisodeService _episodeService;
|
2013-02-18 22:56:02 -08:00
|
|
|
private readonly ISeriesRepository _seriesRepository;
|
2013-03-06 16:19:49 -08:00
|
|
|
private readonly Logger _logger;
|
2012-02-06 21:08:07 -08:00
|
|
|
|
2013-03-06 16:19:49 -08:00
|
|
|
public MonitoredEpisodeSpecification(IEpisodeService episodeService, ISeriesRepository seriesRepository, Logger logger)
|
2012-02-06 21:08:07 -08:00
|
|
|
{
|
2013-02-19 18:05:15 -08:00
|
|
|
_episodeService = episodeService;
|
2013-02-18 22:56:02 -08:00
|
|
|
_seriesRepository = seriesRepository;
|
2013-03-06 16:19:49 -08:00
|
|
|
_logger = logger;
|
2012-02-06 21:08:07 -08:00
|
|
|
}
|
|
|
|
|
2013-03-06 16:19:49 -08:00
|
|
|
public string RejectionReason
|
2012-02-06 21:08:07 -08:00
|
|
|
{
|
2013-03-06 16:19:49 -08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return "Series is not monitored";
|
|
|
|
}
|
2012-02-06 21:08:07 -08:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:01:24 -07:00
|
|
|
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
2012-02-06 21:08:07 -08:00
|
|
|
{
|
2013-02-19 18:05:15 -08:00
|
|
|
var series = _seriesRepository.GetByTitle(subject.CleanTitle);
|
2012-02-06 21:08:07 -08:00
|
|
|
|
|
|
|
if (series == null)
|
|
|
|
{
|
2013-03-06 16:19:49 -08:00
|
|
|
_logger.Trace("{0} is not mapped to any series in DB. skipping", subject.CleanTitle);
|
2012-02-06 21:08:07 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
subject.Series = series;
|
|
|
|
|
|
|
|
if (!series.Monitored)
|
|
|
|
{
|
2013-03-06 16:19:49 -08:00
|
|
|
_logger.Debug("{0} is present in the DB but not tracked. skipping.", subject.CleanTitle);
|
2012-02-06 21:08:07 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-19 18:05:15 -08:00
|
|
|
var episodes = _episodeService.GetEpisodesByParseResult(subject);
|
2012-10-17 00:39:06 -07:00
|
|
|
subject.Episodes = episodes;
|
2012-02-06 21:08:07 -08:00
|
|
|
|
|
|
|
//return monitored if any of the episodes are monitored
|
|
|
|
if (episodes.Any(episode => !episode.Ignored))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-06 16:19:49 -08:00
|
|
|
_logger.Debug("All episodes are ignored. skipping.");
|
2012-02-06 21:08:07 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|