Do not remove all extras when script importing

(cherry picked from commit 0a7f3a12c2be783c6374864e1e8f49ff5e969166)
pull/9399/merge
Jendrik Weise 8 months ago committed by Bogdan
parent b062a46cbd
commit 0a9ae45ed1

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Extras
{
public interface IExistingExtraFiles
{
List<string> ImportExtraFiles(Movie movie, List<string> possibleExtraFiles);
List<string> ImportExtraFiles(Movie movie, List<string> possibleExtraFiles, bool keepExistingEntries);
}
public class ExistingExtraFileService : IExistingExtraFiles, IHandle<MovieScannedEvent>
@ -25,7 +25,7 @@ namespace NzbDrone.Core.Extras
_logger = logger;
}
public List<string> ImportExtraFiles(Movie movie, List<string> possibleExtraFiles)
public List<string> ImportExtraFiles(Movie movie, List<string> 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);
}

@ -7,6 +7,6 @@ namespace NzbDrone.Core.Extras
public interface IImportExistingExtraFiles
{
int Order { get; }
IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles);
IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries);
}
}

@ -19,10 +19,15 @@ namespace NzbDrone.Core.Extras
}
public abstract int Order { get; }
public abstract IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles);
public abstract IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries);
public virtual ImportExistingExtraFileFilterResult<TExtraFile> FilterAndClean(Movie movie, List<string> filesOnDisk, List<string> importedFiles)
public virtual ImportExistingExtraFileFilterResult<TExtraFile> FilterAndClean(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries)
{
if (keepExistingEntries)
{
return Filter(movie, filesOnDisk, importedFiles, new List<TExtraFile>());
}
var movieFiles = _extraFileService.GetFilesByMovie(movie.Id);
Clean(movie, filesOnDisk, importedFiles, movieFiles);

@ -31,12 +31,12 @@ namespace NzbDrone.Core.Extras.Metadata
public override int Order => 0;
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles)
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries)
{
_logger.Debug("Looking for existing metadata in {0}", movie.Path);
var metadataFiles = new List<MetadataFile>();
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles);
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries);
foreach (var possibleMetadataFile in filterResult.FilesOnDisk)
{

@ -27,12 +27,12 @@ namespace NzbDrone.Core.Extras.Others
public override int Order => 2;
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles)
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries)
{
_logger.Debug("Looking for existing extra files in {0}", movie.Path);
var extraFiles = new List<OtherExtraFile>();
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles);
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries);
foreach (var possibleExtraFile in filterResult.FilesOnDisk)
{

@ -32,12 +32,12 @@ namespace NzbDrone.Core.Extras.Subtitles
public override int Order => 1;
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles)
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries)
{
_logger.Debug("Looking for existing subtitle files in {0}", movie.Path);
var subtitleFiles = new List<SubtitleFile>();
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles);
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries);
foreach (var possibleSubtitleFile in filterResult.FilesOnDisk)
{

@ -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)
{

Loading…
Cancel
Save