Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Book Grouping (#292)

Joseph Milazzo8d8e7ce93b96
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
+ // <meta content="5.0" name="calibre:series_index"/>
+ // <meta content="The Dark Tower" name="calibre:series"/>
+ // <meta content="Wolves of the Calla" name="calibre:title_sort"/>
+ // 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()
{