2011-12-02 02:33:17 +01:00
|
|
|
using System;
|
2013-01-13 09:24:48 +01:00
|
|
|
using NLog;
|
2013-02-19 03:19:38 +01:00
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2013-03-07 04:45:36 +01:00
|
|
|
using NzbDrone.Core.IndexerSearch;
|
2013-03-05 06:37:33 +01:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-05-26 07:44:59 +02:00
|
|
|
|
2013-03-05 06:37:33 +01:00
|
|
|
namespace NzbDrone.Core.Jobs.Implementations
|
2011-05-26 07:44:59 +02:00
|
|
|
{
|
|
|
|
public class EpisodeSearchJob : IJob
|
|
|
|
{
|
2013-02-22 01:47:09 +01:00
|
|
|
private readonly IEpisodeService _episodeService;
|
2013-03-07 01:19:49 +01:00
|
|
|
private readonly IQualityUpgradableSpecification _qualityUpgradableSpecification;
|
2013-01-13 09:24:48 +01:00
|
|
|
private readonly EpisodeSearch _episodeSearch;
|
|
|
|
private readonly DailyEpisodeSearch _dailyEpisodeSearch;
|
2011-05-26 07:44:59 +02:00
|
|
|
|
2013-01-13 09:24:48 +01:00
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
2013-03-07 01:19:49 +01:00
|
|
|
public EpisodeSearchJob(IEpisodeService episodeService, IQualityUpgradableSpecification qualityUpgradableSpecification,
|
2013-01-13 09:24:48 +01:00
|
|
|
EpisodeSearch episodeSearch, DailyEpisodeSearch dailyEpisodeSearch)
|
2011-05-26 07:44:59 +02:00
|
|
|
{
|
2013-03-07 01:19:49 +01:00
|
|
|
if (dailyEpisodeSearch == null) throw new ArgumentNullException("dailyEpisodeSearch");
|
2013-02-20 03:05:15 +01:00
|
|
|
_episodeService = episodeService;
|
2013-03-07 01:19:49 +01:00
|
|
|
_qualityUpgradableSpecification = qualityUpgradableSpecification;
|
2013-01-13 09:24:48 +01:00
|
|
|
_episodeSearch = episodeSearch;
|
|
|
|
_dailyEpisodeSearch = dailyEpisodeSearch;
|
2011-05-26 07:44:59 +02:00
|
|
|
}
|
|
|
|
|
2011-08-22 02:48:37 +02:00
|
|
|
public EpisodeSearchJob()
|
|
|
|
{
|
2013-03-07 01:19:49 +01:00
|
|
|
|
2011-08-22 02:48:37 +02:00
|
|
|
}
|
|
|
|
|
2011-05-26 07:44:59 +02:00
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get { return "Episode Search"; }
|
|
|
|
}
|
|
|
|
|
2012-01-15 03:47:23 +01:00
|
|
|
public TimeSpan DefaultInterval
|
2011-05-26 07:44:59 +02:00
|
|
|
{
|
2012-01-15 03:47:23 +01:00
|
|
|
get { return TimeSpan.FromTicks(0); }
|
2011-05-26 07:44:59 +02:00
|
|
|
}
|
|
|
|
|
2012-09-10 21:04:17 +02:00
|
|
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
2011-05-26 07:44:59 +02:00
|
|
|
{
|
2012-09-10 21:04:17 +02:00
|
|
|
if (options == null || options.EpisodeId <= 0)
|
|
|
|
throw new ArgumentException("options");
|
2011-05-27 05:54:28 +02:00
|
|
|
|
2013-02-23 00:55:43 +01:00
|
|
|
Episode episode = _episodeService.GetEpisode((int)options.EpisodeId);
|
2013-01-13 09:24:48 +01:00
|
|
|
|
|
|
|
if (episode == null)
|
|
|
|
{
|
|
|
|
logger.Error("Unable to find an episode {0} in database", options.EpisodeId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-07 01:19:49 +01:00
|
|
|
if (!_qualityUpgradableSpecification.IsUpgradable(episode.Series.QualityProfile, episode.EpisodeFile.QualityModel))
|
2013-01-13 09:24:48 +01:00
|
|
|
{
|
|
|
|
logger.Info("Search for {0} was aborted, file in disk meets or exceeds Profile's Cutoff", episode);
|
|
|
|
notification.CurrentMessage = String.Format("Skipping search for {0}, the file you have is already at cutoff", episode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-24 05:16:00 +01:00
|
|
|
if (episode.Series.SeriesType == SeriesTypes.Daily)
|
2013-01-13 09:24:48 +01:00
|
|
|
{
|
|
|
|
if (!episode.AirDate.HasValue)
|
|
|
|
{
|
|
|
|
logger.Warn("AirDate is not Valid for: {0}", episode);
|
|
|
|
notification.CurrentMessage = String.Format("Search for {0} Failed, AirDate is invalid", episode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_dailyEpisodeSearch.Search(episode.Series, new { Episode = episode }, notification);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2013-03-07 01:19:49 +01:00
|
|
|
_episodeSearch.Search(episode.Series, new { Episode = episode }, notification);
|
2013-01-13 09:24:48 +01:00
|
|
|
}
|
2011-05-26 07:44:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|