From 0a9ae45ed11b25e57decbc345f2267f3434007b0 Mon Sep 17 00:00:00 2001 From: Jendrik Weise Date: Thu, 21 Mar 2024 02:04:17 +0100 Subject: [PATCH] Do not remove all extras when script importing (cherry picked from commit 0a7f3a12c2be783c6374864e1e8f49ff5e969166) --- src/NzbDrone.Core/Extras/ExistingExtraFileService.cs | 8 ++++---- src/NzbDrone.Core/Extras/IImportExistingExtraFiles.cs | 2 +- src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs | 9 +++++++-- .../Extras/Metadata/ExistingMetadataImporter.cs | 4 ++-- .../Extras/Others/ExistingOtherExtraImporter.cs | 4 ++-- .../Extras/Subtitles/ExistingSubtitleImporter.cs | 4 ++-- .../MediaFiles/MovieImport/ImportApprovedMovie.cs | 2 +- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs b/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs index 3cc759c40..ecc10d88f 100644 --- a/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs +++ b/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.Extras { public interface IExistingExtraFiles { - List ImportExtraFiles(Movie movie, List possibleExtraFiles); + List ImportExtraFiles(Movie movie, List possibleExtraFiles, bool keepExistingEntries); } public class ExistingExtraFileService : IExistingExtraFiles, IHandle @@ -25,7 +25,7 @@ namespace NzbDrone.Core.Extras _logger = logger; } - public List ImportExtraFiles(Movie movie, List possibleExtraFiles) + public List ImportExtraFiles(Movie movie, List possibleExtraFiles, bool keepExistingEntries) { _logger.Debug("Looking for existing extra files in {0}", movie.Path); @@ -33,7 +33,7 @@ namespace NzbDrone.Core.Extras foreach (var existingExtraFileImporter in _existingExtraFileImporters) { - var imported = existingExtraFileImporter.ProcessFiles(movie, possibleExtraFiles, importedFiles); + var imported = existingExtraFileImporter.ProcessFiles(movie, possibleExtraFiles, importedFiles, keepExistingEntries); importedFiles.AddRange(imported.Select(f => Path.Combine(movie.Path, f.RelativePath))); } @@ -45,7 +45,7 @@ namespace NzbDrone.Core.Extras { var movie = message.Movie; var possibleExtraFiles = message.PossibleExtraFiles; - var importedFiles = ImportExtraFiles(movie, possibleExtraFiles); + var importedFiles = ImportExtraFiles(movie, possibleExtraFiles, false); _logger.Info("Found {0} possible extra files, imported {1} files.", possibleExtraFiles.Count, importedFiles.Count); } diff --git a/src/NzbDrone.Core/Extras/IImportExistingExtraFiles.cs b/src/NzbDrone.Core/Extras/IImportExistingExtraFiles.cs index b81a8bb90..be64af03c 100644 --- a/src/NzbDrone.Core/Extras/IImportExistingExtraFiles.cs +++ b/src/NzbDrone.Core/Extras/IImportExistingExtraFiles.cs @@ -7,6 +7,6 @@ namespace NzbDrone.Core.Extras public interface IImportExistingExtraFiles { int Order { get; } - IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles); + IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, bool keepExistingEntries); } } diff --git a/src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs b/src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs index d5fc47936..f4683ed1a 100644 --- a/src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs +++ b/src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs @@ -19,10 +19,15 @@ namespace NzbDrone.Core.Extras } public abstract int Order { get; } - public abstract IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles); + public abstract IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, bool keepExistingEntries); - public virtual ImportExistingExtraFileFilterResult FilterAndClean(Movie movie, List filesOnDisk, List importedFiles) + public virtual ImportExistingExtraFileFilterResult FilterAndClean(Movie movie, List filesOnDisk, List importedFiles, bool keepExistingEntries) { + if (keepExistingEntries) + { + return Filter(movie, filesOnDisk, importedFiles, new List()); + } + var movieFiles = _extraFileService.GetFilesByMovie(movie.Id); Clean(movie, filesOnDisk, importedFiles, movieFiles); diff --git a/src/NzbDrone.Core/Extras/Metadata/ExistingMetadataImporter.cs b/src/NzbDrone.Core/Extras/Metadata/ExistingMetadataImporter.cs index ec9b28d07..dd3795c02 100644 --- a/src/NzbDrone.Core/Extras/Metadata/ExistingMetadataImporter.cs +++ b/src/NzbDrone.Core/Extras/Metadata/ExistingMetadataImporter.cs @@ -31,12 +31,12 @@ namespace NzbDrone.Core.Extras.Metadata public override int Order => 0; - public override IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles) + public override IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, bool keepExistingEntries) { _logger.Debug("Looking for existing metadata in {0}", movie.Path); var metadataFiles = new List(); - var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles); + var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries); foreach (var possibleMetadataFile in filterResult.FilesOnDisk) { diff --git a/src/NzbDrone.Core/Extras/Others/ExistingOtherExtraImporter.cs b/src/NzbDrone.Core/Extras/Others/ExistingOtherExtraImporter.cs index a30f9fa17..6a440f43c 100644 --- a/src/NzbDrone.Core/Extras/Others/ExistingOtherExtraImporter.cs +++ b/src/NzbDrone.Core/Extras/Others/ExistingOtherExtraImporter.cs @@ -27,12 +27,12 @@ namespace NzbDrone.Core.Extras.Others public override int Order => 2; - public override IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles) + public override IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, bool keepExistingEntries) { _logger.Debug("Looking for existing extra files in {0}", movie.Path); var extraFiles = new List(); - var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles); + var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries); foreach (var possibleExtraFile in filterResult.FilesOnDisk) { diff --git a/src/NzbDrone.Core/Extras/Subtitles/ExistingSubtitleImporter.cs b/src/NzbDrone.Core/Extras/Subtitles/ExistingSubtitleImporter.cs index 66597eb91..a8062130b 100644 --- a/src/NzbDrone.Core/Extras/Subtitles/ExistingSubtitleImporter.cs +++ b/src/NzbDrone.Core/Extras/Subtitles/ExistingSubtitleImporter.cs @@ -32,12 +32,12 @@ namespace NzbDrone.Core.Extras.Subtitles public override int Order => 1; - public override IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles) + public override IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, bool keepExistingEntries) { _logger.Debug("Looking for existing subtitle files in {0}", movie.Path); var subtitleFiles = new List(); - var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles); + var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries); foreach (var possibleSubtitleFile in filterResult.FilesOnDisk) { diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs index ef25f2197..e0dd83886 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs @@ -155,7 +155,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport { if (localMovie.ScriptImported) { - _existingExtraFiles.ImportExtraFiles(localMovie.Movie, localMovie.PossibleExtraFiles); + _existingExtraFiles.ImportExtraFiles(localMovie.Movie, localMovie.PossibleExtraFiles, true); if (localMovie.FileRenamedAfterScriptImport) {