diff --git a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateSubtitleInfoFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateSubtitleInfoFixture.cs index 54a98c7b5..cf505732c 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateSubtitleInfoFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateSubtitleInfoFixture.cs @@ -9,13 +9,13 @@ namespace NzbDrone.Core.Test.MediaFiles.movieImport.Aggregation.Aggregators [TestFixture] public class AggregateSubtitleInfoFixture : CoreTest { - [TestCase("Name (2020)/Name (2020) - [AAC 2.0].mkv", "", "Name (2020) - [AAC 2.0].default.eng.forced.ass")] - [TestCase("Name (2020)/Name (2020) - [AAC 2.0].mkv", "", "Name (2020) - [AAC 2.0].eng.default.ass")] - [TestCase("Name (2020)/Name (2020) - [AAC 2.0].mkv", "", "Name (2020) - [AAC 2.0].fra.ass")] - [TestCase("", "Name (2020)/Name (2020) - [AAC 2.0].mkv", "Name (2020) - [AAC 2.0].default.eng.forced.ass")] - [TestCase("", "Name (2020)/Name (2020) - [AAC 2.0].mkv", "Name (2020) - [AAC 2.0].eng.default.ass")] - [TestCase("", "Name (2020)/Name (2020) - [AAC 2.0].mkv", "Name (2020) - [AAC 2.0].fra.ass")] - public void should_do_basic_parse(string relativePath, string originalFilePath, string path) + [TestCase("Name (2020)/Name (2020) - [AAC 2.0].mkv", "", "Name (2020) - [AAC 2.0].default.eng.forced.ass", null)] + [TestCase("Name (2020)/Name (2020) - [AAC 2.0].mkv", "", "Name (2020) - [AAC 2.0].eng.default.ass", null)] + [TestCase("Name (2020)/Name (2020) - [AAC 2.0].mkv", "", "Name (2020) - [AAC 2.0].fra.ass", null)] + [TestCase("", "Name (2020)/Name (2020) - [AAC 2.0].mkv", "Name (2020) - [AAC 2.0].default.eng.forced.ass", "Name (2020)/Name (2020) - [FLAC 2.0].mkv")] + [TestCase("", "Name (2020)/Name (2020) - [AAC 2.0].mkv", "Name (2020) - [AAC 2.0].eng.default.ass", null)] + [TestCase("", "Name (2020)/Name (2020) - [AAC 2.0].mkv", "Name (2020) - [AAC 2.0].fra.ass", null)] + public void should_do_basic_parse(string relativePath, string originalFilePath, string path, string fileNameBeforeRename) { var movieFile = new MovieFile { @@ -23,7 +23,7 @@ namespace NzbDrone.Core.Test.MediaFiles.movieImport.Aggregation.Aggregators OriginalFilePath = originalFilePath }; - var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(movieFile, path); + var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(movieFile, path, fileNameBeforeRename); subtitleTitleInfo.Title.Should().BeNull(); subtitleTitleInfo.Copy.Should().Be(0); @@ -40,7 +40,7 @@ namespace NzbDrone.Core.Test.MediaFiles.movieImport.Aggregation.Aggregators RelativePath = relativePath }; - var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(movieFile, path); + var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(movieFile, path, null); subtitleTitleInfo.LanguageTags.Should().NotContain("default"); } diff --git a/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs b/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs index ecc10d88f..eccbda7f4 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, bool keepExistingEntries); + List ImportExtraFiles(Movie movie, List possibleExtraFiles, string fileNameBeforeRename); } public class ExistingExtraFileService : IExistingExtraFiles, IHandle @@ -25,7 +25,7 @@ namespace NzbDrone.Core.Extras _logger = logger; } - public List ImportExtraFiles(Movie movie, List possibleExtraFiles, bool keepExistingEntries) + public List ImportExtraFiles(Movie movie, List possibleExtraFiles, string fileNameBeforeRename) { _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, keepExistingEntries); + var imported = existingExtraFileImporter.ProcessFiles(movie, possibleExtraFiles, importedFiles, fileNameBeforeRename); 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, false); + var importedFiles = ImportExtraFiles(movie, possibleExtraFiles, null); _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 be64af03c..08a8c3fd9 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, bool keepExistingEntries); + IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, string fileNameBeforeRename); } } diff --git a/src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs b/src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs index c3327a72b..f9f2560b3 100644 --- a/src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs +++ b/src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Core.Extras } public abstract int Order { get; } - public abstract IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, bool keepExistingEntries); + public abstract IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, string fileNameBeforeRename); public virtual ImportExistingExtraFileFilterResult FilterAndClean(Movie movie, List filesOnDisk, List importedFiles, bool keepExistingEntries) { diff --git a/src/NzbDrone.Core/Extras/Metadata/ExistingMetadataImporter.cs b/src/NzbDrone.Core/Extras/Metadata/ExistingMetadataImporter.cs index dd3795c02..bbdb2ad9e 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, bool keepExistingEntries) + public override IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, string fileNameBeforeRename) { _logger.Debug("Looking for existing metadata in {0}", movie.Path); var metadataFiles = new List(); - var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries); + var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, fileNameBeforeRename is not null); 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 6a440f43c..52cf720ff 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, bool keepExistingEntries) + public override IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, string fileNameBeforeRename) { _logger.Debug("Looking for existing extra files in {0}", movie.Path); var extraFiles = new List(); - var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries); + var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, fileNameBeforeRename is not null); 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 a8062130b..8af771811 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, bool keepExistingEntries) + public override IEnumerable ProcessFiles(Movie movie, List filesOnDisk, List importedFiles, string fileNameBeforeRename) { _logger.Debug("Looking for existing subtitle files in {0}", movie.Path); var subtitleFiles = new List(); - var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries); + var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, fileNameBeforeRename is not null); foreach (var possibleSubtitleFile in filterResult.FilesOnDisk) { @@ -57,7 +57,8 @@ namespace NzbDrone.Core.Extras.Subtitles { FileMovieInfo = minimalInfo, Movie = movie, - Path = possibleSubtitleFile + Path = possibleSubtitleFile, + FileNameBeforeRename = fileNameBeforeRename }; try diff --git a/src/NzbDrone.Core/MediaFiles/MovieFileMovingService.cs b/src/NzbDrone.Core/MediaFiles/MovieFileMovingService.cs index d9dc5dbf3..b198697fd 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieFileMovingService.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieFileMovingService.cs @@ -119,6 +119,11 @@ namespace NzbDrone.Core.MediaFiles movieFile.RelativePath = movie.Path.GetRelativePath(destinationFilePath); + if (localMovie is not null) + { + localMovie.FileNameBeforeRename = movieFile.RelativePath; + } + if (localMovie is not null && _scriptImportDecider.TryImport(movieFilePath, destinationFilePath, localMovie, movieFile, mode) is var scriptImportDecision && scriptImportDecision != ScriptImportDecision.DeferMove) { if (scriptImportDecision == ScriptImportDecision.RenameRequested) @@ -126,7 +131,6 @@ namespace NzbDrone.Core.MediaFiles try { MoveMovieFile(movieFile, movie); - localMovie.FileRenamedAfterScriptImport = true; } catch (SameFilenameException) { diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateSubtitleInfo.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateSubtitleInfo.cs index 606cf2609..77e090b9f 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateSubtitleInfo.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateSubtitleInfo.cs @@ -30,16 +30,16 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators return localMovie; } - localMovie.SubtitleInfo = CleanSubtitleTitleInfo(localMovie.Movie.MovieFile, path); + localMovie.SubtitleInfo = CleanSubtitleTitleInfo(localMovie.Movie.MovieFile, path, localMovie.FileNameBeforeRename); return localMovie; } - public SubtitleTitleInfo CleanSubtitleTitleInfo(MovieFile movieFile, string path) + public SubtitleTitleInfo CleanSubtitleTitleInfo(MovieFile movieFile, string path, string fileNameBeforeRename) { var subtitleTitleInfo = LanguageParser.ParseSubtitleLanguageInformation(path); - var movieFileTitle = Path.GetFileNameWithoutExtension(movieFile.RelativePath); + var movieFileTitle = Path.GetFileNameWithoutExtension(fileNameBeforeRename ?? movieFile.RelativePath); var originalMovieFileTitle = Path.GetFileNameWithoutExtension(movieFile.OriginalFilePath) ?? string.Empty; if (subtitleTitleInfo.TitleFirst && (movieFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase) || originalMovieFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase))) diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs index e0dd83886..4c5301620 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs @@ -155,9 +155,9 @@ namespace NzbDrone.Core.MediaFiles.MovieImport { if (localMovie.ScriptImported) { - _existingExtraFiles.ImportExtraFiles(localMovie.Movie, localMovie.PossibleExtraFiles, true); + _existingExtraFiles.ImportExtraFiles(localMovie.Movie, localMovie.PossibleExtraFiles, localMovie.FileNameBeforeRename); - if (localMovie.FileRenamedAfterScriptImport) + if (localMovie.FileNameBeforeRename != movieFile.RelativePath) { _extraService.MoveFilesAfterRename(localMovie.Movie, movieFile); } diff --git a/src/NzbDrone.Core/Parser/Model/LocalMovie.cs b/src/NzbDrone.Core/Parser/Model/LocalMovie.cs index 6e78538bb..c7f66b933 100644 --- a/src/NzbDrone.Core/Parser/Model/LocalMovie.cs +++ b/src/NzbDrone.Core/Parser/Model/LocalMovie.cs @@ -38,7 +38,7 @@ namespace NzbDrone.Core.Parser.Model public int CustomFormatScore { get; set; } public GrabbedReleaseInfo Release { get; set; } public bool ScriptImported { get; set; } - public bool FileRenamedAfterScriptImport { get; set; } + public string FileNameBeforeRename { get; set; } public bool ShouldImportExtras { get; set; } public List PossibleExtraFiles { get; set; } public SubtitleTitleInfo SubtitleInfo { get; set; }