From 31c8092960dfcea9ef9c077254b937aea4b75e32 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 25 Dec 2022 13:41:33 -0600 Subject: [PATCH] New: Author name first character renaming token Co-Authored-By: Mark McDowall --- .../MediaManagement/Naming/NamingModal.js | 2 + .../AuthorNameFirstCharacterFixture.cs | 57 +++++++++++++++++++ .../Organizer/FileNameBuilder.cs | 1 + 3 files changed, 60 insertions(+) create mode 100644 src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/AuthorNameFirstCharacterFixture.cs diff --git a/frontend/src/Settings/MediaManagement/Naming/NamingModal.js b/frontend/src/Settings/MediaManagement/Naming/NamingModal.js index 4b4e615e3..e3d994e11 100644 --- a/frontend/src/Settings/MediaManagement/Naming/NamingModal.js +++ b/frontend/src/Settings/MediaManagement/Naming/NamingModal.js @@ -51,6 +51,8 @@ const authorTokens = [ { token: '{Author NameThe}', example: 'Author\'s Name, The' }, + { token: '{Author NameFirstCharacter}', example: 'A' }, + { token: '{Author CleanName}', example: 'Authors Name' }, { token: '{Author SortName}', example: 'Name, Author' }, diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/AuthorNameFirstCharacterFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/AuthorNameFirstCharacterFixture.cs new file mode 100644 index 000000000..602841f28 --- /dev/null +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/AuthorNameFirstCharacterFixture.cs @@ -0,0 +1,57 @@ +using System.IO; +using System.Linq; +using FizzWare.NBuilder; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Books; +using NzbDrone.Core.Organizer; +using NzbDrone.Core.Qualities; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests +{ + [TestFixture] + public class AuthorNameFirstCharacterFixture : CoreTest + { + private Author _author; + private NamingConfig _namingConfig; + + [SetUp] + public void Setup() + { + _author = Builder + .CreateNew() + .Build(); + + _namingConfig = NamingConfig.Default; + _namingConfig.RenameBooks = true; + + Mocker.GetMock() + .Setup(c => c.GetConfig()).Returns(_namingConfig); + + Mocker.GetMock() + .Setup(v => v.Get(Moq.It.IsAny())) + .Returns(v => Quality.DefaultQualityDefinitions.First(c => c.Quality == v)); + } + + [TestCase("The Mist", "M", "The Mist")] + [TestCase("A", "A", "A")] + [TestCase("30 Rock", "3", "30 Rock")] + public void should_get_expected_folder_name_back(string title, string parent, string child) + { + _author.Name = title; + _namingConfig.AuthorFolderFormat = "{Author NameFirstCharacter}\\{Author Name}"; + + Subject.GetAuthorFolder(_author).Should().Be(Path.Combine(parent, child)); + } + + [Test] + public void should_be_able_to_use_lower_case_first_character() + { + _author.Name = "Westworld"; + _namingConfig.AuthorFolderFormat = "{author namefirstcharacter}\\{author name}"; + + Subject.GetAuthorFolder(_author).Should().Be(Path.Combine("w", "westworld")); + } + } +} diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 51bf9be49..6cab9f528 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -249,6 +249,7 @@ namespace NzbDrone.Core.Organizer tokenHandlers["{Author CleanName}"] = m => CleanTitle(author.Name); tokenHandlers["{Author NameThe}"] = m => TitleThe(author.Name); tokenHandlers["{Author SortName}"] = m => author.Metadata.Value.NameLastFirst; + tokenHandlers["{Author NameFirstCharacter}"] = m => TitleThe(author.Name).Substring(0, 1).FirstCharToUpper(); if (author.Metadata.Value.Disambiguation != null) {