New: More book title naming tokens

pull/1064/head
ta264 4 years ago
parent 4d840d6f43
commit 13d8554e7e

@ -59,15 +59,29 @@ const authorTokens = [
]; ];
const bookTokens = [ const bookTokens = [
{ token: '{Book Title}', example: 'Book Title' }, { token: '{Book Title}', example: 'Book Title!: Subtitle!' },
{ token: '{Book TitleThe}', example: 'Book Title, The' }, { token: '{Book TitleThe}', example: 'Book Title!, The: Subtitle!' },
{ token: '{Book CleanTitle}', example: 'Book Title' }, { token: '{Book CleanTitle}', example: 'Book Title: Subtitle' },
{ token: '{Book Type}', example: 'Book Type' }, { token: '{Book TitleNoSub}', example: 'Book Title!' },
{ token: '{Book Disambiguation}', example: 'Disambiguation' } { token: '{Book TitleTheNoSub}', example: 'Book Title!, The' },
{ token: '{Book CleanTitleNoSub}', example: 'Book Title' },
{ token: '{Book Subtitle}', example: 'Subtitle!' },
{ token: '{Book SubtitleThe}', example: 'Subtitle!, The' },
{ token: '{Book CleanSubtitle}', example: 'Subtitle' },
{ token: '{Book Disambiguation}', example: 'Disambiguation' },
{ token: '{PartNumber}', example: '2' },
{ token: '{PartCount}', example: '10' }
]; ];
const releaseDateTokens = [ const releaseDateTokens = [

@ -31,6 +31,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
_book = Builder<Book> _book = Builder<Book>
.CreateNew() .CreateNew()
.With(s => s.Title = "Hail to the King") .With(s => s.Title = "Hail to the King")
.With(s => s.AuthorMetadata = _author.Metadata.Value)
.Build(); .Build();
_edition = Builder<Edition> _edition = Builder<Edition>

@ -38,6 +38,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
_book = Builder<Book> _book = Builder<Book>
.CreateNew() .CreateNew()
.With(s => s.Title = "Hybrid Theory") .With(s => s.Title = "Hybrid Theory")
.With(s => s.AuthorMetadata = _author.Metadata.Value)
.Build(); .Build();
_edition = Builder<Edition> _edition = Builder<Edition>
@ -433,7 +434,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
{ {
_namingConfig.StandardBookFormat = "{Author.Name}.{Book.Title}"; _namingConfig.StandardBookFormat = "{Author.Name}.{Book.Title}";
Subject.BuildBookFileName(new Author { Name = "In The Woods." }, new Edition { Title = "30 Rock", Book = new Book() }, _trackFile) Subject.BuildBookFileName(new Author { Name = "In The Woods." }, new Edition { Title = "30 Rock", Book = new Book { AuthorMetadata = new AuthorMetadata { Name = "Author" } } }, _trackFile)
.Should().Be("In.The.Woods.30.Rock"); .Should().Be("In.The.Woods.30.Rock");
} }
@ -442,7 +443,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
{ {
_namingConfig.StandardBookFormat = "{Author.Name}.{Book.Title}"; _namingConfig.StandardBookFormat = "{Author.Name}.{Book.Title}";
Subject.BuildBookFileName(new Author { Name = "In The Woods..." }, new Edition { Title = "30 Rock", Book = new Book() }, _trackFile) Subject.BuildBookFileName(new Author { Name = "In The Woods..." }, new Edition { Title = "30 Rock", Book = new Book { AuthorMetadata = new AuthorMetadata { Name = "Author" } } }, _trackFile)
.Should().Be("In.The.Woods.30.Rock"); .Should().Be("In.The.Woods.30.Rock");
} }

@ -31,6 +31,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
_book = Builder<Book> _book = Builder<Book>
.CreateNew() .CreateNew()
.With(s => s.Title = "Anthology") .With(s => s.Title = "Anthology")
.With(s => s.AuthorMetadata = _author.Metadata.Value)
.Build(); .Build();
_edition = Builder<Edition> _edition = Builder<Edition>

@ -10,6 +10,7 @@ using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Books; using NzbDrone.Core.Books;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Profiles.Releases; using NzbDrone.Core.Profiles.Releases;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
@ -44,7 +45,7 @@ namespace NzbDrone.Core.Organizer
public static readonly Regex AuthorNameRegex = new Regex(@"(?<token>\{(?:Author)(?<separator>[- ._])(Clean)?Name(The)?\})", public static readonly Regex AuthorNameRegex = new Regex(@"(?<token>\{(?:Author)(?<separator>[- ._])(Clean)?Name(The)?\})",
RegexOptions.Compiled | RegexOptions.IgnoreCase); RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static readonly Regex BookTitleRegex = new Regex(@"(?<token>\{(?:Book)(?<separator>[- ._])(Clean)?Title(The)?\})", public static readonly Regex BookTitleRegex = new Regex(@"(?<token>\{(?:Book)(?<separator>[- ._])(Clean)?Title(The)?(NoSub)?\})",
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);
@ -234,6 +235,16 @@ namespace NzbDrone.Core.Organizer
tokenHandlers["{Book CleanTitle}"] = m => CleanTitle(edition.Title); tokenHandlers["{Book CleanTitle}"] = m => CleanTitle(edition.Title);
tokenHandlers["{Book TitleThe}"] = m => TitleThe(edition.Title); tokenHandlers["{Book TitleThe}"] = m => TitleThe(edition.Title);
var (titleNoSub, subtitle) = edition.Title.SplitBookTitle(edition.Book.Value.AuthorMetadata.Value.Name);
tokenHandlers["{Book TitleNoSub}"] = m => titleNoSub;
tokenHandlers["{Book CleanTitleNoSub}"] = m => CleanTitle(titleNoSub);
tokenHandlers["{Book TitleTheNoSub}"] = m => TitleThe(titleNoSub);
tokenHandlers["{Book Subtitle}"] = m => subtitle;
tokenHandlers["{Book CleanSubtitle}"] = m => CleanTitle(subtitle);
tokenHandlers["{Book SubtitleThe}"] = m => TitleThe(subtitle);
if (edition.Disambiguation != null) if (edition.Disambiguation != null)
{ {
tokenHandlers["{Book Disambiguation}"] = m => edition.Disambiguation; tokenHandlers["{Book Disambiguation}"] = m => edition.Disambiguation;

Loading…
Cancel
Save