From af5a681ab7edf7f72544647c490216907853d77d Mon Sep 17 00:00:00 2001 From: Jendrik Weise Date: Sun, 24 Mar 2024 15:08:59 +0100 Subject: [PATCH] Fix ignoring title based on pre-rename episodefile --- .../AggregateSubtitleInfoFixture.cs | 19 ++++++++++--------- .../Extras/ExistingExtraFileService.cs | 8 ++++---- .../Extras/IImportExistingExtraFiles.cs | 2 +- .../Extras/ImportExistingExtraFilesBase.cs | 2 +- .../Metadata/ExistingMetadataImporter.cs | 4 ++-- .../Others/ExistingOtherExtraImporter.cs | 4 ++-- .../Subtitles/ExistingSubtitleImporter.cs | 7 ++++--- .../MediaFiles/EpisodeFileMovingService.cs | 2 +- .../Aggregators/AggregateSubtitleInfo.cs | 6 +++--- .../EpisodeImport/ImportApprovedEpisodes.cs | 4 ++-- .../Parser/Model/LocalEpisode.cs | 2 +- 11 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateSubtitleInfoFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateSubtitleInfoFixture.cs index d5e4a472a..201537188 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateSubtitleInfoFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateSubtitleInfoFixture.cs @@ -9,13 +9,14 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators [TestFixture] public class AggregateSubtitleInfoFixture : CoreTest { - [TestCase("Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "", "Name (2020) - S01E20 - [AAC 2.0].default.eng.forced.ass")] - [TestCase("Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "", "Name (2020) - S01E20 - [AAC 2.0].eng.default.ass")] - [TestCase("Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "", "Name (2020) - S01E20 - [AAC 2.0].fra.ass")] - [TestCase("", "Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "Name (2020) - S01E20 - [AAC 2.0].default.eng.forced.ass")] - [TestCase("", "Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "Name (2020) - S01E20 - [AAC 2.0].eng.default.ass")] - [TestCase("", "Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "Name (2020) - S01E20 - [AAC 2.0].fra.ass")] - public void should_do_basic_parse(string relativePath, string originalFilePath, string path) + [TestCase("Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "", "Name (2020) - S01E20 - [AAC 2.0].default.eng.forced.ass", null)] + [TestCase("Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "", "Name (2020) - S01E20 - [AAC 2.0].eng.default.ass", null)] + [TestCase("Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "", "Name (2020) - S01E20 - [AAC 2.0].fra.ass", null)] + [TestCase("Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 5.1].mkv", "", "Name (2020) - S01E20 - [FLAC 2.0].fra.ass", "Name (2020)/Season 1/Name (2020) - S01E20 - [FLAC 2.0].mkv")] + [TestCase("", "Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "Name (2020) - S01E20 - [AAC 2.0].default.eng.forced.ass", null)] + [TestCase("", "Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "Name (2020) - S01E20 - [AAC 2.0].eng.default.ass", null)] + [TestCase("", "Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "Name (2020) - S01E20 - [AAC 2.0].fra.ass", null)] + public void should_do_basic_parse(string relativePath, string originalFilePath, string path, string fileNameBeforeRename) { var episodeFile = new EpisodeFile { @@ -23,7 +24,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators OriginalFilePath = originalFilePath }; - var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(episodeFile, path); + var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(episodeFile, path, fileNameBeforeRename); subtitleTitleInfo.Title.Should().BeNull(); subtitleTitleInfo.Copy.Should().Be(0); @@ -40,7 +41,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators RelativePath = relativePath }; - var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(episodeFile, path); + var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(episodeFile, path, null); subtitleTitleInfo.LanguageTags.Should().NotContain("default"); } diff --git a/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs b/src/NzbDrone.Core/Extras/ExistingExtraFileService.cs index 14aba7b31..d357c5ba6 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(Series series, List possibleExtraFiles, bool keepExistingEntries); + List ImportExtraFiles(Series series, List possibleExtraFiles, string fileNameBeforeRename); } public class ExistingExtraFileService : IExistingExtraFiles, IHandle @@ -25,7 +25,7 @@ namespace NzbDrone.Core.Extras _logger = logger; } - public List ImportExtraFiles(Series series, List possibleExtraFiles, bool keepExistingEntries) + public List ImportExtraFiles(Series series, List possibleExtraFiles, string fileNameBeforeRename) { _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, keepExistingEntries); + var imported = existingExtraFileImporter.ProcessFiles(series, possibleExtraFiles, importedFiles, fileNameBeforeRename); 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, false); + var importedFiles = ImportExtraFiles(series, 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 d2dd17265..97b85d80f 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(Series series, List filesOnDisk, List importedFiles, bool keepExistingEntries); + IEnumerable ProcessFiles(Series series, List filesOnDisk, List importedFiles, string fileNameBeforeRename); } } diff --git a/src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs b/src/NzbDrone.Core/Extras/ImportExistingExtraFilesBase.cs index c45f2dbc8..c3ae44cba 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(Series series, List filesOnDisk, List importedFiles, bool keepExistingEntries); + public abstract IEnumerable ProcessFiles(Series series, List filesOnDisk, List importedFiles, string fileNameBeforeRename); public virtual ImportExistingExtraFileFilterResult FilterAndClean(Series series, 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 42c1dc1ae..373282259 100644 --- a/src/NzbDrone.Core/Extras/Metadata/ExistingMetadataImporter.cs +++ b/src/NzbDrone.Core/Extras/Metadata/ExistingMetadataImporter.cs @@ -33,12 +33,12 @@ namespace NzbDrone.Core.Extras.Metadata public override int Order => 0; - public override IEnumerable ProcessFiles(Series series, List filesOnDisk, List importedFiles, bool keepExistingEntries) + public override IEnumerable ProcessFiles(Series series, List filesOnDisk, List importedFiles, string fileNameBeforeRename) { _logger.Debug("Looking for existing metadata in {0}", series.Path); var metadataFiles = new List(); - var filterResult = FilterAndClean(series, filesOnDisk, importedFiles, keepExistingEntries); + var filterResult = FilterAndClean(series, 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 1ac074394..ea8d021de 100644 --- a/src/NzbDrone.Core/Extras/Others/ExistingOtherExtraImporter.cs +++ b/src/NzbDrone.Core/Extras/Others/ExistingOtherExtraImporter.cs @@ -28,12 +28,12 @@ namespace NzbDrone.Core.Extras.Others public override int Order => 2; - public override IEnumerable ProcessFiles(Series series, List filesOnDisk, List importedFiles, bool keepExistingEntries) + public override IEnumerable ProcessFiles(Series series, List filesOnDisk, List importedFiles, string fileNameBeforeRename) { _logger.Debug("Looking for existing extra files in {0}", series.Path); var extraFiles = new List(); - var filterResult = FilterAndClean(series, filesOnDisk, importedFiles, keepExistingEntries); + var filterResult = FilterAndClean(series, 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 9ca3f3e67..631c92be3 100644 --- a/src/NzbDrone.Core/Extras/Subtitles/ExistingSubtitleImporter.cs +++ b/src/NzbDrone.Core/Extras/Subtitles/ExistingSubtitleImporter.cs @@ -29,12 +29,12 @@ namespace NzbDrone.Core.Extras.Subtitles public override int Order => 1; - public override IEnumerable ProcessFiles(Series series, List filesOnDisk, List importedFiles, bool keepExistingEntries) + public override IEnumerable ProcessFiles(Series series, List filesOnDisk, List importedFiles, string fileNameBeforeRename) { _logger.Debug("Looking for existing subtitle files in {0}", series.Path); var subtitleFiles = new List(); - var filterResult = FilterAndClean(series, filesOnDisk, importedFiles, keepExistingEntries); + var filterResult = FilterAndClean(series, filesOnDisk, importedFiles, fileNameBeforeRename is not null); foreach (var possibleSubtitleFile in filterResult.FilesOnDisk) { @@ -46,7 +46,8 @@ namespace NzbDrone.Core.Extras.Subtitles { FileEpisodeInfo = Parser.Parser.ParsePath(possibleSubtitleFile), Series = series, - Path = possibleSubtitleFile + Path = possibleSubtitleFile, + FileNameBeforeRename = fileNameBeforeRename }; try diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs b/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs index dde75161a..e186246ba 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs @@ -122,6 +122,7 @@ namespace NzbDrone.Core.MediaFiles } episodeFile.RelativePath = series.Path.GetRelativePath(destinationFilePath); + localEpisode.FileNameBeforeRename = episodeFile.RelativePath; if (localEpisode is not null && _scriptImportDecider.TryImport(episodeFilePath, destinationFilePath, localEpisode, episodeFile, mode) is var scriptImportDecision && scriptImportDecision != ScriptImportDecision.DeferMove) { @@ -130,7 +131,6 @@ namespace NzbDrone.Core.MediaFiles try { MoveEpisodeFile(episodeFile, series, episodeFile.Episodes); - localEpisode.FileRenamedAfterScriptImport = true; } catch (SameFilenameException) { diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateSubtitleInfo.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateSubtitleInfo.cs index 65eaf0cca..53418a6ff 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateSubtitleInfo.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateSubtitleInfo.cs @@ -38,16 +38,16 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators var firstEpisode = localEpisode.Episodes.First(); var episodeFile = firstEpisode.EpisodeFile.Value; - localEpisode.SubtitleInfo = CleanSubtitleTitleInfo(episodeFile, path); + localEpisode.SubtitleInfo = CleanSubtitleTitleInfo(episodeFile, path, localEpisode.FileNameBeforeRename); return localEpisode; } - public SubtitleTitleInfo CleanSubtitleTitleInfo(EpisodeFile episodeFile, string path) + public SubtitleTitleInfo CleanSubtitleTitleInfo(EpisodeFile episodeFile, string path, string fileNameBeforeRename) { var subtitleTitleInfo = LanguageParser.ParseSubtitleLanguageInformation(path); - var episodeFileTitle = Path.GetFileNameWithoutExtension(episodeFile.RelativePath); + var episodeFileTitle = Path.GetFileNameWithoutExtension(fileNameBeforeRename ?? episodeFile.RelativePath); var originalEpisodeFileTitle = Path.GetFileNameWithoutExtension(episodeFile.OriginalFilePath) ?? string.Empty; if (subtitleTitleInfo.TitleFirst && (episodeFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase) || originalEpisodeFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase))) diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs index 030079081..4cdf288fd 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs @@ -176,9 +176,9 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport { if (localEpisode.ScriptImported) { - _existingExtraFiles.ImportExtraFiles(localEpisode.Series, localEpisode.PossibleExtraFiles, true); + _existingExtraFiles.ImportExtraFiles(localEpisode.Series, localEpisode.PossibleExtraFiles, localEpisode.FileNameBeforeRename); - if (localEpisode.FileRenamedAfterScriptImport) + if (localEpisode.FileNameBeforeRename != episodeFile.RelativePath) { _extraService.MoveFilesAfterRename(localEpisode.Series, episodeFile); } diff --git a/src/NzbDrone.Core/Parser/Model/LocalEpisode.cs b/src/NzbDrone.Core/Parser/Model/LocalEpisode.cs index 65f6e84f8..0129c5d0c 100644 --- a/src/NzbDrone.Core/Parser/Model/LocalEpisode.cs +++ b/src/NzbDrone.Core/Parser/Model/LocalEpisode.cs @@ -44,7 +44,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; }