From 6c413d83ebc0904cbeaeb70d23f0465384f85bdd Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Sat, 14 Jan 2017 14:02:45 -0500 Subject: [PATCH] Simply completed download service --- .../Download/CompletedDownloadService.cs | 153 ++++-------------- 1 file changed, 27 insertions(+), 126 deletions(-) diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index 3b00979dd..bb4eedf4d 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -94,86 +94,18 @@ public void Process(TrackedDownload trackedDownload, bool ignoreWarnings = false return; } - var series = _parsingService.GetSeries(trackedDownload.DownloadItem.Title); - - if (series == null) + var movie = _parsingService.GetMovie(trackedDownload.DownloadItem.Title); + if (movie == null) { if (historyItem != null) { - //series = _seriesService.GetSeries(historyItem.SeriesId); + movie = _movieService.GetMovie(historyItem.MovieId); } - if (series == null) + if (movie == null) { - var movie = _parsingService.GetMovie(trackedDownload.DownloadItem.Title); - - if (movie == null) - { - if (historyItem != null) - { - movie = _movieService.GetMovie(historyItem.MovieId); - if (movie.MovieFile != null) - { - movie.MovieFile.LazyLoad(); - if (movie.MovieFile.Value != null) - { - _logger.Debug("File Title: {0}, download item title: {1}", Parser.Parser.CleanSeriesTitle(movie.MovieFile.Value.RelativePath), Parser.Parser.CleanSeriesTitle(trackedDownload.DownloadItem.Title)); - if (Parser.Parser.CleanSeriesTitle(movie.MovieFile.Value.RelativePath).Contains(Parser.Parser.CleanSeriesTitle(trackedDownload.DownloadItem.Title))) - { - trackedDownload.Warn("Seems like the movie already has a file associated with this download item. Maybe the History failed?"); - return; - } - } - } - } - else - { - var parserResult = Parser.Parser.ParseMovieTitle(trackedDownload.DownloadItem.Title); - if (parserResult != null) - { - movie = _movieService.FindByTitle(parserResult.MovieTitle); - if (movie.MovieFile != null) - { - movie.MovieFile.LazyLoad(); - if (movie.MovieFile.Value != null) - { - _logger.Debug("File Title: {0}, download item title: {1}", Parser.Parser.CleanSeriesTitle(movie.MovieFile.Value.RelativePath), Parser.Parser.CleanSeriesTitle(trackedDownload.DownloadItem.Title)); - if (Parser.Parser.CleanSeriesTitle(movie.MovieFile.Value.RelativePath).Contains(Parser.Parser.CleanSeriesTitle(trackedDownload.DownloadItem.Title))) - { - trackedDownload.Warn("Seems like the movie already has a file associated with this download item. Maybe the History failed?"); - return; - } - } - } - } - - } - - - if (movie == null) - { - trackedDownload.Warn("Movie title mismatch, automatic import is not possible."); - return; - } - } - else - { - if (movie.MovieFile != null) - { - movie.MovieFile.LazyLoad(); - if (movie.MovieFile.Value != null) - { - _logger.Debug("File Title: {0}, download item title: {1}", Parser.Parser.CleanSeriesTitle(movie.MovieFile.Value.RelativePath), Parser.Parser.CleanSeriesTitle(trackedDownload.DownloadItem.Title)); - if (Parser.Parser.CleanSeriesTitle(movie.MovieFile.Value.RelativePath).Contains(Parser.Parser.CleanSeriesTitle(trackedDownload.DownloadItem.Title))) - { - trackedDownload.Warn("Seems like the movie already has a file associated with this download item. Maybe the History failed?"); - return; - } - } - } - } - //trackedDownload.Warn("Series title mismatch, automatic import is not possible."); - //return; + trackedDownload.Warn("Movie title mismatch, automatic import is not possible."); + return; } } } @@ -184,61 +116,30 @@ public void Process(TrackedDownload trackedDownload, bool ignoreWarnings = false private void Import(TrackedDownload trackedDownload) { var outputPath = trackedDownload.DownloadItem.OutputPath.FullPath; - if (trackedDownload.RemoteMovie != null && trackedDownload.RemoteMovie.Movie != null) + var importResults = _downloadedMovieImportService.ProcessPath(outputPath, ImportMode.Auto, trackedDownload.RemoteMovie.Movie, trackedDownload.DownloadItem); + + if (importResults.Empty()) { - var importResults = _downloadedMovieImportService.ProcessPath(outputPath, ImportMode.Auto, trackedDownload.RemoteMovie.Movie, trackedDownload.DownloadItem); - - if (importResults.Empty()) - { - trackedDownload.Warn("No files found are eligible for import in {0}", outputPath); - return; - } - - if (importResults.Count(c => c.Result == ImportResultType.Imported) >= 1) - { - trackedDownload.State = TrackedDownloadStage.Imported; - _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); - return; - } - - if (importResults.Any(c => c.Result != ImportResultType.Imported)) - { - var statusMessages = importResults - .Where(v => v.Result != ImportResultType.Imported) - .Select(v => new TrackedDownloadStatusMessage(Path.GetFileName(v.ImportDecision.LocalEpisode.Path), v.Errors)) - .ToArray(); - - trackedDownload.Warn(statusMessages); - } - } - else if (trackedDownload.RemoteEpisode != null && trackedDownload.RemoteEpisode.Series != null) - { - var importResults = _downloadedEpisodesImportService.ProcessPath(outputPath, ImportMode.Auto, trackedDownload.RemoteEpisode.Series, trackedDownload.DownloadItem); - - if (importResults.Empty()) - { - trackedDownload.Warn("No files found are eligible for import in {0}", outputPath); - return; - } - - if (importResults.Count(c => c.Result == ImportResultType.Imported) >= Math.Max(1, trackedDownload.RemoteEpisode.Episodes.Count)) - { - trackedDownload.State = TrackedDownloadStage.Imported; - _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); - return; - } - - if (importResults.Any(c => c.Result != ImportResultType.Imported)) - { - var statusMessages = importResults - .Where(v => v.Result != ImportResultType.Imported) - .Select(v => new TrackedDownloadStatusMessage(Path.GetFileName(v.ImportDecision.LocalEpisode.Path), v.Errors)) - .ToArray(); - - trackedDownload.Warn(statusMessages); - } + trackedDownload.Warn("No files found are eligible for import in {0}", outputPath); + return; } + if (importResults.Count(c => c.Result == ImportResultType.Imported) >= 1) + { + trackedDownload.State = TrackedDownloadStage.Imported; + _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); + return; + } + + if (importResults.Any(c => c.Result != ImportResultType.Imported)) + { + var statusMessages = importResults + .Where(v => v.Result != ImportResultType.Imported) + .Select(v => new TrackedDownloadStatusMessage(Path.GetFileName(v.ImportDecision.LocalEpisode.Path), v.Errors)) + .ToArray(); + + trackedDownload.Warn(statusMessages); + } } } }