From 70469a1c148fb363ba3f2c1a064b01b8a1c7aa51 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 20 Jan 2021 12:43:12 -0800 Subject: [PATCH] Fixed: Improve multi-episode title squashing (cherry picked from commit 328cfa12f6dd88244d153a32df625092d62c57bd) --- .../MultiEpisodeTitleFixture.cs | 80 +++++++++++++++++++ .../Organizer/FileNameBuilder.cs | 2 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/MultiEpisodeTitleFixture.cs diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/MultiEpisodeTitleFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/MultiEpisodeTitleFixture.cs new file mode 100644 index 000000000..2493ddf94 --- /dev/null +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/MultiEpisodeTitleFixture.cs @@ -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 + { + private Series _series; + private Episode _episode1; + private Episode _episode2; + private EpisodeFile _episodeFile; + private NamingConfig _namingConfig; + + [SetUp] + public void Setup() + { + _series = Builder + .CreateNew() + .With(s => s.Title = "South Park") + .Build(); + + + _namingConfig = NamingConfig.Default; + _namingConfig.RenameEpisodes = true; + + + Mocker.GetMock() + .Setup(c => c.GetConfig()).Returns(_namingConfig); + + _episode1 = Builder.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.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() + .Setup(v => v.Get(Moq.It.IsAny())) + .Returns(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 {_episode1, _episode2}, _series, _episodeFile) + .Should().Be("Episode Title HDTV-720p"); + } + } +} diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 3737eae61..513e16043 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -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[] { ' ', '.', '?' };