diff --git a/Source/LibationFileManager/TemplateTags.cs b/Source/LibationFileManager/TemplateTags.cs index e4146d28..864258c8 100644 --- a/Source/LibationFileManager/TemplateTags.cs +++ b/Source/LibationFileManager/TemplateTags.cs @@ -48,7 +48,7 @@ namespace LibationFileManager // Included here for display by EditTemplateDialog public static TemplateTags FileDate { get; } = new TemplateTags("file date [...]", "File date/time. e.g. yyyy-MM-dd HH-mm", false, $""); public static TemplateTags DatePublished { get; } = new TemplateTags("pub date [...]", "Publication date. e.g. yyyy-MM-dd", false, $""); - public static TemplateTags DateAdded { get; } = new TemplateTags("date added [...]", "Date added to you Audible account. e.g. yyyy-MM-dd", false, $""); + public static TemplateTags DateAdded { get; } = new TemplateTags("date added [...]", "Date added to your Audible account. e.g. yyyy-MM-dd", false, $""); public static TemplateTags IfSeries { get; } = new TemplateTags("if series->...<-if series", "Only include if part of a series", false, "<-if series>"); } } diff --git a/Source/LibationFileManager/Templates.cs b/Source/LibationFileManager/Templates.cs index 19dc62d9..8880efd1 100644 --- a/Source/LibationFileManager/Templates.cs +++ b/Source/LibationFileManager/Templates.cs @@ -107,9 +107,9 @@ namespace LibationFileManager .GetFilePath(fileExtension).PathWithoutPrefix; public const string DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; - private static Regex fileDateTagRegex { get; } = new Regex(@"", RegexOptions.Compiled | RegexOptions.IgnoreCase); - private static Regex dateAddedTagRegex { get; } = new Regex(@"", RegexOptions.Compiled | RegexOptions.IgnoreCase); - private static Regex datePublishedTagRegex { get; } = new Regex(@"", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static Regex fileDateTagRegex { get; } = new Regex(@"", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static Regex dateAddedTagRegex { get; } = new Regex(@"", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static Regex datePublishedTagRegex { get; } = new Regex(@"", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static Regex ifSeriesRegex { get; } = new Regex("(.*?)<-if series>", RegexOptions.Compiled | RegexOptions.IgnoreCase); internal static FileNamingTemplate getFileNamingTemplate(LibraryBookDto libraryBookDto, string template, string dirFullPath, string extension, ReplacementCharacters replacements) @@ -192,7 +192,7 @@ namespace LibationFileManager /// a date parameter replacement tag with the format string sanitized private static string sanitizeDateParameterTag(Match dateTag, ReplacementCharacters replacements, out string sanitizedFormatter) { - if (dateTag.Groups.Count < 2 || string.IsNullOrWhiteSpace(dateTag.Groups[1].Value)) + if (dateTag.Groups.Count != 2 || string.IsNullOrWhiteSpace(dateTag.Groups[1].Value)) { sanitizedFormatter = DEFAULT_DATE_FORMAT; return dateTag.Value; diff --git a/Source/_Tests/LibationFileManager.Tests/TemplatesTests.cs b/Source/_Tests/LibationFileManager.Tests/TemplatesTests.cs index 93759d85..400565d3 100644 --- a/Source/_Tests/LibationFileManager.Tests/TemplatesTests.cs +++ b/Source/_Tests/LibationFileManager.Tests/TemplatesTests.cs @@ -102,27 +102,25 @@ namespace TemplatesTests => Templates.getFileNamingTemplate(GetLibraryBook(), template, dirFullPath, extension, Replacements); [TestMethod] - [DataRow("f.txt", @"C:\foo\bar", "", @"C:\foo\bar\f.txt", PlatformID.Win32NT)] - [DataRow("f.txt", @"/foo/bar", "", @"/foo/bar/f.txt", PlatformID.Unix)] - [DataRow("f.txt", @"C:\foo\bar", ".ext", @"C:\foo\bar\f.txt.ext", PlatformID.Win32NT)] - [DataRow("f.txt", @"/foo/bar", ".ext", @"/foo/bar/f.txt.ext", PlatformID.Unix)] - [DataRow("f", @"C:\foo\bar", ".ext", @"C:\foo\bar\f.ext", PlatformID.Win32NT)] - [DataRow("f", @"/foo/bar", ".ext", @"/foo/bar/f.ext", PlatformID.Unix)] - [DataRow("", @"C:\foo\bar", ".ext", @"C:\foo\bar\asin.ext", PlatformID.Win32NT)] - [DataRow("", @"/foo/bar", ".ext", @"/foo/bar/asin.ext", PlatformID.Unix)] - [DataRow(" - - ", @"C:\foo\bar", ".ext", @"C:\foo\bar\128 - 44100 - 2.ext", PlatformID.Win32NT)] - [DataRow(" - - ", @"/foo/bar", ".ext", @"/foo/bar/128 - 44100 - 2.ext", PlatformID.Unix)] - [DataRow(" - ", @"C:\foo\bar", ".ext", @"C:\foo\bar\2017 - 2.ext", PlatformID.Win32NT)] - [DataRow(" - ", @"/foo/bar", ".ext", @"/foo/bar/2017 - 2.ext", PlatformID.Unix)] - [DataRow("(000.0) - ", @"C:\foo\bar", "ext", @"C:\foo\bar\(000.0) 2017 - 2.ext", PlatformID.Win32NT)] - [DataRow("(000.0) - ", @"/foo/bar", ".ext", @"/foo/bar/(000.0) 2017 - 2.ext", PlatformID.Unix)] - public void Tests(string template, string dirFullPath, string extension, string expected, PlatformID platformID) + [DataRow("f.txt", @"C:\foo\bar", "", @"C:\foo\bar\f.txt")] + [DataRow("f.txt", @"C:\foo\bar", ".ext", @"C:\foo\bar\f.txt.ext")] + [DataRow("f", @"C:\foo\bar", ".ext", @"C:\foo\bar\f.ext")] + [DataRow("", @"C:\foo\bar", ".ext", @"C:\foo\bar\asin.ext")] + [DataRow(" - - ", @"C:\foo\bar", ".ext", @"C:\foo\bar\128 - 44100 - 2.ext")] + [DataRow(" - ", @"C:\foo\bar", ".ext", @"C:\foo\bar\2017 - 2.ext")] + [DataRow("(000.0) - ", @"C:\foo\bar", "ext", @"C:\foo\bar\(000.0) 2017 - 2.ext")] + public void Tests(string template, string dirFullPath, string extension, string expected) { - if (Environment.OSVersion.Platform == platformID) - Templates.getFileNamingTemplate(GetLibraryBook(), template, dirFullPath, extension, Replacements) - .GetFilePath(extension) - .PathWithoutPrefix - .Should().Be(expected); + if (Environment.OSVersion.Platform is not PlatformID.Win32NT) + { + dirFullPath = dirFullPath.Replace("C:", "").Replace('\\', '/'); + expected = expected.Replace("C:", "").Replace('\\', '/'); + } + + Templates.getFileNamingTemplate(GetLibraryBook(), template, dirFullPath, extension, Replacements) + .GetFilePath(extension) + .PathWithoutPrefix + .Should().Be(expected); } [TestMethod] @@ -154,8 +152,12 @@ namespace TemplatesTests [TestMethod] [DataRow("", @"C:\foo\bar", ".m4b", @"C:\foo\bar\<filedate[h]>.m4b")] [DataRow("< filedate[yyyy]>", @"C:\foo\bar", ".m4b", @"C:\foo\bar\< filedate[yyyy]>.m4b")] + [DataRow("", @"C:\foo\bar", ".m4b", @"C:\foo\bar\<filedate[yyyy][]>.m4b")] + [DataRow("", @"C:\foo\bar", ".m4b", @"C:\foo\bar\<filedate[yyyy[]]>.m4b")] [DataRow("", @"C:\foo\bar", ".m4b", @"C:\foo\bar\<filedate yyyy]>.m4b")] + [DataRow("", @"C:\foo\bar", ".m4b", @"C:\foo\bar\<filedate ]yyyy]>.m4b")] [DataRow("", @"C:\foo\bar", ".m4b", @"C:\foo\bar\<filedate [yyyy>.m4b")] + [DataRow("", @"C:\foo\bar", ".m4b", @"C:\foo\bar\<filedate [yyyy[>.m4b")] [DataRow("", @"C:\foo\bar", ".m4b", @"C:\foo\bar\<filedate yyyy>.m4b")] [DataRow("", @"C:\foo\bar", ".m4b", @"C:\foo\bar\<fil edate[yyyy]>.m4b")]