mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-22 07:43:01 +00:00
Fixed: Searching for monitored episodes in series when all seasons are unmonitored
This commit is contained in:
parent
b3fc905481
commit
8c1fb31b5d
1 changed files with 34 additions and 9 deletions
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Instrumentation.Extensions;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
|
@ -10,16 +12,19 @@ namespace NzbDrone.Core.IndexerSearch
|
|||
public class SeriesSearchService : IExecute<SeriesSearchCommand>
|
||||
{
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly ISearchForReleases _releaseSearchService;
|
||||
private readonly IProcessDownloadDecisions _processDownloadDecisions;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public SeriesSearchService(ISeriesService seriesService,
|
||||
IEpisodeService episodeService,
|
||||
ISearchForReleases releaseSearchService,
|
||||
IProcessDownloadDecisions processDownloadDecisions,
|
||||
Logger logger)
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
_episodeService = episodeService;
|
||||
_releaseSearchService = releaseSearchService;
|
||||
_processDownloadDecisions = processDownloadDecisions;
|
||||
_logger = logger;
|
||||
|
@ -28,19 +33,39 @@ namespace NzbDrone.Core.IndexerSearch
|
|||
public void Execute(SeriesSearchCommand message)
|
||||
{
|
||||
var series = _seriesService.GetSeries(message.SeriesId);
|
||||
|
||||
var downloadedCount = 0;
|
||||
var userInvokedSearch = message.Trigger == CommandTrigger.Manual;
|
||||
|
||||
foreach (var season in series.Seasons.OrderBy(s => s.SeasonNumber))
|
||||
if (series.Seasons.None(s => s.Monitored))
|
||||
{
|
||||
if (!season.Monitored)
|
||||
{
|
||||
_logger.Debug("Season {0} of {1} is not monitored, skipping search", season.SeasonNumber, series.Title);
|
||||
continue;
|
||||
}
|
||||
_logger.Debug("No seasons of {0} are monitored, searching for all monitored episodes", series.Title);
|
||||
|
||||
var decisions = _releaseSearchService.SeasonSearch(message.SeriesId, season.SeasonNumber, false, true, message.Trigger == CommandTrigger.Manual, false);
|
||||
downloadedCount += _processDownloadDecisions.ProcessDecisions(decisions).Grabbed.Count;
|
||||
var episodes = _episodeService.GetEpisodeBySeries(series.Id)
|
||||
.Where(e => e.Monitored &&
|
||||
!e.HasFile &&
|
||||
e.AirDateUtc.HasValue &&
|
||||
e.AirDateUtc.Value.Before(DateTime.UtcNow))
|
||||
.ToList();
|
||||
|
||||
foreach (var episode in episodes)
|
||||
{
|
||||
var decisions = _releaseSearchService.EpisodeSearch(episode, userInvokedSearch, false);
|
||||
downloadedCount += _processDownloadDecisions.ProcessDecisions(decisions).Grabbed.Count;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var season in series.Seasons.OrderBy(s => s.SeasonNumber))
|
||||
{
|
||||
if (!season.Monitored)
|
||||
{
|
||||
_logger.Debug("Season {0} of {1} is not monitored, skipping search", season.SeasonNumber, series.Title);
|
||||
continue;
|
||||
}
|
||||
|
||||
var decisions = _releaseSearchService.SeasonSearch(message.SeriesId, season.SeasonNumber, false, true, userInvokedSearch, false);
|
||||
downloadedCount += _processDownloadDecisions.ProcessDecisions(decisions).Grabbed.Count;
|
||||
}
|
||||
}
|
||||
|
||||
_logger.ProgressInfo("Series search completed. {0} reports downloaded.", downloadedCount);
|
||||
|
|
Loading…
Reference in a new issue