diff --git a/Documentation/NamingTemplates.md b/Documentation/NamingTemplates.md index 0ec51894..7b277dd1 100644 --- a/Documentation/NamingTemplates.md +++ b/Documentation/NamingTemplates.md @@ -11,7 +11,7 @@ These templates apply to both GUI and CLI. - [Tag Formatters](#tag-formatters) - [Text Formatters](#text-formatters) - [Name List Formatters](#name-list-formatters) - - [Integer Formatters](#integer-formatters) + - [Number Formatters](#number-formatters) - [Date Formatters](#date-formatters) @@ -32,23 +32,23 @@ These tags will be replaced in the template with the audiobook's values. |\|Narrator(s)|Name List| |\|First narrator|Text| |\|Name of series|Text| -|\|Number order in series|Text| -|\|File's original bitrate (Kbps)|Integer| -|\|File's original audio sample rate|Integer| -|\|Number of audio channels|Integer| +|\|Number order in series|Number| +|\|File's original bitrate (Kbps)|Number| +|\|File's original audio sample rate|Number| +|\|Number of audio channels|Number| |\|Audible account of this book|Text| |\|Audible account nickname of this book|Text| |\|Region/country|Text| -|\|Year published|Integer| +|\|Year published|Number| |\|Book's language|Text| |\ **†**|Book's language abbreviated. Eg: ENG|Text| |\|File creation date/time.|DateTime| |\|Audiobook publication date|DateTime| |\|Date the book added to your Audible account|DateTime| -|\ **‡**|Number of chapters|Integer| +|\ **‡**|Number of chapters|Number| |\ **‡**|Chapter title|Text| -|\ **‡**|Chapter number|Integer| -|\ **‡**|Chapter number with leading zeros|Integer| +|\ **‡**|Chapter number|Number| +|\ **‡**|Chapter number with leading zeros|Number| **†** Does not support custom formatting @@ -78,7 +78,7 @@ As an example, this folder template will place all Liberated podcasts into a "Po # Tag Formatters -**Text**, **Name List**, **Integer**, and **DateTime** tags can be optionally formatted using format text in square brackets after the tag name. Below is a list of supported formatters for each tag type. +**Text**, **Name List**, **Number**, and **DateTime** tags can be optionally formatted using format text in square brackets after the tag name. Below is a list of supported formatters for each tag type. ## Text Formatters |Formatter|Description|Example Usage|Example Result| @@ -94,10 +94,12 @@ As an example, this folder template will place all Liberated podcasts into a "Po |sort(F \| M \| L)|Sorts the names by first, middle, or last name

Default is unsorted|``|Stephen Fry, Arthur Conan Doyle| |max(#)|Only use the first # of names

Default is all names|``|Arthur Conan Doyle| -## Integer Formatters +## Number Formatters +For more custom formatters and examples, [see this guide from Microsoft](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings). |Formatter|Description|Example Usage|Example Result| |-|-|-|-| -|# (a number)|Zero-pads the number|\
\
\|0128
001
044100| +|\[integer\]|Zero-pads the number|\
\
\|0128
001
044100| +|0|Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string.|\|001.0| ## Date Formatters Form more standard formatters, [see this guide from Microsoft](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings). diff --git a/Source/FileLiberator/UtilityExtensions.cs b/Source/FileLiberator/UtilityExtensions.cs index b3edf7de..358cdd60 100644 --- a/Source/FileLiberator/UtilityExtensions.cs +++ b/Source/FileLiberator/UtilityExtensions.cs @@ -50,7 +50,7 @@ namespace FileLiberator Narrators = libraryBook.Book.Narrators.Select(c => c.Name).ToList(), SeriesName = libraryBook.Book.SeriesLink.FirstOrDefault()?.Series.Name, - SeriesNumber = (int?)libraryBook.Book.SeriesLink.FirstOrDefault()?.Index, + SeriesNumber = libraryBook.Book.SeriesLink.FirstOrDefault()?.Index, IsPodcastParent = libraryBook.Book.IsEpisodeParent(), IsPodcast = libraryBook.Book.IsEpisodeChild() || libraryBook.Book.IsEpisodeParent(), diff --git a/Source/LibationFileManager/LibraryBookDto.cs b/Source/LibationFileManager/LibraryBookDto.cs index bb09440f..a4e7456e 100644 --- a/Source/LibationFileManager/LibraryBookDto.cs +++ b/Source/LibationFileManager/LibraryBookDto.cs @@ -20,7 +20,7 @@ namespace LibationFileManager public string FirstNarrator => Narrators.FirstOrDefault(); public string SeriesName { get; set; } - public int? SeriesNumber { get; set; } + public float? SeriesNumber { get; set; } public bool IsSeries => !string.IsNullOrEmpty(SeriesName); public bool IsPodcastParent { get; set; } public bool IsPodcast { get; set; } diff --git a/Source/LibationFileManager/Templates.cs b/Source/LibationFileManager/Templates.cs index 4a9358db..4c56d824 100644 --- a/Source/LibationFileManager/Templates.cs +++ b/Source/LibationFileManager/Templates.cs @@ -196,7 +196,7 @@ namespace LibationFileManager #region Registered Template Properties private static readonly PropertyTagCollection filePropertyTags = - new(caseSensative: true, StringFormatter, DateTimeFormatter, IntegerFormatter) + new(caseSensative: true, StringFormatter, DateTimeFormatter, IntegerFormatter, FloatFormatter) { //Don't allow formatting of Id { TemplateTags.Id, lb => lb.AudibleProductId, v => v }, @@ -279,10 +279,20 @@ namespace LibationFileManager } private static string IntegerFormatter(ITemplateTag templateTag, int value, string formatString) + => FloatFormatter(templateTag, value, formatString); + + private static string FloatFormatter(ITemplateTag templateTag, float value, string formatString) { - if (int.TryParse(formatString, out var numDigits)) - return value.ToString($"D{numDigits}"); - return value.ToString(); + if (int.TryParse(formatString, out var numDigits) && numDigits > 0) + { + //Zero-pad the integer part + var strValue = value.ToString(); + var decIndex = strValue.IndexOf(System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator); + var zeroPad = decIndex == -1 ? int.Max(0, numDigits - strValue.Length) : int.Max(0, numDigits - decIndex); + + return new string('0', zeroPad) + strValue; + } + return value.ToString(formatString); } private static string DateTimeFormatter(ITemplateTag templateTag, DateTime value, string formatString)