You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.9 KiB
83 lines
2.9 KiB
13 years ago
|
using System;
|
||
12 years ago
|
using System.Linq;
|
||
12 years ago
|
using NLog;
|
||
12 years ago
|
using NzbDrone.Core.DecisionEngine;
|
||
12 years ago
|
using NzbDrone.Core.Model.Notification;
|
||
12 years ago
|
using NzbDrone.Core.Providers.Search;
|
||
12 years ago
|
using NzbDrone.Core.Tv;
|
||
14 years ago
|
|
||
12 years ago
|
namespace NzbDrone.Core.Jobs.Implementations
|
||
14 years ago
|
{
|
||
|
public class EpisodeSearchJob : IJob
|
||
|
{
|
||
12 years ago
|
private readonly IEpisodeService _episodeService;
|
||
12 years ago
|
private readonly UpgradePossibleSpecification _upgradePossibleSpecification;
|
||
|
private readonly EpisodeSearch _episodeSearch;
|
||
|
private readonly DailyEpisodeSearch _dailyEpisodeSearch;
|
||
14 years ago
|
|
||
12 years ago
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||
|
|
||
12 years ago
|
public EpisodeSearchJob(IEpisodeService episodeService, UpgradePossibleSpecification upgradePossibleSpecification,
|
||
12 years ago
|
EpisodeSearch episodeSearch, DailyEpisodeSearch dailyEpisodeSearch)
|
||
14 years ago
|
{
|
||
12 years ago
|
if(dailyEpisodeSearch == null) throw new ArgumentNullException("dailyEpisodeSearch");
|
||
12 years ago
|
_episodeService = episodeService;
|
||
12 years ago
|
_upgradePossibleSpecification = upgradePossibleSpecification;
|
||
|
_episodeSearch = episodeSearch;
|
||
|
_dailyEpisodeSearch = dailyEpisodeSearch;
|
||
14 years ago
|
}
|
||
|
|
||
13 years ago
|
public EpisodeSearchJob()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
14 years ago
|
public string Name
|
||
|
{
|
||
|
get { return "Episode Search"; }
|
||
|
}
|
||
|
|
||
13 years ago
|
public TimeSpan DefaultInterval
|
||
14 years ago
|
{
|
||
13 years ago
|
get { return TimeSpan.FromTicks(0); }
|
||
14 years ago
|
}
|
||
|
|
||
12 years ago
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
||
14 years ago
|
{
|
||
12 years ago
|
if (options == null || options.EpisodeId <= 0)
|
||
|
throw new ArgumentException("options");
|
||
14 years ago
|
|
||
12 years ago
|
Episode episode = _episodeService.GetEpisode((int)options.EpisodeId);
|
||
12 years ago
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
12 years ago
|
if (episode.Series.SeriesTypes == SeriesTypes.Daily)
|
||
12 years ago
|
{
|
||
|
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);
|
||
|
}
|
||
14 years ago
|
}
|
||
|
}
|
||
|
}
|