mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-17 15:02:34 +02:00
New: Search for newly added past episodes after series is refreshed
Closes #503
This commit is contained in:
parent
27980b2cd6
commit
5a2fa41af7
@ -892,6 +892,7 @@
|
|||||||
<Compile Include="Tv\Commands\MoveSeriesCommand.cs" />
|
<Compile Include="Tv\Commands\MoveSeriesCommand.cs" />
|
||||||
<Compile Include="Tv\Commands\RefreshSeriesCommand.cs" />
|
<Compile Include="Tv\Commands\RefreshSeriesCommand.cs" />
|
||||||
<Compile Include="Tv\Episode.cs" />
|
<Compile Include="Tv\Episode.cs" />
|
||||||
|
<Compile Include="Tv\EpisodeAddedService.cs" />
|
||||||
<Compile Include="Tv\EpisodeCutoffService.cs" />
|
<Compile Include="Tv\EpisodeCutoffService.cs" />
|
||||||
<Compile Include="Tv\EpisodeMonitoredService.cs" />
|
<Compile Include="Tv\EpisodeMonitoredService.cs" />
|
||||||
<Compile Include="Tv\EpisodeRepository.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 @@ public class SeriesScannedHandler : IHandle<SeriesScannedEvent>,
|
|||||||
private readonly IEpisodeMonitoredService _episodeMonitoredService;
|
private readonly IEpisodeMonitoredService _episodeMonitoredService;
|
||||||
private readonly ISeriesService _seriesService;
|
private readonly ISeriesService _seriesService;
|
||||||
private readonly IManageCommandQueue _commandQueueManager;
|
private readonly IManageCommandQueue _commandQueueManager;
|
||||||
|
private readonly IEpisodeAddedService _episodeAddedService;
|
||||||
|
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public SeriesScannedHandler(IEpisodeMonitoredService episodeMonitoredService,
|
public SeriesScannedHandler(IEpisodeMonitoredService episodeMonitoredService,
|
||||||
ISeriesService seriesService,
|
ISeriesService seriesService,
|
||||||
IManageCommandQueue commandQueueManager,
|
IManageCommandQueue commandQueueManager,
|
||||||
|
IEpisodeAddedService episodeAddedService,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_episodeMonitoredService = episodeMonitoredService;
|
_episodeMonitoredService = episodeMonitoredService;
|
||||||
_seriesService = seriesService;
|
_seriesService = seriesService;
|
||||||
_commandQueueManager = commandQueueManager;
|
_commandQueueManager = commandQueueManager;
|
||||||
|
_episodeAddedService = episodeAddedService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +33,7 @@ private void HandleScanEvents(Series series)
|
|||||||
{
|
{
|
||||||
if (series.AddOptions == null)
|
if (series.AddOptions == null)
|
||||||
{
|
{
|
||||||
|
_episodeAddedService.SearchForRecentlyAdded(series.Id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user