1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 16:02:29 +01:00
Sonarr/NzbDrone.Core/DecisionEngine/MonitoredEpisodeSpecification.cs

58 lines
1.7 KiB
C#
Raw Normal View History

using System.Linq;
using NLog;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
2013-02-19 03:19:38 +01:00
using NzbDrone.Core.Providers;
2013-02-19 03:19:38 +01:00
namespace NzbDrone.Core.DecisionEngine
{
public class MonitoredEpisodeSpecification
{
private readonly IEpisodeService _episodeService;
2013-02-19 07:56:02 +01:00
private readonly ISeriesRepository _seriesRepository;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public MonitoredEpisodeSpecification(IEpisodeService episodeService, ISeriesRepository seriesRepository)
{
_episodeService = episodeService;
2013-02-19 07:56:02 +01:00
_seriesRepository = seriesRepository;
}
public MonitoredEpisodeSpecification()
{
}
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
{
var series = _seriesRepository.GetByTitle(subject.CleanTitle);
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 = _episodeService.GetEpisodesByParseResult(subject);
subject.Episodes = episodes;
//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;
}
}
}