Fixed: Searching for monitored episodes in series when all seasons are unmonitored

This commit is contained in:
Mark McDowall 2022-11-12 11:58:57 -08:00
parent b3fc905481
commit 8c1fb31b5d
1 changed files with 34 additions and 9 deletions

View File

@ -1,5 +1,7 @@
using System;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
@ -10,16 +12,19 @@ namespace NzbDrone.Core.IndexerSearch
public class SeriesSearchService : IExecute<SeriesSearchCommand> public class SeriesSearchService : IExecute<SeriesSearchCommand>
{ {
private readonly ISeriesService _seriesService; private readonly ISeriesService _seriesService;
private readonly IEpisodeService _episodeService;
private readonly ISearchForReleases _releaseSearchService; private readonly ISearchForReleases _releaseSearchService;
private readonly IProcessDownloadDecisions _processDownloadDecisions; private readonly IProcessDownloadDecisions _processDownloadDecisions;
private readonly Logger _logger; private readonly Logger _logger;
public SeriesSearchService(ISeriesService seriesService, public SeriesSearchService(ISeriesService seriesService,
IEpisodeService episodeService,
ISearchForReleases releaseSearchService, ISearchForReleases releaseSearchService,
IProcessDownloadDecisions processDownloadDecisions, IProcessDownloadDecisions processDownloadDecisions,
Logger logger) Logger logger)
{ {
_seriesService = seriesService; _seriesService = seriesService;
_episodeService = episodeService;
_releaseSearchService = releaseSearchService; _releaseSearchService = releaseSearchService;
_processDownloadDecisions = processDownloadDecisions; _processDownloadDecisions = processDownloadDecisions;
_logger = logger; _logger = logger;
@ -28,19 +33,39 @@ namespace NzbDrone.Core.IndexerSearch
public void Execute(SeriesSearchCommand message) public void Execute(SeriesSearchCommand message)
{ {
var series = _seriesService.GetSeries(message.SeriesId); var series = _seriesService.GetSeries(message.SeriesId);
var downloadedCount = 0; 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("No seasons of {0} are monitored, searching for all monitored episodes", series.Title);
{
_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, message.Trigger == CommandTrigger.Manual, false); var episodes = _episodeService.GetEpisodeBySeries(series.Id)
downloadedCount += _processDownloadDecisions.ProcessDecisions(decisions).Grabbed.Count; .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); _logger.ProgressInfo("Series search completed. {0} reports downloaded.", downloadedCount);