Processing of Daily Episode searching now supported.

This commit is contained in:
Mark McDowall 2011-11-26 11:10:13 -08:00
commit 726eccb0e8
3 changed files with 331 additions and 1 deletions

View file

@ -146,7 +146,10 @@ namespace NzbDrone.Core.Providers
Logger.Debug("Finished searching all indexers. Total {0}", reports.Count);
notification.CurrentMessage = "Processing search results";
if (ProcessSearchResults(notification, reports, series, episode.SeasonNumber, episode.EpisodeNumber).Count == 1)
if (!series.IsDaily && ProcessSearchResults(notification, reports, series, episode.SeasonNumber, episode.EpisodeNumber).Count == 1)
return true;
if (series.IsDaily && ProcessSearchResults(notification, reports, series, episode.AirDate.Value))
return true;
Logger.Warn("Unable to find {0} in any of indexers.", episode);
@ -268,6 +271,54 @@ namespace NzbDrone.Core.Providers
return successes;
}
public bool ProcessSearchResults(ProgressNotification notification, IEnumerable<EpisodeParseResult> reports, Series series, DateTime airDate)
{
foreach (var episodeParseResult in reports.OrderByDescending(c => c.Quality))
{
try
{
Logger.Trace("Analysing report " + episodeParseResult);
//Get the matching series
episodeParseResult.Series = _seriesProvider.FindSeries(episodeParseResult.CleanTitle);
//If series is null or doesn't match the series we're looking for return
if (episodeParseResult.Series == null || episodeParseResult.Series.SeriesId != series.SeriesId)
continue;
//If parse result doesn't have an air date or it doesn't match passed in airdate, skip the report.
if (!episodeParseResult.AirDate.HasValue || episodeParseResult.AirDate.Value.Date != airDate.Date)
continue;
if (_inventoryProvider.IsQualityNeeded(episodeParseResult))
{
Logger.Debug("Found '{0}'. Adding to download queue.", episodeParseResult);
try
{
if (_downloadProvider.DownloadReport(episodeParseResult))
{
notification.CurrentMessage =
String.Format("{0} - {1} {2}Added to download queue",
episodeParseResult.Series.Title, episodeParseResult.AirDate.Value.ToShortDateString(), episodeParseResult.Quality);
return true;
}
}
catch (Exception e)
{
Logger.ErrorException("Unable to add report to download queue." + episodeParseResult, e);
notification.CurrentMessage = String.Format("Unable to add report to download queue. {0}", episodeParseResult);
}
}
}
catch (Exception e)
{
Logger.ErrorException("An error has occurred while processing parse result items from " + episodeParseResult, e);
}
}
return false;
}
private List<int> GetEpisodeNumberPrefixes(IEnumerable<int> episodeNumbers)
{
var results = new List<int>();