|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
using NzbDrone.Common.Instrumentation.Extensions;
|
|
|
|
@ -40,46 +39,63 @@ namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SearchForEpisodes(List<Episode> episodes, bool monitoredOnly, bool userInvokedSearch)
|
|
|
|
|
private void SearchForBulkEpisodes(List<Episode> episodes, bool monitoredOnly, bool userInvokedSearch)
|
|
|
|
|
{
|
|
|
|
|
_logger.ProgressInfo("Performing search for {0} episodes", episodes.Count);
|
|
|
|
|
var downloadedCount = 0;
|
|
|
|
|
var groups = new List<EpisodeSearchGroup>();
|
|
|
|
|
|
|
|
|
|
foreach (var series in episodes.GroupBy(e => e.SeriesId))
|
|
|
|
|
{
|
|
|
|
|
foreach (var season in series.Select(e => e).GroupBy(e => e.SeasonNumber))
|
|
|
|
|
{
|
|
|
|
|
List<DownloadDecision> decisions;
|
|
|
|
|
groups.Add(new EpisodeSearchGroup
|
|
|
|
|
{
|
|
|
|
|
SeriesId = series.Key,
|
|
|
|
|
SeasonNumber = season.Key,
|
|
|
|
|
Episodes = season.ToList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var group in groups.OrderBy(g => g.Episodes.Min(e => e.LastSearchTime ?? DateTime.MinValue)))
|
|
|
|
|
{
|
|
|
|
|
List<DownloadDecision> decisions;
|
|
|
|
|
|
|
|
|
|
if (season.Count() > 1)
|
|
|
|
|
var seriesId = group.SeriesId;
|
|
|
|
|
var seasonNumber = group.SeasonNumber;
|
|
|
|
|
var groupEpisodes = group.Episodes;
|
|
|
|
|
|
|
|
|
|
if (groupEpisodes.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
decisions = _releaseSearchService.SeasonSearch(series.Key, season.Key, season.ToList(), monitoredOnly, userInvokedSearch, false);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(ex, "Unable to search for episodes in season {0} of [{1}]", season.Key, series.Key);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
decisions = _releaseSearchService.SeasonSearch(seriesId, seasonNumber, groupEpisodes, monitoredOnly, userInvokedSearch, false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
decisions = _releaseSearchService.EpisodeSearch(season.First(), userInvokedSearch, false);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(ex, "Unable to search for episode: [{0}]", season.First());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
_logger.Error(ex, "Unable to search for episodes in season {0} of [{1}]", seasonNumber, seriesId);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var episode = groupEpisodes.First();
|
|
|
|
|
|
|
|
|
|
var processed = _processDownloadDecisions.ProcessDecisions(decisions);
|
|
|
|
|
|
|
|
|
|
downloadedCount += processed.Grabbed.Count;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
decisions = _releaseSearchService.EpisodeSearch(episode, userInvokedSearch, false);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(ex, "Unable to search for episode: [{0}]", episode);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var processed = _processDownloadDecisions.ProcessDecisions(decisions);
|
|
|
|
|
|
|
|
|
|
downloadedCount += processed.Grabbed.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.ProgressInfo("Completed search for {0} episodes. {1} reports downloaded.", episodes.Count, downloadedCount);
|
|
|
|
@ -120,7 +136,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
var pagingSpec = new PagingSpec<Episode>
|
|
|
|
|
{
|
|
|
|
|
Page = 1,
|
|
|
|
|
PageSize = 100000,
|
|
|
|
|
PageSize = 1000000,
|
|
|
|
|
SortDirection = SortDirection.Ascending,
|
|
|
|
|
SortKey = "Id"
|
|
|
|
|
};
|
|
|
|
@ -140,7 +156,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
var queue = _queueService.GetQueue().Where(q => q.Episode != null).Select(q => q.Episode.Id);
|
|
|
|
|
var missing = episodes.Where(e => !queue.Contains(e.Id)).ToList();
|
|
|
|
|
|
|
|
|
|
SearchForEpisodes(missing, monitored, message.Trigger == CommandTrigger.Manual);
|
|
|
|
|
SearchForBulkEpisodes(missing, monitored, message.Trigger == CommandTrigger.Manual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Execute(CutoffUnmetEpisodeSearchCommand message)
|
|
|
|
@ -174,7 +190,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
var queue = _queueService.GetQueue().Where(q => q.Episode != null).Select(q => q.Episode.Id);
|
|
|
|
|
var cutoffUnmet = episodes.Where(e => !queue.Contains(e.Id)).ToList();
|
|
|
|
|
|
|
|
|
|
SearchForEpisodes(cutoffUnmet, monitored, message.Trigger == CommandTrigger.Manual);
|
|
|
|
|
SearchForBulkEpisodes(cutoffUnmet, monitored, message.Trigger == CommandTrigger.Manual);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|