mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Use an event to update title mismatches
This commit is contained in:
parent
3c1df5693c
commit
907aa4a0ba
@ -27,6 +27,7 @@ public class SceneMappingService : ISceneMappingService,
|
||||
{
|
||||
private readonly ISceneMappingRepository _repository;
|
||||
private readonly IEnumerable<ISceneMappingProvider> _sceneMappingProviders;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly Logger _logger;
|
||||
private readonly ICached<SceneMapping> _getTvdbIdCache;
|
||||
private readonly ICached<List<SceneMapping>> _findByTvdbIdCache;
|
||||
@ -34,10 +35,12 @@ public class SceneMappingService : ISceneMappingService,
|
||||
public SceneMappingService(ISceneMappingRepository repository,
|
||||
ICacheManager cacheManager,
|
||||
IEnumerable<ISceneMappingProvider> sceneMappingProviders,
|
||||
IEventAggregator eventAggregator,
|
||||
Logger logger)
|
||||
{
|
||||
_repository = repository;
|
||||
_sceneMappingProviders = sceneMappingProviders;
|
||||
_eventAggregator = eventAggregator;
|
||||
|
||||
_getTvdbIdCache = cacheManager.GetCache<SceneMapping>(GetType(), "tvdb_id");
|
||||
_findByTvdbIdCache = cacheManager.GetCache<List<SceneMapping>>(GetType(), "find_tvdb_id");
|
||||
@ -129,6 +132,7 @@ private void UpdateMappings()
|
||||
}
|
||||
|
||||
RefreshCache();
|
||||
_eventAggregator.PublishEvent(new SceneMappingsUpdatedEvent());
|
||||
}
|
||||
|
||||
private SceneMapping FindTvdbId(string title)
|
||||
|
@ -0,0 +1,8 @@
|
||||
using NzbDrone.Common.Messaging;
|
||||
|
||||
namespace NzbDrone.Core.DataAugmentation.Scene
|
||||
{
|
||||
public class SceneMappingsUpdatedEvent : IEvent
|
||||
{
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
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 @@ public interface IDownloadTrackingService
|
||||
public class DownloadTrackingService : IDownloadTrackingService,
|
||||
IExecute<CheckForFinishedDownloadCommand>,
|
||||
IHandleAsync<ApplicationStartedEvent>,
|
||||
IHandle<EpisodeGrabbedEvent>
|
||||
IHandle<EpisodeGrabbedEvent>,
|
||||
IHandle<SceneMappingsUpdatedEvent>
|
||||
{
|
||||
private readonly IProvideDownloadClient _downloadClientProvider;
|
||||
private readonly IHistoryService _historyService;
|
||||
@ -152,8 +154,7 @@ private Boolean UpdateTrackedDownloads(List<History.History> grabbedHistory)
|
||||
|
||||
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 @@ private TrackedDownload GetTrackedDownload(String trackingId, Int32 downloadClie
|
||||
Status = TrackedDownloadStatus.Ok,
|
||||
};
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var historyItems = grabbedHistory.Where(h =>
|
||||
@ -298,5 +298,18 @@ public void Handle(EpisodeGrabbedEvent message)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,6 +135,7 @@
|
||||
<Compile Include="DataAugmentation\Scene\SceneMappingProxy.cs" />
|
||||
<Compile Include="DataAugmentation\Scene\SceneMappingRepository.cs" />
|
||||
<Compile Include="DataAugmentation\Scene\SceneMappingService.cs" />
|
||||
<Compile Include="DataAugmentation\Scene\SceneMappingsUpdatedEvent.cs" />
|
||||
<Compile Include="DataAugmentation\Scene\ServicesProvider.cs" />
|
||||
<Compile Include="DataAugmentation\Scene\UpdateSceneMappingCommand.cs" />
|
||||
<Compile Include="DataAugmentation\Xem\Model\XemResult.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user