|
|
@ -1,4 +1,4 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
@ -11,19 +11,19 @@ using NzbDrone.Core.Tv.Events;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Tv
|
|
|
|
namespace NzbDrone.Core.Tv
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public interface IEpisodeAddedService
|
|
|
|
public interface IEpisodeRefreshedService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
void SearchForRecentlyAdded(int seriesId);
|
|
|
|
void Search(int seriesId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class EpisodeAddedService : IHandle<EpisodeInfoRefreshedEvent>, IEpisodeAddedService
|
|
|
|
public class EpisodeRefreshedService : IEpisodeRefreshedService, IHandle<EpisodeInfoRefreshedEvent>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IManageCommandQueue _commandQueueManager;
|
|
|
|
private readonly IManageCommandQueue _commandQueueManager;
|
|
|
|
private readonly IEpisodeService _episodeService;
|
|
|
|
private readonly IEpisodeService _episodeService;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly ICached<List<int>> _addedEpisodesCache;
|
|
|
|
private readonly ICached<List<int>> _searchCache;
|
|
|
|
|
|
|
|
|
|
|
|
public EpisodeAddedService(ICacheManager cacheManager,
|
|
|
|
public EpisodeRefreshedService(ICacheManager cacheManager,
|
|
|
|
IManageCommandQueue commandQueueManager,
|
|
|
|
IManageCommandQueue commandQueueManager,
|
|
|
|
IEpisodeService episodeService,
|
|
|
|
IEpisodeService episodeService,
|
|
|
|
Logger logger)
|
|
|
|
Logger logger)
|
|
|
@ -31,12 +31,12 @@ namespace NzbDrone.Core.Tv
|
|
|
|
_commandQueueManager = commandQueueManager;
|
|
|
|
_commandQueueManager = commandQueueManager;
|
|
|
|
_episodeService = episodeService;
|
|
|
|
_episodeService = episodeService;
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
_addedEpisodesCache = cacheManager.GetCache<List<int>>(GetType());
|
|
|
|
_searchCache = cacheManager.GetCache<List<int>>(GetType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SearchForRecentlyAdded(int seriesId)
|
|
|
|
public void Search(int seriesId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var previouslyAired = _addedEpisodesCache.Find(seriesId.ToString());
|
|
|
|
var previouslyAired = _searchCache.Find(seriesId.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
if (previouslyAired != null && previouslyAired.Any())
|
|
|
|
if (previouslyAired != null && previouslyAired.Any())
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -48,7 +48,7 @@ namespace NzbDrone.Core.Tv
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_addedEpisodesCache.Remove(seriesId.ToString());
|
|
|
|
_searchCache.Remove(seriesId.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Handle(EpisodeInfoRefreshedEvent message)
|
|
|
|
public void Handle(EpisodeInfoRefreshedEvent message)
|
|
|
@ -61,29 +61,39 @@ namespace NzbDrone.Core.Tv
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (message.Added.Empty())
|
|
|
|
var previouslyAired = message.Added.Where(a =>
|
|
|
|
|
|
|
|
a.AirDateUtc.HasValue &&
|
|
|
|
|
|
|
|
a.AirDateUtc.Value.Between(DateTime.UtcNow.AddDays(-14), DateTime.UtcNow.AddDays(1)) &&
|
|
|
|
|
|
|
|
a.Monitored)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (previouslyAired.Empty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Debug("No new episodes, skipping search");
|
|
|
|
_logger.Debug("Newly added episodes all air in the future");
|
|
|
|
return;
|
|
|
|
_searchCache.Set(message.Series.Id.ToString(), previouslyAired.Select(e => e.Id).ToList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (message.Added.None(a => a.AirDateUtc.HasValue))
|
|
|
|
var absoluteEpisodeNumberAdded = message.Updated.Where(a =>
|
|
|
|
|
|
|
|
a.AbsoluteEpisodeNumberAdded &&
|
|
|
|
|
|
|
|
a.AirDateUtc.HasValue &&
|
|
|
|
|
|
|
|
a.AirDateUtc.Value.Between(DateTime.UtcNow.AddDays(-14), DateTime.UtcNow.AddDays(1)) &&
|
|
|
|
|
|
|
|
a.Monitored)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (absoluteEpisodeNumberAdded.Empty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Debug("No new episodes have an air date");
|
|
|
|
_logger.Debug("No updated episodes recently aired and had absolute episode number added");
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var previouslyAired = message.Added.Where(a => a.AirDateUtc.HasValue
|
|
|
|
var toSearch = new List<int>();
|
|
|
|
&& a.AirDateUtc.Value.Between(DateTime.UtcNow.AddDays(-14), DateTime.UtcNow.AddDays(1))
|
|
|
|
|
|
|
|
&& a.Monitored).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (previouslyAired.Empty())
|
|
|
|
toSearch.AddRange(previouslyAired.Select(e => e.Id));
|
|
|
|
|
|
|
|
toSearch.AddRange(absoluteEpisodeNumberAdded.Select(e => e.Id));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (toSearch.Any())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Debug("Newly added episodes all air in the future");
|
|
|
|
_searchCache.Set(message.Series.Id.ToString(), toSearch.Distinct().ToList());
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_addedEpisodesCache.Set(message.Series.Id.ToString(), previouslyAired.Select(e => e.Id).ToList());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|