Use series order float (#632)

Add decimal formatter to number tag types
This commit is contained in:
Mbucari 2023-06-15 10:04:17 -06:00
parent a386ace0e6
commit bd3e833dc1
4 changed files with 30 additions and 18 deletions

View File

@ -11,7 +11,7 @@ These templates apply to both GUI and CLI.
- [Tag Formatters](#tag-formatters) - [Tag Formatters](#tag-formatters)
- [Text Formatters](#text-formatters) - [Text Formatters](#text-formatters)
- [Name List Formatters](#name-list-formatters) - [Name List Formatters](#name-list-formatters)
- [Integer Formatters](#integer-formatters) - [Number Formatters](#number-formatters)
- [Date Formatters](#date-formatters) - [Date Formatters](#date-formatters)
@ -32,23 +32,23 @@ These tags will be replaced in the template with the audiobook's values.
|\<narrator\>|Narrator(s)|Name List| |\<narrator\>|Narrator(s)|Name List|
|\<first narrator\>|First narrator|Text| |\<first narrator\>|First narrator|Text|
|\<series\>|Name of series|Text| |\<series\>|Name of series|Text|
|\<series#\>|Number order in series|Text| |\<series#\>|Number order in series|Number|
|\<bitrate\>|File's original bitrate (Kbps)|Integer| |\<bitrate\>|File's original bitrate (Kbps)|Number|
|\<samplerate\>|File's original audio sample rate|Integer| |\<samplerate\>|File's original audio sample rate|Number|
|\<channels\>|Number of audio channels|Integer| |\<channels\>|Number of audio channels|Number|
|\<account\>|Audible account of this book|Text| |\<account\>|Audible account of this book|Text|
|\<account nickname\>|Audible account nickname of this book|Text| |\<account nickname\>|Audible account nickname of this book|Text|
|\<locale\>|Region/country|Text| |\<locale\>|Region/country|Text|
|\<year\>|Year published|Integer| |\<year\>|Year published|Number|
|\<language\>|Book's language|Text| |\<language\>|Book's language|Text|
|\<language short\> **†**|Book's language abbreviated. Eg: ENG|Text| |\<language short\> **†**|Book's language abbreviated. Eg: ENG|Text|
|\<file date\>|File creation date/time.|DateTime| |\<file date\>|File creation date/time.|DateTime|
|\<pub date\>|Audiobook publication date|DateTime| |\<pub date\>|Audiobook publication date|DateTime|
|\<date added\>|Date the book added to your Audible account|DateTime| |\<date added\>|Date the book added to your Audible account|DateTime|
|\<ch count\> **‡**|Number of chapters|Integer| |\<ch count\> **‡**|Number of chapters|Number|
|\<ch title\> **‡**|Chapter title|Text| |\<ch title\> **‡**|Chapter title|Text|
|\<ch#\> **‡**|Chapter number|Integer| |\<ch#\> **‡**|Chapter number|Number|
|\<ch# 0\> **‡**|Chapter number with leading zeros|Integer| |\<ch# 0\> **‡**|Chapter number with leading zeros|Number|
**†** Does not support custom formatting **†** 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 # 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 ## Text Formatters
|Formatter|Description|Example Usage|Example Result| |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<br><br>Default is unsorted|`<author[sort(M)]>`|Stephen Fry, Arthur Conan Doyle| |sort(F \| M \| L)|Sorts the names by first, middle, or last name<br><br>Default is unsorted|`<author[sort(M)]>`|Stephen Fry, Arthur Conan Doyle|
|max(#)|Only use the first # of names<br><br>Default is all names|`<author[max(1)]>`|Arthur Conan Doyle| |max(#)|Only use the first # of names<br><br>Default is all names|`<author[max(1)]>`|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| |Formatter|Description|Example Usage|Example Result|
|-|-|-|-| |-|-|-|-|
|# (a number)|Zero-pads the number|\<bitrate\[4\]\><br>\<series#\[3\]\><br>\<samplerate\[6\]\>|0128<br>001<br>044100| |\[integer\]|Zero-pads the number|\<bitrate\[4\]\><br>\<series#\[3\]\><br>\<samplerate\[6\]\>|0128<br>001<br>044100|
|0|Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string.|\<series#\[000.0\]\>|001.0|
## Date Formatters ## 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). 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).

View File

@ -50,7 +50,7 @@ namespace FileLiberator
Narrators = libraryBook.Book.Narrators.Select(c => c.Name).ToList(), Narrators = libraryBook.Book.Narrators.Select(c => c.Name).ToList(),
SeriesName = libraryBook.Book.SeriesLink.FirstOrDefault()?.Series.Name, SeriesName = libraryBook.Book.SeriesLink.FirstOrDefault()?.Series.Name,
SeriesNumber = (int?)libraryBook.Book.SeriesLink.FirstOrDefault()?.Index, SeriesNumber = libraryBook.Book.SeriesLink.FirstOrDefault()?.Index,
IsPodcastParent = libraryBook.Book.IsEpisodeParent(), IsPodcastParent = libraryBook.Book.IsEpisodeParent(),
IsPodcast = libraryBook.Book.IsEpisodeChild() || libraryBook.Book.IsEpisodeParent(), IsPodcast = libraryBook.Book.IsEpisodeChild() || libraryBook.Book.IsEpisodeParent(),

View File

@ -20,7 +20,7 @@ namespace LibationFileManager
public string FirstNarrator => Narrators.FirstOrDefault(); public string FirstNarrator => Narrators.FirstOrDefault();
public string SeriesName { get; set; } public string SeriesName { get; set; }
public int? SeriesNumber { get; set; } public float? SeriesNumber { get; set; }
public bool IsSeries => !string.IsNullOrEmpty(SeriesName); public bool IsSeries => !string.IsNullOrEmpty(SeriesName);
public bool IsPodcastParent { get; set; } public bool IsPodcastParent { get; set; }
public bool IsPodcast { get; set; } public bool IsPodcast { get; set; }

View File

@ -196,7 +196,7 @@ namespace LibationFileManager
#region Registered Template Properties #region Registered Template Properties
private static readonly PropertyTagCollection<LibraryBookDto> filePropertyTags = private static readonly PropertyTagCollection<LibraryBookDto> filePropertyTags =
new(caseSensative: true, StringFormatter, DateTimeFormatter, IntegerFormatter) new(caseSensative: true, StringFormatter, DateTimeFormatter, IntegerFormatter, FloatFormatter)
{ {
//Don't allow formatting of Id //Don't allow formatting of Id
{ TemplateTags.Id, lb => lb.AudibleProductId, v => v }, { TemplateTags.Id, lb => lb.AudibleProductId, v => v },
@ -279,10 +279,20 @@ namespace LibationFileManager
} }
private static string IntegerFormatter(ITemplateTag templateTag, int value, string formatString) 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)) if (int.TryParse(formatString, out var numDigits) && numDigits > 0)
return value.ToString($"D{numDigits}"); {
return value.ToString(); //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) private static string DateTimeFormatter(ITemplateTag templateTag, DateTime value, string formatString)