mirror of
https://github.com/Radarr/Radarr
synced 2025-01-03 13:54:29 +00:00
Improve usage of Original Title renaming token
Closes #7168 Fixed: Don't recursively add the current file name to new file name when '{Original Title}' is used in addition to other naming tokens (cherry picked from commit ebb48a19cc792c71bfbd57d5f106067190d95339)
This commit is contained in:
parent
86777e021b
commit
7142d1f224
2 changed files with 105 additions and 10 deletions
|
@ -0,0 +1,88 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class OriginalTitleFixture : CoreTest<FileNameBuilder>
|
||||
{
|
||||
private Movie _movie;
|
||||
private MovieFile _movieFile;
|
||||
private NamingConfig _namingConfig;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_movie = Builder<Movie>
|
||||
.CreateNew()
|
||||
.With(s => s.Title = "My Movie")
|
||||
.Build();
|
||||
|
||||
_movieFile = new MovieFile { Quality = new QualityModel(Quality.HDTV720p), ReleaseGroup = "RadarrTest" };
|
||||
|
||||
_namingConfig = NamingConfig.Default;
|
||||
_namingConfig.RenameMovies = true;
|
||||
|
||||
Mocker.GetMock<INamingConfigService>()
|
||||
.Setup(c => c.GetConfig()).Returns(_namingConfig);
|
||||
|
||||
Mocker.GetMock<IQualityDefinitionService>()
|
||||
.Setup(v => v.Get(Moq.It.IsAny<Quality>()))
|
||||
.Returns<Quality>(v => Quality.DefaultQualityDefinitions.First(c => c.Quality == v));
|
||||
|
||||
Mocker.GetMock<ICustomFormatService>()
|
||||
.Setup(v => v.All())
|
||||
.Returns(new List<CustomFormat>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_recursively_include_current_filename()
|
||||
{
|
||||
_movieFile.RelativePath = "My Movie";
|
||||
_namingConfig.StandardMovieFormat = "{Movie Title} {[Original Title]}";
|
||||
|
||||
Subject.BuildFileName(_movie, _movieFile)
|
||||
.Should().Be("My Movie");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_include_original_title_if_not_current_file_name()
|
||||
{
|
||||
_movieFile.SceneName = "my.movie.2008";
|
||||
_movieFile.RelativePath = "My Movie";
|
||||
_namingConfig.StandardMovieFormat = "{Movie Title} {[Original Title]}";
|
||||
|
||||
Subject.BuildFileName(_movie, _movieFile)
|
||||
.Should().Be("My Movie [my.movie.2008]");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_include_current_filename_if_not_renaming_files()
|
||||
{
|
||||
_movieFile.SceneName = "my.movie.2008";
|
||||
_namingConfig.RenameMovies = false;
|
||||
|
||||
Subject.BuildFileName(_movie, _movieFile)
|
||||
.Should().Be("my.movie.2008");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_include_current_filename_if_not_including_multiple_naming_tokens()
|
||||
{
|
||||
_movieFile.RelativePath = "My Movie";
|
||||
_namingConfig.StandardMovieFormat = "{Original Title}";
|
||||
|
||||
Subject.BuildFileName(_movie, _movieFile)
|
||||
.Should().Be("My Movie");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -103,11 +103,12 @@ public string BuildFileName(Movie movie, MovieFile movieFile, NamingConfig namin
|
|||
|
||||
if (!namingConfig.RenameMovies)
|
||||
{
|
||||
return GetOriginalTitle(movieFile);
|
||||
return GetOriginalTitle(movieFile, false);
|
||||
}
|
||||
|
||||
var pattern = namingConfig.StandardMovieFormat;
|
||||
var tokenHandlers = new Dictionary<string, Func<TokenMatch, string>>(FileNameBuilderTokenEqualityComparer.Instance);
|
||||
var multipleTokens = TitleRegex.Matches(pattern).Count > 1;
|
||||
|
||||
UpdateMediaInfoIfNeeded(pattern, movieFile, movie);
|
||||
|
||||
|
@ -116,7 +117,7 @@ public string BuildFileName(Movie movie, MovieFile movieFile, NamingConfig namin
|
|||
AddIdTokens(tokenHandlers, movie);
|
||||
AddQualityTokens(tokenHandlers, movie, movieFile);
|
||||
AddMediaInfoTokens(tokenHandlers, movieFile);
|
||||
AddMovieFileTokens(tokenHandlers, movieFile);
|
||||
AddMovieFileTokens(tokenHandlers, movieFile, multipleTokens);
|
||||
AddEditionTagsTokens(tokenHandlers, movieFile);
|
||||
AddCustomFormats(tokenHandlers, movie, movieFile, customFormats);
|
||||
|
||||
|
@ -167,6 +168,7 @@ public string GetMovieFolder(Movie movie, NamingConfig namingConfig = null)
|
|||
|
||||
var pattern = namingConfig.MovieFolderFormat;
|
||||
var tokenHandlers = new Dictionary<string, Func<TokenMatch, string>>(FileNameBuilderTokenEqualityComparer.Instance);
|
||||
var multipleTokens = TitleRegex.Matches(pattern).Count > 1;
|
||||
|
||||
AddMovieTokens(tokenHandlers, movie);
|
||||
AddReleaseDateTokens(tokenHandlers, movie.Year);
|
||||
|
@ -176,12 +178,12 @@ public string GetMovieFolder(Movie movie, NamingConfig namingConfig = null)
|
|||
{
|
||||
AddQualityTokens(tokenHandlers, movie, movieFile);
|
||||
AddMediaInfoTokens(tokenHandlers, movieFile);
|
||||
AddMovieFileTokens(tokenHandlers, movieFile);
|
||||
AddMovieFileTokens(tokenHandlers, movieFile, multipleTokens);
|
||||
AddEditionTagsTokens(tokenHandlers, movieFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddMovieFileTokens(tokenHandlers, new MovieFile { SceneName = $"{movie.Title} {movie.Year}", RelativePath = $"{movie.Title} {movie.Year}" });
|
||||
AddMovieFileTokens(tokenHandlers, new MovieFile { SceneName = $"{movie.Title} {movie.Year}", RelativePath = $"{movie.Title} {movie.Year}" }, multipleTokens);
|
||||
}
|
||||
|
||||
var splitPatterns = pattern.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
@ -306,10 +308,10 @@ private void AddIdTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandl
|
|||
tokenHandlers["{TmdbId}"] = m => movie.MovieMetadata.Value.TmdbId.ToString();
|
||||
}
|
||||
|
||||
private void AddMovieFileTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, MovieFile movieFile)
|
||||
private void AddMovieFileTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, MovieFile movieFile, bool multipleTokens)
|
||||
{
|
||||
tokenHandlers["{Original Title}"] = m => GetOriginalTitle(movieFile);
|
||||
tokenHandlers["{Original Filename}"] = m => GetOriginalFileName(movieFile);
|
||||
tokenHandlers["{Original Title}"] = m => GetOriginalTitle(movieFile, multipleTokens);
|
||||
tokenHandlers["{Original Filename}"] = m => GetOriginalFileName(movieFile, multipleTokens);
|
||||
|
||||
tokenHandlers["{Release Group}"] = m => movieFile.ReleaseGroup ?? m.DefaultValue("Radarr");
|
||||
}
|
||||
|
@ -572,18 +574,23 @@ private string GetQualityReal(Movie movie, QualityModel quality)
|
|||
return string.Empty;
|
||||
}
|
||||
|
||||
private string GetOriginalTitle(MovieFile movieFile)
|
||||
private string GetOriginalTitle(MovieFile movieFile, bool multipleTokens)
|
||||
{
|
||||
if (movieFile.SceneName.IsNullOrWhiteSpace())
|
||||
{
|
||||
return GetOriginalFileName(movieFile);
|
||||
return GetOriginalFileName(movieFile, multipleTokens);
|
||||
}
|
||||
|
||||
return movieFile.SceneName;
|
||||
}
|
||||
|
||||
private string GetOriginalFileName(MovieFile movieFile)
|
||||
private string GetOriginalFileName(MovieFile movieFile, bool multipleTokens)
|
||||
{
|
||||
if (multipleTokens)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (movieFile.RelativePath.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(movieFile.Path);
|
||||
|
|
Loading…
Reference in a new issue