|
|
@ -3,9 +3,7 @@ using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common.Cache;
|
|
|
|
using NzbDrone.Common.Cache;
|
|
|
|
using NzbDrone.Common.Instrumentation;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
|
|
|
using NzbDrone.Core.Messaging;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
@ -13,35 +11,44 @@ using NzbDrone.Core.Tv.Events;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public interface IXemProvider
|
|
|
|
public class XemService : IExecute<UpdateXemMappingsCommand>, IHandle<SeriesUpdatedEvent>, IHandleAsync<ApplicationStartedEvent>
|
|
|
|
{
|
|
|
|
|
|
|
|
void UpdateMappings();
|
|
|
|
|
|
|
|
void UpdateMappings(int seriesId);
|
|
|
|
|
|
|
|
void UpdateMappings(Series series);
|
|
|
|
|
|
|
|
void PerformUpdate(Series series);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class XemProvider : IXemProvider, IExecute<UpdateXemMappingsCommand>, IHandle<SeriesUpdatedEvent>, IHandleAsync<ApplicationStartedEvent>
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IEpisodeService _episodeService;
|
|
|
|
private readonly IEpisodeService _episodeService;
|
|
|
|
private readonly IXemCommunicationProvider _xemCommunicationProvider;
|
|
|
|
private readonly IXemProxy _xemProxy;
|
|
|
|
private readonly ISeriesService _seriesService;
|
|
|
|
private readonly ISeriesService _seriesService;
|
|
|
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly ICached<bool> _cache;
|
|
|
|
private readonly ICached<bool> _cache;
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly Logger _logger = NzbDroneLogger.GetLogger();
|
|
|
|
public XemService(IEpisodeService episodeService,
|
|
|
|
|
|
|
|
IXemProxy xemProxy,
|
|
|
|
public XemProvider(IEpisodeService episodeService,
|
|
|
|
ISeriesService seriesService, ICacheManger cacheManger, Logger logger)
|
|
|
|
IXemCommunicationProvider xemCommunicationProvider,
|
|
|
|
|
|
|
|
ISeriesService seriesService, ICacheManger cacheManger)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (seriesService == null) throw new ArgumentNullException("seriesService");
|
|
|
|
if (seriesService == null) throw new ArgumentNullException("seriesService");
|
|
|
|
_episodeService = episodeService;
|
|
|
|
_episodeService = episodeService;
|
|
|
|
_xemCommunicationProvider = xemCommunicationProvider;
|
|
|
|
_xemProxy = xemProxy;
|
|
|
|
_seriesService = seriesService;
|
|
|
|
_seriesService = seriesService;
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
_cache = cacheManger.GetCache<bool>(GetType());
|
|
|
|
_cache = cacheManger.GetCache<bool>(GetType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateMappings()
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute(UpdateXemMappingsCommand message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
UpdateMappings();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Handle(SeriesUpdatedEvent message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
UpdateMappings(message.Series);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void HandleAsync(ApplicationStartedEvent message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GetXemSeriesIds();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateMappings()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Trace("Starting scene numbering update");
|
|
|
|
_logger.Trace("Starting scene numbering update");
|
|
|
|
|
|
|
|
|
|
|
@ -66,20 +73,7 @@ namespace NzbDrone.Core.Providers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateMappings(int seriesId)
|
|
|
|
private void UpdateMappings(Series series)
|
|
|
|
{
|
|
|
|
|
|
|
|
var series = _seriesService.GetSeries(seriesId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (series == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Trace("Series could not be found: {0}", seriesId);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdateMappings(series);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateMappings(Series series)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!_cache.Find(series.TvdbId.ToString()))
|
|
|
|
if (!_cache.Find(series.TvdbId.ToString()))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -90,17 +84,18 @@ namespace NzbDrone.Core.Providers
|
|
|
|
PerformUpdate(series);
|
|
|
|
PerformUpdate(series);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void PerformUpdate(Series series)
|
|
|
|
private void PerformUpdate(Series series)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Trace("Updating scene numbering mapping for: {0}", series);
|
|
|
|
_logger.Trace("Updating scene numbering mapping for: {0}", series);
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var episodesToUpdate = new List<Episode>();
|
|
|
|
var episodesToUpdate = new List<Episode>();
|
|
|
|
var mappings = _xemCommunicationProvider.GetSceneTvdbMappings(series.TvdbId);
|
|
|
|
var mappings = _xemProxy.GetSceneTvdbMappings(series.TvdbId);
|
|
|
|
|
|
|
|
|
|
|
|
if (mappings == null)
|
|
|
|
if (!mappings.Any())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Trace("Mappings for: {0} are null, skipping", series);
|
|
|
|
_logger.Trace("Mappings for: {0} are empty, skipping", series);
|
|
|
|
|
|
|
|
_cache.Remove(series.TvdbId.ToString());
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -142,7 +137,7 @@ namespace NzbDrone.Core.Providers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_cache.Clear();
|
|
|
|
_cache.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
var ids = _xemCommunicationProvider.GetXemSeriesIds();
|
|
|
|
var ids = _xemProxy.GetXemSeriesIds();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var id in ids)
|
|
|
|
foreach (var id in ids)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -151,27 +146,5 @@ namespace NzbDrone.Core.Providers
|
|
|
|
|
|
|
|
|
|
|
|
return ids;
|
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute(UpdateXemMappingsCommand message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (message.SeriesId.HasValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
UpdateMappings(message.SeriesId.Value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
UpdateMappings();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Handle(SeriesUpdatedEvent message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
UpdateMappings(message.Series);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void HandleAsync(ApplicationStartedEvent message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GetXemSeriesIds();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|