From 20e792c589c1c342e7af9ea2b0c7686c10c66bc0 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 9 May 2025 13:36:07 -0600 Subject: [PATCH] Always change the last chapter's length to coincide with the end of the audio file. --- Source/FileLiberator/DownloadDecryptBook.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Source/FileLiberator/DownloadDecryptBook.cs b/Source/FileLiberator/DownloadDecryptBook.cs index a5ec6f9e..3ead2a9f 100644 --- a/Source/FileLiberator/DownloadDecryptBook.cs +++ b/Source/FileLiberator/DownloadDecryptBook.cs @@ -184,16 +184,13 @@ namespace FileLiberator fileDuration -= TimeSpan.FromMilliseconds(options.ContentMetadata.ChapterInfo.BrandOutroDurationMs); var durationDelta = fileDuration - options.ChapterInfo.EndOffset; - if (durationDelta.TotalMilliseconds > 0) - { - //only fix chapters which are shorter than the file. Chapters which are longer - //than the file will be truncated to match the file length, which is correct. - var chapters = options.ChapterInfo.Chapters as List; - var lastChapter = chapters[^1]; + //Remove the last chapter and re-add it with the durationDelta that will + //make the chapter's end coincide with the end of the audio file. + var chapters = options.ChapterInfo.Chapters as List; + var lastChapter = chapters[^1]; - chapters.Remove(lastChapter); - options.ChapterInfo.Add(lastChapter.Title, lastChapter.Duration + durationDelta); - } + chapters.Remove(lastChapter); + options.ChapterInfo.Add(lastChapter.Title, lastChapter.Duration + durationDelta); #endregion