New: Add Medium Name to multi disc track naming

Fix TrimSeparatorsRegex to match multiple characters

Fixes #4027
pull/4020/head
Bogdan 1 year ago
parent 9b4a3001a0
commit 8d87b88147

@ -40,11 +40,13 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
_medium = Builder<Medium> _medium = Builder<Medium>
.CreateNew() .CreateNew()
.With(m => m.Number = 3) .With(m => m.Number = 3)
.With(m => m.Name = "Hybrid Theory")
.Build(); .Build();
_medium2 = Builder<Medium> _medium2 = Builder<Medium>
.CreateNew() .CreateNew()
.With(m => m.Number = 4) .With(m => m.Number = 4)
.With(m => m.Name = "Reanimation")
.Build(); .Build();
_release = Builder<AlbumRelease> _release = Builder<AlbumRelease>
@ -130,5 +132,16 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
Subject.BuildTrackFileName(new List<Track> { _track1 }, _artist, _album, _trackFile) Subject.BuildTrackFileName(new List<Track> { _track1 }, _artist, _album, _trackFile)
.Should().Be("Hybrid Theory (2020)\\CD 03\\Linkin Park - 06 [MP3-256]".AsOsAgnostic()); .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<Track> { _track1 }, _artist, _album, _trackFile)
.Should().Be("Hybrid Theory (2020)\\CD 03 - Hybrid Theory\\Linkin Park - 06 [MP3-256]".AsOsAgnostic());
}
} }
} }

@ -57,7 +57,7 @@ namespace NzbDrone.Core.Organizer
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);
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 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); 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(); 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<string>(); var components = new List<string>();
for (var i = 0; i < splitPatterns.Length; i++) for (var i = 0; i < splitPatterns.Length; i++)
@ -313,6 +313,7 @@ namespace NzbDrone.Core.Organizer
private void AddMediumTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Medium medium) private void AddMediumTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Medium medium)
{ {
tokenHandlers["{Medium Name}"] = m => medium.Name;
tokenHandlers["{Medium Format}"] = m => medium.Format; tokenHandlers["{Medium Format}"] = m => medium.Format;
} }

@ -61,7 +61,7 @@ namespace NzbDrone.Core.Organizer
{ {
new Medium new Medium
{ {
Name = "CD 1: First Years", Name = "First Years",
Format = "CD", Format = "CD",
Number = 1 Number = 1
} }
@ -76,13 +76,13 @@ namespace NzbDrone.Core.Organizer
{ {
new Medium new Medium
{ {
Name = "CD 1: First Years", Name = "First Years",
Format = "CD", Format = "CD",
Number = 1 Number = 1
}, },
new Medium new Medium
{ {
Name = "CD 2: Second Best", Name = "Second Best",
Format = "CD", Format = "CD",
Number = 2 Number = 2
} }

Loading…
Cancel
Save