mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-11-24 08:42:19 +02:00
Improve usage of Original Title renaming token
Fixed: Don't recursively add the current file name to new file name when '{Original Title}' is used in addition to other naming tokens
This commit is contained in:
parent
fa9136c4d1
commit
ebb48a19cc
@ -0,0 +1,91 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class OriginalTitleFixture : CoreTest<FileNameBuilder>
|
||||
{
|
||||
private Series _series;
|
||||
private Episode _episode;
|
||||
private EpisodeFile _episodeFile;
|
||||
private NamingConfig _namingConfig;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>
|
||||
.CreateNew()
|
||||
.With(s => s.Title = "My Series")
|
||||
.Build();
|
||||
|
||||
_episode = Builder<Episode>.CreateNew()
|
||||
.With(e => e.Title = "City Sushi")
|
||||
.With(e => e.SeasonNumber = 15)
|
||||
.With(e => e.EpisodeNumber = 6)
|
||||
.With(e => e.AbsoluteEpisodeNumber = 100)
|
||||
.Build();
|
||||
|
||||
_episodeFile = new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p), ReleaseGroup = "SonarrTest" };
|
||||
|
||||
_namingConfig = NamingConfig.Default;
|
||||
_namingConfig.RenameEpisodes = 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));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_recursively_include_current_filename()
|
||||
{
|
||||
_episodeFile.RelativePath = "My Series - S15E06 - City Sushi";
|
||||
_namingConfig.StandardEpisodeFormat = "{Series Title} - S{season:00}E{episode:00} - {Episode Title} {[Original Title]}";
|
||||
|
||||
Subject.BuildFileName(new List<Episode> { _episode }, _series, _episodeFile)
|
||||
.Should().Be("My Series - S15E06 - City Sushi");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_include_original_title_if_not_current_file_name()
|
||||
{
|
||||
_episodeFile.SceneName = "my.series.s15e06";
|
||||
_episodeFile.RelativePath = "My Series - S15E06 - City Sushi";
|
||||
_namingConfig.StandardEpisodeFormat = "{Series Title} - S{season:00}E{episode:00} - {Episode Title} {[Original Title]}";
|
||||
|
||||
Subject.BuildFileName(new List<Episode> { _episode }, _series, _episodeFile)
|
||||
.Should().Be("My Series - S15E06 - City Sushi [my.series.s15e06]");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_include_current_filename_if_not_renaming_files()
|
||||
{
|
||||
_episodeFile.SceneName = "my.series.s15e06";
|
||||
_namingConfig.RenameEpisodes = false;
|
||||
|
||||
Subject.BuildFileName(new List<Episode> { _episode }, _series, _episodeFile)
|
||||
.Should().Be("my.series.s15e06");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_include_current_filename_if_not_including_multiple_naming_tokens()
|
||||
{
|
||||
_episodeFile.RelativePath = "My Series - S15E06 - City Sushi";
|
||||
_namingConfig.StandardEpisodeFormat = "{Original Title}";
|
||||
|
||||
Subject.BuildFileName(new List<Episode> { _episode }, _series, _episodeFile)
|
||||
.Should().Be("My Series - S15E06 - City Sushi");
|
||||
}
|
||||
}
|
||||
}
|
@ -109,7 +109,7 @@ private string BuildFileName(List<Episode> episodes, Series series, EpisodeFile
|
||||
|
||||
if (!namingConfig.RenameEpisodes)
|
||||
{
|
||||
return GetOriginalTitle(episodeFile) + extension;
|
||||
return GetOriginalTitle(episodeFile, false) + extension;
|
||||
}
|
||||
|
||||
if (namingConfig.StandardEpisodeFormat.IsNullOrWhiteSpace() && series.SeriesType == SeriesTypes.Standard)
|
||||
@ -148,6 +148,8 @@ private string BuildFileName(List<Episode> episodes, Series series, EpisodeFile
|
||||
{
|
||||
var splitPattern = splitPatterns[i];
|
||||
var tokenHandlers = new Dictionary<string, Func<TokenMatch, string>>(FileNameBuilderTokenEqualityComparer.Instance);
|
||||
var multipleTokens = TitleRegex.Matches(splitPattern).Count > 1;
|
||||
|
||||
splitPattern = AddSeasonEpisodeNumberingTokens(splitPattern, tokenHandlers, episodes, namingConfig);
|
||||
splitPattern = AddAbsoluteNumberingTokens(splitPattern, tokenHandlers, series, episodes, namingConfig);
|
||||
|
||||
@ -157,7 +159,7 @@ private string BuildFileName(List<Episode> episodes, Series series, EpisodeFile
|
||||
AddIdTokens(tokenHandlers, series);
|
||||
AddEpisodeTokens(tokenHandlers, episodes);
|
||||
AddEpisodeTitlePlaceholderTokens(tokenHandlers);
|
||||
AddEpisodeFileTokens(tokenHandlers, episodeFile);
|
||||
AddEpisodeFileTokens(tokenHandlers, episodeFile, multipleTokens);
|
||||
AddQualityTokens(tokenHandlers, series, episodeFile);
|
||||
AddMediaInfoTokens(tokenHandlers, episodeFile);
|
||||
AddPreferredWords(tokenHandlers, series, episodeFile, preferredWords);
|
||||
@ -583,10 +585,10 @@ private void AddEpisodeTitleTokens(Dictionary<string, Func<TokenMatch, string>>
|
||||
tokenHandlers["{Episode CleanTitle}"] = m => GetEpisodeTitle(GetEpisodeTitles(episodes).Select(CleanTitle).ToList(), "and", maxLength);
|
||||
}
|
||||
|
||||
private void AddEpisodeFileTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, EpisodeFile episodeFile)
|
||||
private void AddEpisodeFileTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, EpisodeFile episodeFile, bool multipleTokens)
|
||||
{
|
||||
tokenHandlers["{Original Title}"] = m => GetOriginalTitle(episodeFile);
|
||||
tokenHandlers["{Original Filename}"] = m => GetOriginalFileName(episodeFile);
|
||||
tokenHandlers["{Original Title}"] = m => GetOriginalTitle(episodeFile, multipleTokens);
|
||||
tokenHandlers["{Original Filename}"] = m => GetOriginalFileName(episodeFile, multipleTokens);
|
||||
tokenHandlers["{Release Group}"] = m => episodeFile.ReleaseGroup ?? m.DefaultValue("Sonarr");
|
||||
}
|
||||
|
||||
@ -1030,18 +1032,23 @@ private string GetQualityReal(Series series, QualityModel quality)
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string GetOriginalTitle(EpisodeFile episodeFile)
|
||||
private string GetOriginalTitle(EpisodeFile episodeFile, bool multipleTokens)
|
||||
{
|
||||
if (episodeFile.SceneName.IsNullOrWhiteSpace())
|
||||
{
|
||||
return GetOriginalFileName(episodeFile);
|
||||
return GetOriginalFileName(episodeFile, multipleTokens);
|
||||
}
|
||||
|
||||
return episodeFile.SceneName;
|
||||
}
|
||||
|
||||
private string GetOriginalFileName(EpisodeFile episodeFile)
|
||||
private string GetOriginalFileName(EpisodeFile episodeFile, bool multipleTokens)
|
||||
{
|
||||
if (multipleTokens)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (episodeFile.RelativePath.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(episodeFile.Path);
|
||||
|
Loading…
Reference in New Issue
Block a user