Fixed: Improve multi-episode title squashing

(cherry picked from commit 328cfa12f6dd88244d153a32df625092d62c57bd)
This commit is contained in:
Mark McDowall 2021-01-20 12:43:12 -08:00 committed by servarr
parent 84f9b8ca2d
commit 70469a1c14
2 changed files with 81 additions and 1 deletions

View File

@ -0,0 +1,80 @@
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 MultiEpisodeTitleFixture : CoreTest<FileNameBuilder>
{
private Series _series;
private Episode _episode1;
private Episode _episode2;
private EpisodeFile _episodeFile;
private NamingConfig _namingConfig;
[SetUp]
public void Setup()
{
_series = Builder<Series>
.CreateNew()
.With(s => s.Title = "South Park")
.Build();
_namingConfig = NamingConfig.Default;
_namingConfig.RenameEpisodes = true;
Mocker.GetMock<INamingConfigService>()
.Setup(c => c.GetConfig()).Returns(_namingConfig);
_episode1 = Builder<Episode>.CreateNew()
.With(e => e.Title = "Episode Title")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 6)
.With(e => e.AbsoluteEpisodeNumber = 100)
.Build();
_episode2 = Builder<Episode>.CreateNew()
.With(e => e.Title = "Episode Title")
.With(e => e.SeasonNumber = 15)
.With(e => e.EpisodeNumber = 7)
.With(e => e.AbsoluteEpisodeNumber = 101)
.Build();
_episodeFile = new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p), ReleaseGroup = "SonarrTest" };
Mocker.GetMock<IQualityDefinitionService>()
.Setup(v => v.Get(Moq.It.IsAny<Quality>()))
.Returns<Quality>(v => Quality.DefaultQualityDefinitions.First(c => c.Quality == v));
}
private void GivenProper()
{
_episodeFile.Quality.Revision.Version = 2;
}
[TestCase("Episode Title (1)", "Episode Title (2)")]
[TestCase("Episode Title Part 1", "Episode Title Part 2")]
[TestCase("Episode Title", "Episode Title: Part 2")]
public void should_replace_Series_space_Title(string firstTitle, string secondTitle)
{
_episode1.Title = firstTitle;
_episode2.Title = secondTitle;
_namingConfig.StandardEpisodeFormat = "{Episode Title} {Quality Full}";
Subject.BuildFileName(new List<Episode> {_episode1, _episode2}, _series, _episodeFile)
.Should().Be("Episode Title HDTV-720p");
}
}
}

View File

@ -62,7 +62,7 @@ namespace NzbDrone.Core.Organizer
private static readonly Regex ScenifyReplaceChars = new Regex(@"[\/]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
//TODO: Support Written numbers (One, Two, etc) and Roman Numerals (I, II, III etc)
private static readonly Regex MultiPartCleanupRegex = new Regex(@"(?:\(\d+\)|(Part|Pt\.?)\s?\d+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex MultiPartCleanupRegex = new Regex(@"(?:\:?\s?(?:\(\d+\)|(Part|Pt\.?)\s?\d+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly char[] TrackTitleTrimCharacters = new[] { ' ', '.', '?' };