New: Added 'Series Title, The' renaming option

Closes #371
This commit is contained in:
Chris Dyson 2017-07-03 07:21:46 +12:00 committed by Taloth
parent 773274f3cc
commit 68290b0385
5 changed files with 97 additions and 4 deletions

View File

@ -308,6 +308,7 @@
<Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\EpisodeTitleCollapseFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\MultiEpisodeFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheFixture.cs" />
<Compile Include="ParserTests\MiniSeriesEpisodeParserFixture.cs" />
<Compile Include="Qualities\RevisionComparableFixture.cs" />
<Compile Include="QueueTests\QueueServiceFixture.cs" />

View File

@ -0,0 +1,83 @@
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 TitleTheFixture : 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 = "South Park")
.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));
}
[TestCase("The Mist", "Mist, The")]
[TestCase("A Place to Call Home", "Place to Call Home, A")]
[TestCase("An Adventure in Space and Time", "Adventure in Space and Time, An")]
[TestCase("The Flash (2010)", "Flash, The (2010)")]
[TestCase("A League Of Their Own (AU)", "League Of Their Own, A (AU)")]
[TestCase("The Fixer (ZH) (2015)", "Fixer, The (ZH) (2015)")]
[TestCase("The Sixth Sense 2 (Thai)", "Sixth Sense 2, The (Thai)")]
[TestCase("The Amazing Race (Latin America)", "Amazing Race, The (Latin America)")]
[TestCase("The Rat Pack (A&E)", "Rat Pack, The (A&E)")]
[TestCase("The Climax: I (Almost) Got Away With It (2016)", "Climax- I (Almost) Got Away With It, The (2016)")]
//[TestCase("", "")]
public void should_get_expected_title_back(string title, string expected)
{
_series.Title = title;
_namingConfig.StandardEpisodeFormat = "{Series TitleThe}";
Subject.BuildFileName(new List<Episode> { _episode }, _series, _episodeFile)
.Should().Be(expected);
}
[TestCase("A")]
[TestCase("Anne")]
[TestCase("Theodore")]
[TestCase("3%")]
public void should_not_change_title(string title)
{
_series.Title = title;
_namingConfig.StandardEpisodeFormat = "{Series TitleThe}";
Subject.BuildFileName(new List<Episode> { _episode }, _series, _episodeFile)
.Should().Be(title);
}
}
}

View File

@ -53,7 +53,7 @@ namespace NzbDrone.Core.Organizer
public static readonly Regex AirDateRegex = new Regex(@"\{Air(\s|\W|_)Date\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static readonly Regex SeriesTitleRegex = new Regex(@"(?<token>\{(?:Series)(?<separator>[- ._])(Clean)?Title\})",
public static readonly Regex SeriesTitleRegex = new Regex(@"(?<token>\{(?:Series)(?<separator>[- ._])(Clean)?Title(The)?\})",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex FileNameCleanupRegex = new Regex(@"([- ._])(\1)+", RegexOptions.Compiled);
@ -67,6 +67,8 @@ namespace NzbDrone.Core.Organizer
private static readonly char[] EpisodeTitleTrimCharacters = new[] { ' ', '.', '?' };
private static readonly Regex TitlePrefixRegex = new Regex(@"^(The|An|A) (.*?)((?: *\([^)]+\))*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public FileNameBuilder(INamingConfigService namingConfigService,
IQualityDefinitionService qualityDefinitionService,
ICacheManager cacheManager,
@ -253,6 +255,11 @@ namespace NzbDrone.Core.Organizer
return title;
}
public static string TitleThe(string title)
{
return TitlePrefixRegex.Replace(title, "$2, $1$3");
}
public static string CleanFileName(string name, bool replace = true)
{
string result = name;
@ -277,6 +284,7 @@ namespace NzbDrone.Core.Organizer
{
tokenHandlers["{Series Title}"] = m => series.Title;
tokenHandlers["{Series CleanTitle}"] = m => CleanTitle(series.Title);
tokenHandlers["{Series TitleThe}"] = m => TitleThe(series.Title);
}
private string AddSeasonEpisodeNumberingTokens(string pattern, Dictionary<string, Func<TokenMatch, string>> tokenHandlers, List<Episode> episodes, NamingConfig namingConfig)

View File

@ -41,19 +41,19 @@ namespace NzbDrone.Core.Organizer
_standardSeries = new Series
{
SeriesType = SeriesTypes.Standard,
Title = "Series Title (2010)"
Title = "The Series Title (2010)"
};
_dailySeries = new Series
{
SeriesType = SeriesTypes.Daily,
Title = "Series Title (2010)"
Title = "The Series Title (2010)"
};
_animeSeries = new Series
{
SeriesType = SeriesTypes.Anime,
Title = "Series Title (2010)"
Title = "The Series Title (2010)"
};
_episode1 = new Episode

View File

@ -4,6 +4,7 @@
<li><a href="#" data-token="Series Title">Series Title</a></li>
<li><a href="#" data-token="Series.Title">Series.Title</a></li>
<li><a href="#" data-token="Series_Title">Series_Title</a></li>
<li><a href="#" data-token="Series TitleThe">Series Title, The</a></li>
<li><a href="#" data-token="Series CleanTitle">Series CleanTitle</a></li>
<li><a href="#" data-token="Series.CleanTitle">Series.CleanTitle</a></li>
<li><a href="#" data-token="Series_CleanTitle">Series_CleanTitle</a></li>