Fix ignoring title based on pre-rename episodefile

This commit is contained in:
Jendrik Weise 2024-03-24 15:08:59 +01:00 committed by Mark McDowall
parent 0a7f3a12c2
commit af5a681ab7
11 changed files with 31 additions and 29 deletions

View File

@ -9,13 +9,14 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators
[TestFixture] [TestFixture]
public class AggregateSubtitleInfoFixture : CoreTest<AggregateSubtitleInfo> public class AggregateSubtitleInfoFixture : CoreTest<AggregateSubtitleInfo>
{ {
[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].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")] [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")] [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 2.0].mkv", "Name (2020) - S01E20 - [AAC 2.0].default.eng.forced.ass")] [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].eng.default.ass")] [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].fra.ass")] [TestCase("", "Name (2020)/Season 1/Name (2020) - S01E20 - [AAC 2.0].mkv", "Name (2020) - S01E20 - [AAC 2.0].eng.default.ass", null)]
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].fra.ass", null)]
public void should_do_basic_parse(string relativePath, string originalFilePath, string path, string fileNameBeforeRename)
{ {
var episodeFile = new EpisodeFile var episodeFile = new EpisodeFile
{ {
@ -23,7 +24,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators
OriginalFilePath = originalFilePath OriginalFilePath = originalFilePath
}; };
var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(episodeFile, path); var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(episodeFile, path, fileNameBeforeRename);
subtitleTitleInfo.Title.Should().BeNull(); subtitleTitleInfo.Title.Should().BeNull();
subtitleTitleInfo.Copy.Should().Be(0); subtitleTitleInfo.Copy.Should().Be(0);
@ -40,7 +41,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators
RelativePath = relativePath RelativePath = relativePath
}; };
var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(episodeFile, path); var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(episodeFile, path, null);
subtitleTitleInfo.LanguageTags.Should().NotContain("default"); subtitleTitleInfo.LanguageTags.Should().NotContain("default");
} }

View File

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Extras
{ {
public interface IExistingExtraFiles public interface IExistingExtraFiles
{ {
List<string> ImportExtraFiles(Series series, List<string> possibleExtraFiles, bool keepExistingEntries); List<string> ImportExtraFiles(Series series, List<string> possibleExtraFiles, string fileNameBeforeRename);
} }
public class ExistingExtraFileService : IExistingExtraFiles, IHandle<SeriesScannedEvent> public class ExistingExtraFileService : IExistingExtraFiles, IHandle<SeriesScannedEvent>
@ -25,7 +25,7 @@ namespace NzbDrone.Core.Extras
_logger = logger; _logger = logger;
} }
public List<string> ImportExtraFiles(Series series, List<string> possibleExtraFiles, bool keepExistingEntries) public List<string> ImportExtraFiles(Series series, List<string> possibleExtraFiles, string fileNameBeforeRename)
{ {
_logger.Debug("Looking for existing extra files in {0}", series.Path); _logger.Debug("Looking for existing extra files in {0}", series.Path);
@ -33,7 +33,7 @@ namespace NzbDrone.Core.Extras
foreach (var existingExtraFileImporter in _existingExtraFileImporters) 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))); importedFiles.AddRange(imported.Select(f => Path.Combine(series.Path, f.RelativePath)));
} }
@ -45,7 +45,7 @@ namespace NzbDrone.Core.Extras
{ {
var series = message.Series; var series = message.Series;
var possibleExtraFiles = message.PossibleExtraFiles; 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); _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 public interface IImportExistingExtraFiles
{ {
int Order { get; } int Order { get; }
IEnumerable<ExtraFile> ProcessFiles(Series series, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries); IEnumerable<ExtraFile> ProcessFiles(Series series, List<string> filesOnDisk, List<string> importedFiles, string fileNameBeforeRename);
} }
} }

View File

@ -19,7 +19,7 @@ namespace NzbDrone.Core.Extras
} }
public abstract int Order { get; } public abstract int Order { get; }
public abstract IEnumerable<ExtraFile> ProcessFiles(Series series, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries); public abstract IEnumerable<ExtraFile> ProcessFiles(Series series, List<string> filesOnDisk, List<string> importedFiles, string fileNameBeforeRename);
public virtual ImportExistingExtraFileFilterResult<TExtraFile> FilterAndClean(Series series, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries) public virtual ImportExistingExtraFileFilterResult<TExtraFile> FilterAndClean(Series series, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries)
{ {

View File

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

View File

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

View File

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

View File

@ -122,6 +122,7 @@ namespace NzbDrone.Core.MediaFiles
} }
episodeFile.RelativePath = series.Path.GetRelativePath(destinationFilePath); 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) 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 try
{ {
MoveEpisodeFile(episodeFile, series, episodeFile.Episodes); MoveEpisodeFile(episodeFile, series, episodeFile.Episodes);
localEpisode.FileRenamedAfterScriptImport = true;
} }
catch (SameFilenameException) catch (SameFilenameException)
{ {

View File

@ -38,16 +38,16 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators
var firstEpisode = localEpisode.Episodes.First(); var firstEpisode = localEpisode.Episodes.First();
var episodeFile = firstEpisode.EpisodeFile.Value; var episodeFile = firstEpisode.EpisodeFile.Value;
localEpisode.SubtitleInfo = CleanSubtitleTitleInfo(episodeFile, path); localEpisode.SubtitleInfo = CleanSubtitleTitleInfo(episodeFile, path, localEpisode.FileNameBeforeRename);
return localEpisode; return localEpisode;
} }
public SubtitleTitleInfo CleanSubtitleTitleInfo(EpisodeFile episodeFile, string path) public SubtitleTitleInfo CleanSubtitleTitleInfo(EpisodeFile episodeFile, string path, string fileNameBeforeRename)
{ {
var subtitleTitleInfo = LanguageParser.ParseSubtitleLanguageInformation(path); 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; var originalEpisodeFileTitle = Path.GetFileNameWithoutExtension(episodeFile.OriginalFilePath) ?? string.Empty;
if (subtitleTitleInfo.TitleFirst && (episodeFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase) || originalEpisodeFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase))) if (subtitleTitleInfo.TitleFirst && (episodeFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase) || originalEpisodeFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase)))

View File

@ -176,9 +176,9 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
{ {
if (localEpisode.ScriptImported) 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); _extraService.MoveFilesAfterRename(localEpisode.Series, episodeFile);
} }

View File

@ -44,7 +44,7 @@ namespace NzbDrone.Core.Parser.Model
public int CustomFormatScore { get; set; } public int CustomFormatScore { get; set; }
public GrabbedReleaseInfo Release { get; set; } public GrabbedReleaseInfo Release { get; set; }
public bool ScriptImported { get; set; } public bool ScriptImported { get; set; }
public bool FileRenamedAfterScriptImport { get; set; } public string FileNameBeforeRename { get; set; }
public bool ShouldImportExtras { get; set; } public bool ShouldImportExtras { get; set; }
public List<string> PossibleExtraFiles { get; set; } public List<string> PossibleExtraFiles { get; set; }
public SubtitleTitleInfo SubtitleInfo { get; set; } public SubtitleTitleInfo SubtitleInfo { get; set; }