From 8d8e7ce93b9680ed0bc6ac58b39c16409b15132e Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Tue, 8 Jun 2021 12:33:54 -0500 Subject: [PATCH] Book Grouping (#292) * Implemented the ability to group books by series if certain calibre tags are in the epub. --- API/Services/BookService.cs | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/API/Services/BookService.cs b/API/Services/BookService.cs index 8be3bb0c8..3d35919f0 100644 --- a/API/Services/BookService.cs +++ b/API/Services/BookService.cs @@ -234,6 +234,55 @@ namespace API.Services try { using var epubBook = EpubReader.OpenBook(filePath); + + // If the epub has the following tags, we can group the books as Volumes + // + // + // + // If all three are present, we can take that over dc:title and format as: + // Series = The Dark Tower, Volume = 5, Filename as "Wolves of the Calla" + try + { + string seriesIndex = string.Empty; + string series = string.Empty; + string specialName = string.Empty; + + foreach (var metadataItem in epubBook.Schema.Package.Metadata.MetaItems) + { + switch (metadataItem.Name) + { + case "calibre:series_index": + seriesIndex = metadataItem.Content; + break; + case "calibre:series": + series = metadataItem.Content; + break; + case "calibre:title_sort": + specialName = metadataItem.Content; + break; + } + } + + if (!string.IsNullOrEmpty(series) && !string.IsNullOrEmpty(seriesIndex) && !string.IsNullOrEmpty(specialName)) + { + return new ParserInfo() + { + Chapters = "0", + Edition = "", + Format = MangaFormat.Book, + Filename = Path.GetFileName(filePath), + Title = specialName, + FullFilePath = filePath, + IsSpecial = false, + Series = series, + Volumes = seriesIndex.Split(".")[0] + }; + } + } + catch (Exception) + { + // Swallow exception + } return new ParserInfo() {