mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-26 17:57:43 +00:00
New: Search for newly added past episodes after series is refreshed
Closes #503
This commit is contained in:
parent
27980b2cd6
commit
5a2fa41af7
3 changed files with 94 additions and 1 deletions
|
@ -892,6 +892,7 @@
|
|||
<Compile Include="Tv\Commands\MoveSeriesCommand.cs" />
|
||||
<Compile Include="Tv\Commands\RefreshSeriesCommand.cs" />
|
||||
<Compile Include="Tv\Episode.cs" />
|
||||
<Compile Include="Tv\EpisodeAddedService.cs" />
|
||||
<Compile Include="Tv\EpisodeCutoffService.cs" />
|
||||
<Compile Include="Tv\EpisodeMonitoredService.cs" />
|
||||
<Compile Include="Tv\EpisodeRepository.cs">
|
||||
|
|
88
src/NzbDrone.Core/Tv/EpisodeAddedService.cs
Normal file
88
src/NzbDrone.Core/Tv/EpisodeAddedService.cs
Normal file
|
@ -0,0 +1,88 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Tv.Events;
|
||||
|
||||
namespace NzbDrone.Core.Tv
|
||||
{
|
||||
public interface IEpisodeAddedService
|
||||
{
|
||||
void SearchForRecentlyAdded(int seriesId);
|
||||
}
|
||||
|
||||
public class EpisodeAddedService : IHandle<EpisodeInfoRefreshedEvent>, IEpisodeAddedService
|
||||
{
|
||||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly Logger _logger;
|
||||
private readonly ICached<List<int>> _addedEpisodesCache;
|
||||
|
||||
public EpisodeAddedService(ICacheManager cacheManager,
|
||||
IManageCommandQueue commandQueueManager,
|
||||
IEpisodeService episodeService,
|
||||
Logger logger)
|
||||
{
|
||||
_commandQueueManager = commandQueueManager;
|
||||
_episodeService = episodeService;
|
||||
_logger = logger;
|
||||
_addedEpisodesCache = cacheManager.GetCache<List<int>>(GetType());
|
||||
}
|
||||
|
||||
public void SearchForRecentlyAdded(int seriesId)
|
||||
{
|
||||
var previouslyAired = _addedEpisodesCache.Find(seriesId.ToString());
|
||||
|
||||
if (previouslyAired != null && previouslyAired.Any())
|
||||
{
|
||||
var missing = previouslyAired.Select(e => _episodeService.GetEpisode(e)).Where(e => !e.HasFile).ToList();
|
||||
|
||||
if (missing.Any())
|
||||
{
|
||||
_commandQueueManager.Push(new EpisodeSearchCommand(missing.Select(e => e.Id).ToList()));
|
||||
}
|
||||
}
|
||||
|
||||
_addedEpisodesCache.Remove(seriesId.ToString());
|
||||
}
|
||||
|
||||
public void Handle(EpisodeInfoRefreshedEvent message)
|
||||
{
|
||||
if (message.Series.AddOptions == null)
|
||||
{
|
||||
if (!message.Series.Monitored)
|
||||
{
|
||||
_logger.Debug("Series is not monitored");
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.Added.Empty())
|
||||
{
|
||||
_logger.Debug("No new episodes, skipping search");
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.Added.None(a => a.AirDateUtc.HasValue))
|
||||
{
|
||||
_logger.Debug("No new episodes have an air date");
|
||||
return;
|
||||
}
|
||||
|
||||
var previouslyAired = message.Added.Where(a => a.AirDateUtc.HasValue && a.AirDateUtc.Value.Before(DateTime.UtcNow.AddDays(1)) && a.Monitored).ToList();
|
||||
|
||||
if (previouslyAired.Empty())
|
||||
{
|
||||
_logger.Debug("Newly added episodes all air in the future");
|
||||
return;
|
||||
}
|
||||
|
||||
_addedEpisodesCache.Set(message.Series.Id.ToString(), previouslyAired.Select(e => e.Id).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,17 +12,20 @@ namespace NzbDrone.Core.Tv
|
|||
private readonly IEpisodeMonitoredService _episodeMonitoredService;
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
|
||||
private readonly IEpisodeAddedService _episodeAddedService;
|
||||
|
||||
private readonly Logger _logger;
|
||||
|
||||
public SeriesScannedHandler(IEpisodeMonitoredService episodeMonitoredService,
|
||||
ISeriesService seriesService,
|
||||
IManageCommandQueue commandQueueManager,
|
||||
IEpisodeAddedService episodeAddedService,
|
||||
Logger logger)
|
||||
{
|
||||
_episodeMonitoredService = episodeMonitoredService;
|
||||
_seriesService = seriesService;
|
||||
_commandQueueManager = commandQueueManager;
|
||||
_episodeAddedService = episodeAddedService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
@ -30,6 +33,7 @@ namespace NzbDrone.Core.Tv
|
|||
{
|
||||
if (series.AddOptions == null)
|
||||
{
|
||||
_episodeAddedService.SearchForRecentlyAdded(series.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue