diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index 2dd67deb6..a663538b7 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -138,7 +138,7 @@ namespace NzbDrone.Core.Download if (allMoviesImported) { trackedDownload.State = TrackedDownloadState.Imported; - _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); + _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteMovie.Movie.Id)); return true; } @@ -156,7 +156,7 @@ namespace NzbDrone.Core.Download if (allMoviesImportedInHistory) { trackedDownload.State = TrackedDownloadState.Imported; - _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); + _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteMovie.Movie.Id)); return true; } } diff --git a/src/NzbDrone.Core/Download/DownloadCompletedEvent.cs b/src/NzbDrone.Core/Download/DownloadCompletedEvent.cs index 30cfd63c7..9684cdac3 100644 --- a/src/NzbDrone.Core/Download/DownloadCompletedEvent.cs +++ b/src/NzbDrone.Core/Download/DownloadCompletedEvent.cs @@ -6,10 +6,12 @@ namespace NzbDrone.Core.Download public class DownloadCompletedEvent : IEvent { public TrackedDownload TrackedDownload { get; private set; } + public int MovieId { get; set; } - public DownloadCompletedEvent(TrackedDownload trackedDownload) + public DownloadCompletedEvent(TrackedDownload trackedDownload, int movieId) { TrackedDownload = trackedDownload; + MovieId = movieId; } } } diff --git a/src/NzbDrone.Core/Download/DownloadProcessingService.cs b/src/NzbDrone.Core/Download/DownloadProcessingService.cs index 32e11a5ec..a0eb18ec9 100644 --- a/src/NzbDrone.Core/Download/DownloadProcessingService.cs +++ b/src/NzbDrone.Core/Download/DownloadProcessingService.cs @@ -40,7 +40,7 @@ namespace NzbDrone.Core.Download foreach (var trackedDownload in trackedDownloads) { - _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); + _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteMovie.Movie.Id)); } } diff --git a/src/NzbDrone.Core/Download/History/DownloadHistoryService.cs b/src/NzbDrone.Core/Download/History/DownloadHistoryService.cs index 080ad9a7b..c657469d8 100644 --- a/src/NzbDrone.Core/Download/History/DownloadHistoryService.cs +++ b/src/NzbDrone.Core/Download/History/DownloadHistoryService.cs @@ -85,6 +85,12 @@ namespace NzbDrone.Core.Download.History public void Handle(MovieGrabbedEvent message) { + // Don't store grabbed events for clients that don't download IDs + if (message.DownloadId.IsNullOrWhiteSpace()) + { + return; + } + var history = new DownloadHistory { EventType = DownloadHistoryEventType.DownloadGrabbed, @@ -149,7 +155,7 @@ namespace NzbDrone.Core.Download.History var history = new DownloadHistory { EventType = DownloadHistoryEventType.DownloadImported, - MovieId = message.TrackedDownload.RemoteMovie.Movie.Id, + MovieId = message.MovieId, DownloadId = message.TrackedDownload.DownloadItem.DownloadId, SourceTitle = message.TrackedDownload.DownloadItem.OutputPath.ToString(), Date = DateTime.UtcNow, diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportService.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportService.cs index 651b0b1e4..a74ac0015 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportService.cs @@ -301,21 +301,22 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Manual { var trackedDownload = groupedTrackedDownload.First().TrackedDownload; + var importMovie = groupedTrackedDownload.First().ImportResult.ImportDecision.LocalMovie.Movie; + if (_diskProvider.FolderExists(trackedDownload.DownloadItem.OutputPath.FullPath)) { if (_downloadedMovieImportService.ShouldDeleteFolder( new DirectoryInfo(trackedDownload.DownloadItem.OutputPath.FullPath), - trackedDownload.RemoteMovie.Movie) && trackedDownload.DownloadItem.CanMoveFiles) + importMovie) && trackedDownload.DownloadItem.CanMoveFiles) { _diskProvider.DeleteFolder(trackedDownload.DownloadItem.OutputPath.FullPath, true); } } - //TODO: trackedDownload.RemoteMovie.Movie.Count is always 1? - if (groupedTrackedDownload.Select(c => c.ImportResult).Count(c => c.Result == ImportResultType.Imported) >= Math.Max(1, 1)) + if (groupedTrackedDownload.Select(c => c.ImportResult).Count(c => c.Result == ImportResultType.Imported) >= 1) { trackedDownload.State = TrackedDownloadState.Imported; - _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); + _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, importMovie.Id)); } } }