From 1de7edd9dfce50f974a7700d455e28b22b00eb50 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Sat, 9 Oct 2021 14:20:21 -0400 Subject: [PATCH] Chapter splitting: file names need more leading zeros when qty >100 --- AaxDecrypter/AaxcDownloadConverter.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/AaxDecrypter/AaxcDownloadConverter.cs b/AaxDecrypter/AaxcDownloadConverter.cs index 26a6abff..87bb7d30 100644 --- a/AaxDecrypter/AaxcDownloadConverter.cs +++ b/AaxDecrypter/AaxcDownloadConverter.cs @@ -187,7 +187,7 @@ That naming may not be desirable for everyone, but it's an easy change to instea var chapterCount = 0; aaxFile.ConvertToMultiMp4a(splitChapters, newSplitCallback => { - var fileName = GetMultipartFileName(++chapterCount, newSplitCallback.Chapter.Title); + var fileName = GetMultipartFileName(++chapterCount, splitChapters.Count, newSplitCallback.Chapter.Title); if (File.Exists(fileName)) FileExt.SafeDelete(fileName); newSplitCallback.OutputFile = File.Open(fileName, FileMode.OpenOrCreate); @@ -199,7 +199,7 @@ That naming may not be desirable for everyone, but it's an easy change to instea var chapterCount = 0; aaxFile.ConvertToMultiMp3(splitChapters, newSplitCallback => { - var fileName = GetMultipartFileName(++chapterCount, newSplitCallback.Chapter.Title); + var fileName = GetMultipartFileName(++chapterCount, splitChapters.Count, newSplitCallback.Chapter.Title); if (File.Exists(fileName)) FileExt.SafeDelete(fileName); newSplitCallback.OutputFile = File.Open(fileName, FileMode.OpenOrCreate); @@ -208,11 +208,16 @@ That naming may not be desirable for everyone, but it's an easy change to instea } // return. cache name for event call at end of processing - private string GetMultipartFileName(int chapterCount, string chapterTitle) + private string GetMultipartFileName(int chapterCount, int chaptersTotal, string chapterTitle) { + // 1-9 => 1-9 + // 10-99 => 01-99 + // 100-999 => 001-999 + var chapterCountLeadingZeros = chapterCount.ToString().PadLeft(chaptersTotal.ToString().Length, '0'); + string extension = Path.GetExtension(OutputFileName); - var filenameBase = $"{Path.GetFileNameWithoutExtension(OutputFileName)} - {chapterCount:D2} - {chapterTitle}"; + var filenameBase = $"{Path.GetFileNameWithoutExtension(OutputFileName)} - {chapterCountLeadingZeros} - {chapterTitle}"; // Replace illegal path characters with spaces var filenameBaseSafe = string.Join(" ", filenameBase.Split(Path.GetInvalidFileNameChars())); var fileName = filenameBaseSafe.Truncate(MAX_FILENAME_LENGTH - extension.Length);