2011-12-02 01:33:17 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System;
|
2013-01-13 08:24:48 +00:00
|
|
|
|
using NLog;
|
2013-03-05 05:20:47 +00:00
|
|
|
|
using NzbDrone.Core.Jobs.Framework;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-05-26 05:44:59 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2013-02-19 02:19:38 +00:00
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2013-01-13 08:24:48 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Search;
|
2013-01-17 02:51:25 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-05-26 05:44:59 +00:00
|
|
|
|
|
2011-12-02 01:33:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Jobs
|
2011-05-26 05:44:59 +00:00
|
|
|
|
{
|
|
|
|
|
public class EpisodeSearchJob : IJob
|
|
|
|
|
{
|
2013-02-22 00:47:09 +00:00
|
|
|
|
private readonly IEpisodeService _episodeService;
|
2013-01-13 08:24:48 +00:00
|
|
|
|
private readonly UpgradePossibleSpecification _upgradePossibleSpecification;
|
|
|
|
|
private readonly EpisodeSearch _episodeSearch;
|
|
|
|
|
private readonly DailyEpisodeSearch _dailyEpisodeSearch;
|
2011-05-26 05:44:59 +00:00
|
|
|
|
|
2013-01-13 08:24:48 +00:00
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
public EpisodeSearchJob(IEpisodeService episodeService, UpgradePossibleSpecification upgradePossibleSpecification,
|
2013-01-13 08:24:48 +00:00
|
|
|
|
EpisodeSearch episodeSearch, DailyEpisodeSearch dailyEpisodeSearch)
|
2011-05-26 05:44:59 +00:00
|
|
|
|
{
|
2013-01-13 08:24:48 +00:00
|
|
|
|
if(dailyEpisodeSearch == null) throw new ArgumentNullException("dailyEpisodeSearch");
|
2013-02-20 02:05:15 +00:00
|
|
|
|
_episodeService = episodeService;
|
2013-01-13 08:24:48 +00:00
|
|
|
|
_upgradePossibleSpecification = upgradePossibleSpecification;
|
|
|
|
|
_episodeSearch = episodeSearch;
|
|
|
|
|
_dailyEpisodeSearch = dailyEpisodeSearch;
|
2011-05-26 05:44:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-22 00:48:37 +00:00
|
|
|
|
public EpisodeSearchJob()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-26 05:44:59 +00:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Episode Search"; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 02:47:23 +00:00
|
|
|
|
public TimeSpan DefaultInterval
|
2011-05-26 05:44:59 +00:00
|
|
|
|
{
|
2012-01-15 02:47:23 +00:00
|
|
|
|
get { return TimeSpan.FromTicks(0); }
|
2011-05-26 05:44:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
2011-05-26 05:44:59 +00:00
|
|
|
|
{
|
2012-09-10 19:04:17 +00:00
|
|
|
|
if (options == null || options.EpisodeId <= 0)
|
|
|
|
|
throw new ArgumentException("options");
|
2011-05-27 03:54:28 +00:00
|
|
|
|
|
2013-02-22 23:55:43 +00:00
|
|
|
|
Episode episode = _episodeService.GetEpisode((int)options.EpisodeId);
|
2013-01-13 08:24:48 +00:00
|
|
|
|
|
|
|
|
|
if (episode == null)
|
|
|
|
|
{
|
|
|
|
|
logger.Error("Unable to find an episode {0} in database", options.EpisodeId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_upgradePossibleSpecification.IsSatisfiedBy(episode))
|
|
|
|
|
{
|
|
|
|
|
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-04 05:53:02 +00:00
|
|
|
|
if (episode.Series.SeriesTypes == SeriesTypes.Daily)
|
2013-01-13 08:24:48 +00: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
|
|
|
|
|
{
|
|
|
|
|
_episodeSearch.Search(episode.Series, new { Episode = episode }, notification);
|
|
|
|
|
}
|
2011-05-26 05:44:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|