2012-09-19 04:30:30 +03:00
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using Ninject;
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers.DecisionEngine
|
|
|
|
{
|
2012-09-20 18:37:40 +03:00
|
|
|
public class CustomStartDateSpecification
|
2012-09-19 04:30:30 +03:00
|
|
|
{
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
[Inject]
|
2012-09-20 18:37:40 +03:00
|
|
|
public CustomStartDateSpecification(EpisodeProvider episodeProvider)
|
2012-09-19 04:30:30 +03:00
|
|
|
{
|
|
|
|
_episodeProvider = episodeProvider;
|
|
|
|
}
|
|
|
|
|
2012-09-20 18:37:40 +03:00
|
|
|
public CustomStartDateSpecification()
|
2012-09-19 04:30:30 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
|
|
|
|
{
|
2012-09-20 18:37:40 +03:00
|
|
|
if (!subject.Series.CustomStartDate.HasValue)
|
2012-09-19 04:30:30 +03:00
|
|
|
{
|
|
|
|
logger.Debug("{0} does not restrict downloads before date.", subject.Series.Title);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var episodes = _episodeProvider.GetEpisodesByParseResult(subject);
|
|
|
|
|
2012-09-20 18:37:40 +03:00
|
|
|
if (episodes.Any(episode => episode.AirDate > subject.Series.CustomStartDate.Value))
|
2012-09-19 04:30:30 +03:00
|
|
|
{
|
|
|
|
logger.Debug("One or more episodes aired after cutoff, downloading.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-20 18:37:40 +03:00
|
|
|
logger.Debug("Episodes aired before cutoff date: {0}", subject.Series.CustomStartDate);
|
2012-09-19 04:30:30 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|