New: Series Title with Year renaming token
This commit is contained in:
parent
62b03adb53
commit
400838c79a
|
@ -336,6 +336,9 @@
|
||||||
<Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleFixture.cs" />
|
<Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleFixture.cs" />
|
||||||
<Compile Include="OrganizerTests\FileNameBuilderTests\EpisodeTitleCollapseFixture.cs" />
|
<Compile Include="OrganizerTests\FileNameBuilderTests\EpisodeTitleCollapseFixture.cs" />
|
||||||
<Compile Include="OrganizerTests\FileNameBuilderTests\MultiEpisodeFixture.cs" />
|
<Compile Include="OrganizerTests\FileNameBuilderTests\MultiEpisodeFixture.cs" />
|
||||||
|
<Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleYearFixture.cs" />
|
||||||
|
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleYearFixture.cs" />
|
||||||
|
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheYearFixture.cs" />
|
||||||
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheFixture.cs" />
|
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheFixture.cs" />
|
||||||
<Compile Include="ParserTests\MiniSeriesEpisodeParserFixture.cs" />
|
<Compile Include="ParserTests\MiniSeriesEpisodeParserFixture.cs" />
|
||||||
<Compile Include="ParserTests\ValidateParsedEpisodeInfoFixture.cs" />
|
<Compile Include="ParserTests\ValidateParsedEpisodeInfoFixture.cs" />
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
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 CleanTitleYearFixture : CoreTest<FileNameBuilder>
|
||||||
|
{
|
||||||
|
private Series _series;
|
||||||
|
private Episode _episode;
|
||||||
|
private EpisodeFile _episodeFile;
|
||||||
|
private NamingConfig _namingConfig;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_series = Builder<Series>
|
||||||
|
.CreateNew()
|
||||||
|
.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", 2018, "The Mist 2018")]
|
||||||
|
[TestCase("The Rat Pack (A&E)", 1999, "The Rat Pack AandE 1999")]
|
||||||
|
[TestCase("The Climax: I (Almost) Got Away With It (2016)", 2016, "The Climax I Almost Got Away With It 2016")]
|
||||||
|
public void should_get_expected_title_back(string title, int year, string expected)
|
||||||
|
{
|
||||||
|
_series.Title = title;
|
||||||
|
_series.Year = year;
|
||||||
|
_namingConfig.StandardEpisodeFormat = "{Series CleanTitleYear}";
|
||||||
|
|
||||||
|
Subject.BuildFileName(new List<Episode> { _episode }, _series, _episodeFile)
|
||||||
|
.Should().Be(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -491,8 +491,10 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
|
||||||
{
|
{
|
||||||
VideoCodec = "AVC",
|
VideoCodec = "AVC",
|
||||||
AudioFormat = "DTS",
|
AudioFormat = "DTS",
|
||||||
|
AudioChannels = 6,
|
||||||
AudioLanguages = "English/Spanish",
|
AudioLanguages = "English/Spanish",
|
||||||
Subtitles = "English/Spanish/Italian"
|
Subtitles = "English/Spanish/Italian",
|
||||||
|
SchemaRevision = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile)
|
Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile)
|
||||||
|
@ -508,8 +510,10 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
|
||||||
{
|
{
|
||||||
VideoCodec = "AVC",
|
VideoCodec = "AVC",
|
||||||
AudioFormat = "DTS",
|
AudioFormat = "DTS",
|
||||||
|
AudioChannels = 6,
|
||||||
AudioLanguages = "English",
|
AudioLanguages = "English",
|
||||||
Subtitles = "English/Spanish/Italian"
|
Subtitles = "English/Spanish/Italian",
|
||||||
|
SchemaRevision = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile)
|
Subject.BuildFileName(new List<Episode> { _episode1 }, _series, _episodeFile)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
|
@ -24,7 +24,6 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
|
||||||
{
|
{
|
||||||
_series = Builder<Series>
|
_series = Builder<Series>
|
||||||
.CreateNew()
|
.CreateNew()
|
||||||
.With(s => s.Title = "South Park")
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
_episode = Builder<Episode>.CreateNew()
|
_episode = Builder<Episode>.CreateNew()
|
||||||
|
@ -57,7 +56,6 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
|
||||||
[TestCase("The Amazing Race (Latin America)", "Amazing Race, The (Latin America)")]
|
[TestCase("The Amazing Race (Latin America)", "Amazing Race, The (Latin America)")]
|
||||||
[TestCase("The Rat Pack (A&E)", "Rat Pack, The (A&E)")]
|
[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("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)
|
public void should_get_expected_title_back(string title, string expected)
|
||||||
{
|
{
|
||||||
_series.Title = title;
|
_series.Title = title;
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
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 TitleTheYearFixture : CoreTest<FileNameBuilder>
|
||||||
|
{
|
||||||
|
private Series _series;
|
||||||
|
private Episode _episode;
|
||||||
|
private EpisodeFile _episodeFile;
|
||||||
|
private NamingConfig _namingConfig;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_series = Builder<Series>
|
||||||
|
.CreateNew()
|
||||||
|
.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", 2018, "Mist, The (2018)")]
|
||||||
|
[TestCase("The Rat Pack (A&E)", 1999, "Rat Pack, The (A&E) (1999)")]
|
||||||
|
[TestCase("The Climax: I (Almost) Got Away With It (2016)", 2016, "Climax- I (Almost) Got Away With It, The (2016)")]
|
||||||
|
[TestCase("A", 2017, "A (2017)")]
|
||||||
|
public void should_get_expected_title_back(string title, int year, string expected)
|
||||||
|
{
|
||||||
|
_series.Title = title;
|
||||||
|
_series.Year = year;
|
||||||
|
_namingConfig.StandardEpisodeFormat = "{Series TitleTheYear}";
|
||||||
|
|
||||||
|
Subject.BuildFileName(new List<Episode> { _episode }, _series, _episodeFile)
|
||||||
|
.Should().Be(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
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 TitleYearFixture : CoreTest<FileNameBuilder>
|
||||||
|
{
|
||||||
|
private Series _series;
|
||||||
|
private Episode _episode;
|
||||||
|
private EpisodeFile _episodeFile;
|
||||||
|
private NamingConfig _namingConfig;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_series = Builder<Series>
|
||||||
|
.CreateNew()
|
||||||
|
.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", 2018, "The Mist (2018)")]
|
||||||
|
[TestCase("The Rat Pack (A&E)", 1999, "The Rat Pack (A&E) (1999)")]
|
||||||
|
[TestCase("The Climax: I (Almost) Got Away With It (2016)", 2016, "The Climax- I (Almost) Got Away With It (2016)")]
|
||||||
|
public void should_get_expected_title_back(string title, int year, string expected)
|
||||||
|
{
|
||||||
|
_series.Title = title;
|
||||||
|
_series.Year = year;
|
||||||
|
_namingConfig.StandardEpisodeFormat = "{Series TitleYear}";
|
||||||
|
|
||||||
|
Subject.BuildFileName(new List<Episode> { _episode }, _series, _episodeFile)
|
||||||
|
.Should().Be(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,7 +55,7 @@ namespace NzbDrone.Core.Organizer
|
||||||
|
|
||||||
public static readonly Regex AirDateRegex = new Regex(@"\{Air(\s|\W|_)Date\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
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(The)?\})",
|
public static readonly Regex SeriesTitleRegex = new Regex(@"(?<token>\{(?:Series)(?<separator>[- ._])(Clean)?Title(The)?(Year)?\})",
|
||||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
private static readonly Regex FileNameCleanupRegex = new Regex(@"([- ._])(\1)+", RegexOptions.Compiled);
|
private static readonly Regex FileNameCleanupRegex = new Regex(@"([- ._])(\1)+", RegexOptions.Compiled);
|
||||||
|
@ -71,6 +71,8 @@ namespace NzbDrone.Core.Organizer
|
||||||
|
|
||||||
private static readonly Regex TitlePrefixRegex = new Regex(@"^(The|An|A) (.*?)((?: *\([^)]+\))*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
private static readonly Regex TitlePrefixRegex = new Regex(@"^(The|An|A) (.*?)((?: *\([^)]+\))*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
|
private static readonly Regex YearRegex = new Regex(@"\(\d{4}\)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
public FileNameBuilder(INamingConfigService namingConfigService,
|
public FileNameBuilder(INamingConfigService namingConfigService,
|
||||||
IQualityDefinitionService qualityDefinitionService,
|
IQualityDefinitionService qualityDefinitionService,
|
||||||
ICacheManager cacheManager,
|
ICacheManager cacheManager,
|
||||||
|
@ -263,6 +265,17 @@ namespace NzbDrone.Core.Organizer
|
||||||
return TitlePrefixRegex.Replace(title, "$2, $1$3");
|
return TitlePrefixRegex.Replace(title, "$2, $1$3");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string TitleYear(string title, int year)
|
||||||
|
{
|
||||||
|
// Regex match incase the year in the title doesn't match the year, for whatever reason.
|
||||||
|
if (YearRegex.IsMatch(title))
|
||||||
|
{
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"{title} ({year})";
|
||||||
|
}
|
||||||
|
|
||||||
public static string CleanFileName(string name, bool replace = true)
|
public static string CleanFileName(string name, bool replace = true)
|
||||||
{
|
{
|
||||||
string result = name;
|
string result = name;
|
||||||
|
@ -321,7 +334,10 @@ namespace NzbDrone.Core.Organizer
|
||||||
{
|
{
|
||||||
tokenHandlers["{Series Title}"] = m => series.Title;
|
tokenHandlers["{Series Title}"] = m => series.Title;
|
||||||
tokenHandlers["{Series CleanTitle}"] = m => CleanTitle(series.Title);
|
tokenHandlers["{Series CleanTitle}"] = m => CleanTitle(series.Title);
|
||||||
|
tokenHandlers["{Series CleanTitleYear}"] = m => CleanTitle(TitleYear(series.Title, series.Year));
|
||||||
tokenHandlers["{Series TitleThe}"] = m => TitleThe(series.Title);
|
tokenHandlers["{Series TitleThe}"] = m => TitleThe(series.Title);
|
||||||
|
tokenHandlers["{Series TitleYear}"] = m => TitleYear(series.Title, series.Year);
|
||||||
|
tokenHandlers["{Series TitleTheYear}"] = m => TitleYear(TitleThe(series.Title), series.Year);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string AddSeasonEpisodeNumberingTokens(string pattern, Dictionary<string, Func<TokenMatch, string>> tokenHandlers, List<Episode> episodes, NamingConfig namingConfig)
|
private string AddSeasonEpisodeNumberingTokens(string pattern, Dictionary<string, Func<TokenMatch, string>> tokenHandlers, List<Episode> episodes, NamingConfig namingConfig)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NzbDrone.Core.MediaFiles;
|
using NzbDrone.Core.MediaFiles;
|
||||||
using NzbDrone.Core.Qualities;
|
using NzbDrone.Core.Qualities;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
|
@ -41,19 +41,22 @@ namespace NzbDrone.Core.Organizer
|
||||||
_standardSeries = new Series
|
_standardSeries = new Series
|
||||||
{
|
{
|
||||||
SeriesType = SeriesTypes.Standard,
|
SeriesType = SeriesTypes.Standard,
|
||||||
Title = "The Series Title (2010)"
|
Title = "The Series Title!",
|
||||||
|
Year = 2010
|
||||||
};
|
};
|
||||||
|
|
||||||
_dailySeries = new Series
|
_dailySeries = new Series
|
||||||
{
|
{
|
||||||
SeriesType = SeriesTypes.Daily,
|
SeriesType = SeriesTypes.Daily,
|
||||||
Title = "The Series Title (2010)"
|
Title = "The Series Title!",
|
||||||
|
Year = 2010
|
||||||
};
|
};
|
||||||
|
|
||||||
_animeSeries = new Series
|
_animeSeries = new Series
|
||||||
{
|
{
|
||||||
SeriesType = SeriesTypes.Anime,
|
SeriesType = SeriesTypes.Anime,
|
||||||
Title = "The Series Title (2010)"
|
Title = "The Series Title!",
|
||||||
|
Year = 2010
|
||||||
};
|
};
|
||||||
|
|
||||||
_episode1 = new Episode
|
_episode1 = new Episode
|
||||||
|
|
Loading…
Reference in New Issue