1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-20 01:42:35 +01:00

Do not remove all extras when script importing

(cherry picked from commit 0a7f3a12c2be783c6374864e1e8f49ff5e969166)
This commit is contained in:
Jendrik Weise 2024-03-21 02:04:17 +01:00 committed by Bogdan
parent b062a46cbd
commit 0a9ae45ed1
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(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 @@ public ExistingExtraFileService(IEnumerable<IImportExistingExtraFiles> existingE
_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 @@ public List<string> ImportExtraFiles(Movie movie, List<string> possibleExtraFile
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 @@ public void Handle(MovieScannedEvent message)
{
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);
}

View File

@ -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);
}
}

View File

@ -19,10 +19,15 @@ public ImportExistingExtraFilesBase(IExtraFileService<TExtraFile> extraFileServi
}
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);

View File

@ -31,12 +31,12 @@ public ExistingMetadataImporter(IExtraFileService<MetadataFile> metadataFileServ
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)
{

View File

@ -27,12 +27,12 @@ public ExistingOtherExtraImporter(IExtraFileService<OtherExtraFile> otherExtraFi
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)
{

View File

@ -32,12 +32,12 @@ public ExistingSubtitleImporter(IExtraFileService<SubtitleFile> subtitleFileServ
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)
{

View File

@ -155,7 +155,7 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
{
if (localMovie.ScriptImported)
{
_existingExtraFiles.ImportExtraFiles(localMovie.Movie, localMovie.PossibleExtraFiles);
_existingExtraFiles.ImportExtraFiles(localMovie.Movie, localMovie.PossibleExtraFiles, true);
if (localMovie.FileRenamedAfterScriptImport)
{