mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-20 01:42:35 +01:00
Fix ignoring title based on pre-rename moviefile
(cherry picked from commit af5a681ab7edf7f72544647c490216907853d77d) Fixed: Renaming movie file for a movie (cherry picked from commit fc06e5135213f218648c8b36747d3bdf361f08b4)
This commit is contained in:
parent
fcb758bf67
commit
229e87f398
@ -9,13 +9,13 @@ namespace NzbDrone.Core.Test.MediaFiles.movieImport.Aggregation.Aggregators
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class AggregateSubtitleInfoFixture : CoreTest<AggregateSubtitleInfo>
|
public class AggregateSubtitleInfoFixture : CoreTest<AggregateSubtitleInfo>
|
||||||
{
|
{
|
||||||
[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].default.eng.forced.ass", null)]
|
||||||
[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].eng.default.ass", null)]
|
||||||
[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].fra.ass", null)]
|
||||||
[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].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")]
|
[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")]
|
[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)
|
public void should_do_basic_parse(string relativePath, string originalFilePath, string path, string fileNameBeforeRename)
|
||||||
{
|
{
|
||||||
var movieFile = new MovieFile
|
var movieFile = new MovieFile
|
||||||
{
|
{
|
||||||
@ -23,7 +23,7 @@ public void should_do_basic_parse(string relativePath, string originalFilePath,
|
|||||||
OriginalFilePath = originalFilePath
|
OriginalFilePath = originalFilePath
|
||||||
};
|
};
|
||||||
|
|
||||||
var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(movieFile, path);
|
var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(movieFile, path, fileNameBeforeRename);
|
||||||
|
|
||||||
subtitleTitleInfo.Title.Should().BeNull();
|
subtitleTitleInfo.Title.Should().BeNull();
|
||||||
subtitleTitleInfo.Copy.Should().Be(0);
|
subtitleTitleInfo.Copy.Should().Be(0);
|
||||||
@ -40,7 +40,7 @@ public void should_not_parse_default(string relativePath, string path)
|
|||||||
RelativePath = relativePath
|
RelativePath = relativePath
|
||||||
};
|
};
|
||||||
|
|
||||||
var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(movieFile, path);
|
var subtitleTitleInfo = Subject.CleanSubtitleTitleInfo(movieFile, path, null);
|
||||||
|
|
||||||
subtitleTitleInfo.LanguageTags.Should().NotContain("default");
|
subtitleTitleInfo.LanguageTags.Should().NotContain("default");
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace NzbDrone.Core.Extras
|
|||||||
{
|
{
|
||||||
public interface IExistingExtraFiles
|
public interface IExistingExtraFiles
|
||||||
{
|
{
|
||||||
List<string> ImportExtraFiles(Movie movie, List<string> possibleExtraFiles, bool keepExistingEntries);
|
List<string> ImportExtraFiles(Movie movie, List<string> possibleExtraFiles, string fileNameBeforeRename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExistingExtraFileService : IExistingExtraFiles, IHandle<MovieScannedEvent>
|
public class ExistingExtraFileService : IExistingExtraFiles, IHandle<MovieScannedEvent>
|
||||||
@ -25,7 +25,7 @@ public ExistingExtraFileService(IEnumerable<IImportExistingExtraFiles> existingE
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> ImportExtraFiles(Movie movie, List<string> possibleExtraFiles, bool keepExistingEntries)
|
public List<string> ImportExtraFiles(Movie movie, List<string> possibleExtraFiles, string fileNameBeforeRename)
|
||||||
{
|
{
|
||||||
_logger.Debug("Looking for existing extra files in {0}", movie.Path);
|
_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)
|
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)));
|
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 movie = message.Movie;
|
||||||
var possibleExtraFiles = message.PossibleExtraFiles;
|
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);
|
_logger.Info("Found {0} possible extra files, imported {1} files.", possibleExtraFiles.Count, importedFiles.Count);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@ namespace NzbDrone.Core.Extras
|
|||||||
public interface IImportExistingExtraFiles
|
public interface IImportExistingExtraFiles
|
||||||
{
|
{
|
||||||
int Order { get; }
|
int Order { get; }
|
||||||
IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries);
|
IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, string fileNameBeforeRename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public ImportExistingExtraFilesBase(IExtraFileService<TExtraFile> extraFileServi
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract int Order { get; }
|
public abstract int Order { get; }
|
||||||
public abstract IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries);
|
public abstract IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, string fileNameBeforeRename);
|
||||||
|
|
||||||
public virtual ImportExistingExtraFileFilterResult<TExtraFile> FilterAndClean(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries)
|
public virtual ImportExistingExtraFileFilterResult<TExtraFile> FilterAndClean(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries)
|
||||||
{
|
{
|
||||||
|
@ -31,12 +31,12 @@ public ExistingMetadataImporter(IExtraFileService<MetadataFile> metadataFileServ
|
|||||||
|
|
||||||
public override int Order => 0;
|
public override int Order => 0;
|
||||||
|
|
||||||
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries)
|
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, string fileNameBeforeRename)
|
||||||
{
|
{
|
||||||
_logger.Debug("Looking for existing metadata in {0}", movie.Path);
|
_logger.Debug("Looking for existing metadata in {0}", movie.Path);
|
||||||
|
|
||||||
var metadataFiles = new List<MetadataFile>();
|
var metadataFiles = new List<MetadataFile>();
|
||||||
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries);
|
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, fileNameBeforeRename is not null);
|
||||||
|
|
||||||
foreach (var possibleMetadataFile in filterResult.FilesOnDisk)
|
foreach (var possibleMetadataFile in filterResult.FilesOnDisk)
|
||||||
{
|
{
|
||||||
|
@ -27,12 +27,12 @@ public ExistingOtherExtraImporter(IExtraFileService<OtherExtraFile> otherExtraFi
|
|||||||
|
|
||||||
public override int Order => 2;
|
public override int Order => 2;
|
||||||
|
|
||||||
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries)
|
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, string fileNameBeforeRename)
|
||||||
{
|
{
|
||||||
_logger.Debug("Looking for existing extra files in {0}", movie.Path);
|
_logger.Debug("Looking for existing extra files in {0}", movie.Path);
|
||||||
|
|
||||||
var extraFiles = new List<OtherExtraFile>();
|
var extraFiles = new List<OtherExtraFile>();
|
||||||
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries);
|
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, fileNameBeforeRename is not null);
|
||||||
|
|
||||||
foreach (var possibleExtraFile in filterResult.FilesOnDisk)
|
foreach (var possibleExtraFile in filterResult.FilesOnDisk)
|
||||||
{
|
{
|
||||||
|
@ -32,12 +32,12 @@ public ExistingSubtitleImporter(IExtraFileService<SubtitleFile> subtitleFileServ
|
|||||||
|
|
||||||
public override int Order => 1;
|
public override int Order => 1;
|
||||||
|
|
||||||
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, bool keepExistingEntries)
|
public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> filesOnDisk, List<string> importedFiles, string fileNameBeforeRename)
|
||||||
{
|
{
|
||||||
_logger.Debug("Looking for existing subtitle files in {0}", movie.Path);
|
_logger.Debug("Looking for existing subtitle files in {0}", movie.Path);
|
||||||
|
|
||||||
var subtitleFiles = new List<SubtitleFile>();
|
var subtitleFiles = new List<SubtitleFile>();
|
||||||
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, keepExistingEntries);
|
var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles, fileNameBeforeRename is not null);
|
||||||
|
|
||||||
foreach (var possibleSubtitleFile in filterResult.FilesOnDisk)
|
foreach (var possibleSubtitleFile in filterResult.FilesOnDisk)
|
||||||
{
|
{
|
||||||
@ -57,7 +57,8 @@ public override IEnumerable<ExtraFile> ProcessFiles(Movie movie, List<string> fi
|
|||||||
{
|
{
|
||||||
FileMovieInfo = minimalInfo,
|
FileMovieInfo = minimalInfo,
|
||||||
Movie = movie,
|
Movie = movie,
|
||||||
Path = possibleSubtitleFile
|
Path = possibleSubtitleFile,
|
||||||
|
FileNameBeforeRename = fileNameBeforeRename
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -119,6 +119,11 @@ private MovieFile TransferFile(MovieFile movieFile, Movie movie, string destinat
|
|||||||
|
|
||||||
movieFile.RelativePath = movie.Path.GetRelativePath(destinationFilePath);
|
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 (localMovie is not null && _scriptImportDecider.TryImport(movieFilePath, destinationFilePath, localMovie, movieFile, mode) is var scriptImportDecision && scriptImportDecision != ScriptImportDecision.DeferMove)
|
||||||
{
|
{
|
||||||
if (scriptImportDecision == ScriptImportDecision.RenameRequested)
|
if (scriptImportDecision == ScriptImportDecision.RenameRequested)
|
||||||
@ -126,7 +131,6 @@ private MovieFile TransferFile(MovieFile movieFile, Movie movie, string destinat
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
MoveMovieFile(movieFile, movie);
|
MoveMovieFile(movieFile, movie);
|
||||||
localMovie.FileRenamedAfterScriptImport = true;
|
|
||||||
}
|
}
|
||||||
catch (SameFilenameException)
|
catch (SameFilenameException)
|
||||||
{
|
{
|
||||||
|
@ -30,16 +30,16 @@ public LocalMovie Aggregate(LocalMovie localMovie, DownloadClientItem downloadCl
|
|||||||
return localMovie;
|
return localMovie;
|
||||||
}
|
}
|
||||||
|
|
||||||
localMovie.SubtitleInfo = CleanSubtitleTitleInfo(localMovie.Movie.MovieFile, path);
|
localMovie.SubtitleInfo = CleanSubtitleTitleInfo(localMovie.Movie.MovieFile, path, localMovie.FileNameBeforeRename);
|
||||||
|
|
||||||
return localMovie;
|
return localMovie;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubtitleTitleInfo CleanSubtitleTitleInfo(MovieFile movieFile, string path)
|
public SubtitleTitleInfo CleanSubtitleTitleInfo(MovieFile movieFile, string path, string fileNameBeforeRename)
|
||||||
{
|
{
|
||||||
var subtitleTitleInfo = LanguageParser.ParseSubtitleLanguageInformation(path);
|
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;
|
var originalMovieFileTitle = Path.GetFileNameWithoutExtension(movieFile.OriginalFilePath) ?? string.Empty;
|
||||||
|
|
||||||
if (subtitleTitleInfo.TitleFirst && (movieFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase) || originalMovieFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase)))
|
if (subtitleTitleInfo.TitleFirst && (movieFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase) || originalMovieFileTitle.Contains(subtitleTitleInfo.RawTitle, StringComparison.OrdinalIgnoreCase)))
|
||||||
|
@ -155,9 +155,9 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
|
|||||||
{
|
{
|
||||||
if (localMovie.ScriptImported)
|
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);
|
_extraService.MoveFilesAfterRename(localMovie.Movie, movieFile);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public LocalMovie()
|
|||||||
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; }
|
||||||
|
Loading…
Reference in New Issue
Block a user