1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core/Jobs/EpisodeSearchJob.cs

83 lines
2.9 KiB
C#
Raw Normal View History

2011-12-02 04:33:17 +03:00
using System.Linq;
using System;
2013-01-13 11:24:48 +03:00
using NLog;
using NzbDrone.Core.Model.Notification;
2011-12-02 04:33:17 +03:00
using NzbDrone.Core.Providers;
2013-01-13 11:24:48 +03:00
using NzbDrone.Core.Providers.DecisionEngine;
using NzbDrone.Core.Providers.Search;
2011-12-02 04:33:17 +03:00
namespace NzbDrone.Core.Jobs
{
public class EpisodeSearchJob : IJob
{
2013-01-13 11:24:48 +03:00
private readonly EpisodeProvider _episodeProvider;
private readonly UpgradePossibleSpecification _upgradePossibleSpecification;
private readonly EpisodeSearch _episodeSearch;
private readonly DailyEpisodeSearch _dailyEpisodeSearch;
2013-01-13 11:24:48 +03:00
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public EpisodeSearchJob(EpisodeProvider episodeProvider, UpgradePossibleSpecification upgradePossibleSpecification,
EpisodeSearch episodeSearch, DailyEpisodeSearch dailyEpisodeSearch)
{
2013-01-13 11:24:48 +03:00
if(dailyEpisodeSearch == null) throw new ArgumentNullException("dailyEpisodeSearch");
_episodeProvider = episodeProvider;
_upgradePossibleSpecification = upgradePossibleSpecification;
_episodeSearch = episodeSearch;
_dailyEpisodeSearch = dailyEpisodeSearch;
}
public EpisodeSearchJob()
{
}
public string Name
{
get { return "Episode Search"; }
}
public TimeSpan DefaultInterval
{
get { return TimeSpan.FromTicks(0); }
}
2012-09-10 22:04:17 +03:00
public virtual void Start(ProgressNotification notification, dynamic options)
{
2012-09-10 22:04:17 +03:00
if (options == null || options.EpisodeId <= 0)
throw new ArgumentException("options");
2011-05-27 06:54:28 +03:00
2013-01-13 11:24:48 +03:00
var episode = _episodeProvider.GetEpisode(options.EpisodeId);
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;
}
if (episode.Series.IsDaily)
{
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);
}
}
}
}