2012-02-07 05:08:07 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
using NzbDrone.Core.Model;
|
2013-02-19 02:19:38 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
2013-02-19 02:19:38 +00:00
|
|
|
|
namespace NzbDrone.Core.DecisionEngine
|
2012-02-07 05:08:07 +00:00
|
|
|
|
{
|
|
|
|
|
public class MonitoredEpisodeSpecification
|
|
|
|
|
{
|
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
2013-02-19 06:56:02 +00:00
|
|
|
|
private readonly ISeriesRepository _seriesRepository;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
public MonitoredEpisodeSpecification(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, ISeriesRepository seriesRepository)
|
2012-02-07 05:08:07 +00:00
|
|
|
|
{
|
|
|
|
|
_seriesProvider = seriesProvider;
|
|
|
|
|
_episodeProvider = episodeProvider;
|
2013-02-19 06:56:02 +00:00
|
|
|
|
_seriesRepository = seriesRepository;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MonitoredEpisodeSpecification()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
|
|
|
|
|
{
|
2013-02-19 06:56:02 +00:00
|
|
|
|
var series = _seriesRepository.Get(subject.CleanTitle);
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
|
|
if (series == null)
|
|
|
|
|
{
|
|
|
|
|
logger.Trace("{0} is not mapped to any series in DB. skipping", subject.CleanTitle);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
subject.Series = series;
|
|
|
|
|
|
|
|
|
|
if (!series.Monitored)
|
|
|
|
|
{
|
|
|
|
|
logger.Debug("{0} is present in the DB but not tracked. skipping.", subject.CleanTitle);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var episodes = _episodeProvider.GetEpisodesByParseResult(subject);
|
2012-10-17 07:39:06 +00:00
|
|
|
|
subject.Episodes = episodes;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
|
|
//return monitored if any of the episodes are monitored
|
|
|
|
|
if (episodes.Any(episode => !episode.Ignored))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.Debug("All episodes are ignored. skipping.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|