From 13149eff08cb0e7b58ffe193c144a20616541c86 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Thu, 23 Jun 2022 17:29:45 -0600 Subject: [PATCH] Make better use of heirarch chapters to combine section title audio (which is usually short, eg "Part 1") with the following full-length chapter. --- Source/FileLiberator/DownloadDecryptBook.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/FileLiberator/DownloadDecryptBook.cs b/Source/FileLiberator/DownloadDecryptBook.cs index f3686ca5..257a17cf 100644 --- a/Source/FileLiberator/DownloadDecryptBook.cs +++ b/Source/FileLiberator/DownloadDecryptBook.cs @@ -194,19 +194,31 @@ namespace FileLiberator private List getChapters(IEnumerable chapters) { - List chaps = chapters.ToList(); + List chaps = new(); foreach (var c in chapters) { if (c.Chapters is not null) { - var children = getChapters(c.Chapters); + var firstSub = new AudibleApi.Common.Chapter + { + Title = $"{c.Title}: {c.Chapters[0].Title}", + StartOffsetMs = c.StartOffsetMs, + StartOffsetSec = c.StartOffsetSec, + LengthMs = c.LengthMs + c.Chapters[0].LengthMs + }; + + chaps.Add(firstSub); + + var children = getChapters(c.Chapters[1..]); foreach (var child in children) child.Title = string.IsNullOrEmpty(c.Title) ? child.Title : $"{c.Title}: {child.Title}"; chaps.AddRange(children); } + else + chaps.Add(c); } return chaps; }