diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/NestedFileNameBuilderFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/NestedFileNameBuilderFixture.cs index da077e41f..cae7e757d 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/NestedFileNameBuilderFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/NestedFileNameBuilderFixture.cs @@ -40,11 +40,13 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests _medium = Builder .CreateNew() .With(m => m.Number = 3) + .With(m => m.Name = "Hybrid Theory") .Build(); _medium2 = Builder .CreateNew() .With(m => m.Number = 4) + .With(m => m.Name = "Reanimation") .Build(); _release = Builder @@ -130,5 +132,16 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests Subject.BuildTrackFileName(new List { _track1 }, _artist, _album, _trackFile) .Should().Be("Hybrid Theory (2020)\\CD 03\\Linkin Park - 06 [MP3-256]".AsOsAgnostic()); } + + [Test] + public void should_build_nested_multi_track_filename_with_medium_name() + { + _namingConfig.MultiDiscTrackFormat = "{Album Title} {(Release Year)}/CD {medium:00} - {Medium Name}/{Artist Name} - {track:00} [{Quality Title}] {[Quality Proper]}"; + + _release.Media.Add(_medium2); + + Subject.BuildTrackFileName(new List { _track1 }, _artist, _album, _trackFile) + .Should().Be("Hybrid Theory (2020)\\CD 03 - Hybrid Theory\\Linkin Park - 06 [MP3-256]".AsOsAgnostic()); + } } } diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 7d7e7e632..d1d9c0ec9 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -57,7 +57,7 @@ namespace NzbDrone.Core.Organizer RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex FileNameCleanupRegex = new Regex(@"([- ._])(\1)+", RegexOptions.Compiled); - private static readonly Regex TrimSeparatorsRegex = new Regex(@"[- ._]$", RegexOptions.Compiled); + private static readonly Regex TrimSeparatorsRegex = new Regex(@"[- ._]+$", RegexOptions.Compiled); private static readonly Regex ScenifyRemoveChars = new Regex(@"(?<=\s)(,|<|>|\/|\\|;|:|'|""|\||`|~|!|\?|@|$|%|^|\*|-|_|=){1}(?=\s)|('|:|\?|,)(?=(?:(?:s|m)\s)|\s|$)|(\(|\)|\[|\]|\{|\})", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex ScenifyReplaceChars = new Regex(@"[\/]", RegexOptions.Compiled | RegexOptions.IgnoreCase); @@ -109,7 +109,7 @@ namespace NzbDrone.Core.Organizer tracks = tracks.OrderBy(e => e.AlbumReleaseId).ThenBy(e => e.TrackNumber).ToList(); - var splitPatterns = pattern.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries); + var splitPatterns = pattern.Split(new[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries); var components = new List(); for (var i = 0; i < splitPatterns.Length; i++) @@ -313,6 +313,7 @@ namespace NzbDrone.Core.Organizer private void AddMediumTokens(Dictionary> tokenHandlers, Medium medium) { + tokenHandlers["{Medium Name}"] = m => medium.Name; tokenHandlers["{Medium Format}"] = m => medium.Format; } diff --git a/src/NzbDrone.Core/Organizer/FileNameSampleService.cs b/src/NzbDrone.Core/Organizer/FileNameSampleService.cs index b86d6e226..f3cda2d1b 100644 --- a/src/NzbDrone.Core/Organizer/FileNameSampleService.cs +++ b/src/NzbDrone.Core/Organizer/FileNameSampleService.cs @@ -61,7 +61,7 @@ namespace NzbDrone.Core.Organizer { new Medium { - Name = "CD 1: First Years", + Name = "First Years", Format = "CD", Number = 1 } @@ -76,13 +76,13 @@ namespace NzbDrone.Core.Organizer { new Medium { - Name = "CD 1: First Years", + Name = "First Years", Format = "CD", Number = 1 }, new Medium { - Name = "CD 2: Second Best", + Name = "Second Best", Format = "CD", Number = 2 }