diff --git a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs index 8128ffe6a..2736ce723 100644 --- a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs @@ -27,6 +27,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene { private readonly ISceneMappingRepository _repository; private readonly IEnumerable _sceneMappingProviders; + private readonly IEventAggregator _eventAggregator; private readonly Logger _logger; private readonly ICached _getTvdbIdCache; private readonly ICached> _findByTvdbIdCache; @@ -34,10 +35,12 @@ namespace NzbDrone.Core.DataAugmentation.Scene public SceneMappingService(ISceneMappingRepository repository, ICacheManager cacheManager, IEnumerable sceneMappingProviders, + IEventAggregator eventAggregator, Logger logger) { _repository = repository; _sceneMappingProviders = sceneMappingProviders; + _eventAggregator = eventAggregator; _getTvdbIdCache = cacheManager.GetCache(GetType(), "tvdb_id"); _findByTvdbIdCache = cacheManager.GetCache>(GetType(), "find_tvdb_id"); @@ -129,6 +132,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene } RefreshCache(); + _eventAggregator.PublishEvent(new SceneMappingsUpdatedEvent()); } private SceneMapping FindTvdbId(string title) diff --git a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingsUpdatedEvent.cs b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingsUpdatedEvent.cs new file mode 100644 index 000000000..06f6d4a3f --- /dev/null +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingsUpdatedEvent.cs @@ -0,0 +1,8 @@ +using NzbDrone.Common.Messaging; + +namespace NzbDrone.Core.DataAugmentation.Scene +{ + public class SceneMappingsUpdatedEvent : IEvent + { + } +} diff --git a/src/NzbDrone.Core/Download/DownloadTrackingService.cs b/src/NzbDrone.Core/Download/DownloadTrackingService.cs index ed8f4d156..f107dce25 100644 --- a/src/NzbDrone.Core/Download/DownloadTrackingService.cs +++ b/src/NzbDrone.Core/Download/DownloadTrackingService.cs @@ -5,6 +5,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.Cache; using NzbDrone.Core.Configuration; +using NzbDrone.Core.DataAugmentation.Scene; using NzbDrone.Core.History; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; @@ -25,7 +26,8 @@ namespace NzbDrone.Core.Download public class DownloadTrackingService : IDownloadTrackingService, IExecute, IHandleAsync, - IHandle + IHandle, + IHandle { private readonly IProvideDownloadClient _downloadClientProvider; private readonly IHistoryService _historyService; @@ -152,8 +154,7 @@ namespace NzbDrone.Core.Download if (newTrackedDownloads.ContainsKey(trackingId)) continue; - //TODO: Rebuilding the tracked download when it is a warning is a total hack to deal with updated scene mappings - if (!oldTrackedDownloads.TryGetValue(trackingId, out trackedDownload) || trackedDownload.Status == TrackedDownloadStatus.Warning) + if (!oldTrackedDownloads.TryGetValue(trackingId, out trackedDownload)) { trackedDownload = GetTrackedDownload(trackingId, downloadClient.Definition.Id, downloadItem, grabbedHistory); @@ -244,7 +245,6 @@ namespace NzbDrone.Core.Download Status = TrackedDownloadStatus.Ok, }; - try { var historyItems = grabbedHistory.Where(h => @@ -298,5 +298,18 @@ namespace NzbDrone.Core.Download { ProcessTrackedDownloads(); } + + public void Handle(SceneMappingsUpdatedEvent message) + { + var grabbedHistory = _historyService.Grabbed(); + + foreach (var trackedDownload in GetTrackedDownloads().Where(t => t.Status == TrackedDownloadStatus.Warning)) + { + var newTrackedDownload = GetTrackedDownload(trackedDownload.TrackingId, trackedDownload.DownloadClient, trackedDownload.DownloadItem, grabbedHistory); + + trackedDownload.Status = newTrackedDownload.Status; + trackedDownload.StatusMessages = newTrackedDownload.StatusMessages; + } + } } } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 245957df6..93fed1c08 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -135,6 +135,7 @@ +