Do not remove all extras when script importing

This commit is contained in:
Jendrik Weise 2024-03-21 02:04:17 +01:00 committed by Mark McDowall
parent 2ef46e5b90
commit 0a7f3a12c2
7 changed files with 19 additions and 14 deletions

View File

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Extras
{
public interface IExistingExtraFiles
{
List<string> ImportExtraFiles(Series series, List<string> possibleExtraFiles);
List<string> ImportExtraFiles(Series series, List<string> possibleExtraFiles, bool keepExistingEntries);
}
public class ExistingExtraFileService : IExistingExtraFiles, IHandle<SeriesScannedEvent>
@ -25,7 +25,7 @@ namespace NzbDrone.Core.Extras
_logger = logger;
}
public List<string> ImportExtraFiles(Series series, List<string> possibleExtraFiles)
public List<string> ImportExtraFiles(Series series, List<string> possibleExtraFiles, bool keepExistingEntries)
{
_logger.Debug("Looking for existing extra files in {0}", series.Path);
@ -33,7 +33,7 @@ namespace NzbDrone.Core.Extras
foreach (var existingExtraFileImporter in _existingExtraFileImporters)
{
var imported = existingExtraFileImporter.ProcessFiles(series, possibleExtraFiles, importedFiles);
var imported = existingExtraFileImporter.ProcessFiles(series, possibleExtraFiles, importedFiles, keepExistingEntries);
importedFiles.AddRange(imported.Select(f => Path.Combine(series.Path, f.RelativePath)));
}
@ -45,7 +45,7 @@ namespace NzbDrone.Core.Extras
{
var series = message.Series;
var possibleExtraFiles = message.PossibleExtraFiles;
var importedFiles = ImportExtraFiles(series, possibleExtraFiles);
var importedFiles = ImportExtraFiles(series, possibleExtraFiles, false);
_logger.Info("Found {0} possible extra files, imported {1} files.", possibleExtraFiles.Count, importedFiles.Count);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -176,7 +176,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
{
if (localEpisode.ScriptImported)
{
_existingExtraFiles.ImportExtraFiles(localEpisode.Series, localEpisode.PossibleExtraFiles);
_existingExtraFiles.ImportExtraFiles(localEpisode.Series, localEpisode.PossibleExtraFiles, true);
if (localEpisode.FileRenamedAfterScriptImport)
{