From a3fac3441c0b9657b96a522ac70ee82e7c472121 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Wed, 6 Oct 2021 13:43:01 -0600 Subject: [PATCH 1/3] Allow splitting book only if AllowLibationFixup is true. --- LibationWinForms/Dialogs/SettingsDialog.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LibationWinForms/Dialogs/SettingsDialog.cs b/LibationWinForms/Dialogs/SettingsDialog.cs index 9f686eb2..c96e1664 100644 --- a/LibationWinForms/Dialogs/SettingsDialog.cs +++ b/LibationWinForms/Dialogs/SettingsDialog.cs @@ -84,10 +84,12 @@ namespace LibationWinForms.Dialogs { convertLosslessRb.Enabled = allowLibationFixupCbox.Checked; convertLossyRb.Enabled = allowLibationFixupCbox.Checked; + splitFilesByChapterCbox.Enabled = allowLibationFixupCbox.Checked; if (!allowLibationFixupCbox.Checked) { convertLosslessRb.Checked = true; + splitFilesByChapterCbox.Checked = false; } } From f1c87308ead4140db72a63852f2e0e3f5306089c Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Wed, 6 Oct 2021 13:43:19 -0600 Subject: [PATCH 2/3] Fixed access modifier. --- FileLiberator/Processable.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FileLiberator/Processable.cs b/FileLiberator/Processable.cs index 9f565d06..3043b07d 100644 --- a/FileLiberator/Processable.cs +++ b/FileLiberator/Processable.cs @@ -24,13 +24,13 @@ namespace FileLiberator public abstract Task ProcessAsync(LibraryBook libraryBook); // when used in foreach: stateful. deferred execution - protected IEnumerable GetValidLibraryBooks(IEnumerable library) + public IEnumerable GetValidLibraryBooks(IEnumerable library) => library.Where(libraryBook => Validate(libraryBook) && (libraryBook.Book.ContentType != ContentType.Episode || FileManager.Configuration.Instance.DownloadEpisodes) ); - protected async Task ProcessSingleAsync(LibraryBook libraryBook, bool validate) + public async Task ProcessSingleAsync(LibraryBook libraryBook, bool validate) { if (validate && !Validate(libraryBook)) return new StatusHandler { "Validation failed" }; @@ -50,7 +50,7 @@ namespace FileLiberator return status; } - protected async Task TryProcessAsync(LibraryBook libraryBook) + public async Task TryProcessAsync(LibraryBook libraryBook) => Validate(libraryBook) ? await ProcessAsync(libraryBook) : new StatusHandler(); From b870d562ff4c5f04840928dc88444058d2d725c1 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Wed, 6 Oct 2021 13:44:03 -0600 Subject: [PATCH 3/3] Only split chapters at least 15 seconds long. --- AaxDecrypter/AaxcDownloadConverter.cs | 34 ++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/AaxDecrypter/AaxcDownloadConverter.cs b/AaxDecrypter/AaxcDownloadConverter.cs index c7df6961..d1171967 100644 --- a/AaxDecrypter/AaxcDownloadConverter.cs +++ b/AaxDecrypter/AaxcDownloadConverter.cs @@ -4,11 +4,13 @@ using Dinah.Core.Net.Http; using Dinah.Core.StepRunner; using System; using System.IO; +using System.Linq; namespace AaxDecrypter { public class AaxcDownloadConverter : AudiobookDownloadBase { + private static readonly TimeSpan minChapterLength = TimeSpan.FromSeconds(15); protected override StepSequence steps { get; } private AaxFile aaxFile; @@ -81,11 +83,30 @@ namespace AaxDecrypter { var zeroProgress = Step2_Start(); + var chapters = downloadLicense.ChapterInfo.Chapters.ToList(); + + //Ensure split files are at least minChapterLength in duration. + var splitChapters = new ChapterInfo(); + splitChapters.AddChapter(chapters[0].Title, chapters[0].Duration); + + var runningTotal = chapters[0].Duration; + + for (int i = 1; i < chapters.Count; i++) + { + if (runningTotal >= minChapterLength) + { + splitChapters.AddChapter(chapters[i].Title, chapters[i].Duration); + runningTotal = chapters[i].Duration; + } + else + runningTotal += chapters[i].Duration; + } + aaxFile.ConversionProgressUpdate += AaxFile_ConversionProgressUpdate; if(OutputFormat == OutputFormat.M4b) - ConvertToMultiMp4b(); + ConvertToMultiMp4b(splitChapters); else - ConvertToMultiMp3(); + ConvertToMultiMp3(splitChapters); aaxFile.ConversionProgressUpdate -= AaxFile_ConversionProgressUpdate; Step2_End(zeroProgress); @@ -117,10 +138,10 @@ namespace AaxDecrypter OnDecryptProgressUpdate(zeroProgress); } - private void ConvertToMultiMp4b() + private void ConvertToMultiMp4b(ChapterInfo splitChapters) { var chapterCount = 0; - aaxFile.ConvertToMultiMp4a(downloadLicense.ChapterInfo, newSplitCallback => + aaxFile.ConvertToMultiMp4a(splitChapters, newSplitCallback => { chapterCount++; var fileName = Path.ChangeExtension(outputFileName, $"{chapterCount}.m4b"); @@ -130,10 +151,11 @@ namespace AaxDecrypter }); } - private void ConvertToMultiMp3() + private void ConvertToMultiMp3(ChapterInfo splitChapters) { var chapterCount = 0; - aaxFile.ConvertToMultiMp3(downloadLicense.ChapterInfo, newSplitCallback => + + aaxFile.ConvertToMultiMp3(splitChapters, newSplitCallback => { chapterCount++; var fileName = Path.ChangeExtension(outputFileName, $"{chapterCount}.mp3");