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.
78 lines
2.7 KiB
78 lines
2.7 KiB
12 years ago
|
using System;
|
||
12 years ago
|
using System.Collections.Generic;
|
||
13 years ago
|
using System.Linq;
|
||
|
using NLog;
|
||
|
using NzbDrone.Core.Model.Notification;
|
||
13 years ago
|
using NzbDrone.Core.Providers;
|
||
12 years ago
|
using NzbDrone.Core.Tv;
|
||
13 years ago
|
|
||
12 years ago
|
namespace NzbDrone.Core.Jobs.Implementations
|
||
13 years ago
|
{
|
||
|
public class SeasonSearchJob : IJob
|
||
|
{
|
||
13 years ago
|
private readonly SearchProvider _searchProvider;
|
||
13 years ago
|
private readonly EpisodeSearchJob _episodeSearchJob;
|
||
12 years ago
|
private readonly IEpisodeService _episodeService;
|
||
13 years ago
|
|
||
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||
|
|
||
13 years ago
|
public SeasonSearchJob(SearchProvider searchProvider, EpisodeSearchJob episodeSearchJob,
|
||
12 years ago
|
IEpisodeService episodeService)
|
||
13 years ago
|
{
|
||
13 years ago
|
_searchProvider = searchProvider;
|
||
13 years ago
|
_episodeSearchJob = episodeSearchJob;
|
||
12 years ago
|
_episodeService = episodeService;
|
||
13 years ago
|
}
|
||
|
|
||
13 years ago
|
public SeasonSearchJob()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
13 years ago
|
public string Name
|
||
|
{
|
||
|
get { return "Season Search"; }
|
||
|
}
|
||
|
|
||
13 years ago
|
public TimeSpan DefaultInterval
|
||
13 years ago
|
{
|
||
13 years ago
|
get { return TimeSpan.FromTicks(0); }
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
||
13 years ago
|
{
|
||
12 years ago
|
if (options == null || options.SeriesId <= 0)
|
||
|
throw new ArgumentException("options");
|
||
13 years ago
|
|
||
12 years ago
|
if (options.SeasonNumber < 0)
|
||
|
throw new ArgumentException("options.SeasonNumber");
|
||
13 years ago
|
|
||
13 years ago
|
//Perform a Partial Season Search - Because a full season search is a waste
|
||
|
//3 searches should guarentee results, (24 eps) versus, a potential 4 to get the same eps.
|
||
12 years ago
|
List<int> successes = _searchProvider.PartialSeasonSearch(notification, options.SeriesId, options.SeasonNumber);
|
||
13 years ago
|
|
||
12 years ago
|
//This causes issues with Newznab
|
||
|
//if (successes.Count == 0)
|
||
|
// return;
|
||
13 years ago
|
|
||
12 years ago
|
Logger.Debug("Getting episodes from database for series: {0} and season: {1}", options.SeriesId, options.SeasonNumber);
|
||
12 years ago
|
IList<Episode> episodes = _episodeService.GetEpisodesBySeason((int)options.SeriesId, (int)options.SeasonNumber);
|
||
13 years ago
|
|
||
13 years ago
|
if (episodes == null || episodes.Count == 0)
|
||
13 years ago
|
{
|
||
12 years ago
|
Logger.Warn("No episodes in database found for series: {0} and season: {1}.", options.SeriesId, options.SeasonNumber);
|
||
13 years ago
|
return;
|
||
|
}
|
||
|
|
||
13 years ago
|
if (episodes.Count == successes.Count)
|
||
|
return;
|
||
13 years ago
|
|
||
12 years ago
|
var missingEpisodes = episodes.Select(e => e.Id).Except(successes).ToList();
|
||
13 years ago
|
|
||
12 years ago
|
foreach (var episode in episodes.Where(e => !e.Ignored && missingEpisodes.Contains(e.Id)).OrderBy(o => o.EpisodeNumber))
|
||
13 years ago
|
{
|
||
12 years ago
|
_episodeSearchJob.Start(notification, new { EpisodeId = episode.Id });
|
||
13 years ago
|
}
|
||
13 years ago
|
}
|
||
|
}
|
||
|
}
|