mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-05-30 19:35:21 -04:00
PDF Metadata Support (#3552)
Co-authored-by: Matthias Neeracher <microtherion@gmail.com>
This commit is contained in:
@@ -6,12 +6,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using API.Data.Metadata;
|
||||
using API.DTOs.Reader;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Extensions;
|
||||
using API.Services.Tasks.Scanner.Parser;
|
||||
using API.Helpers;
|
||||
using Docnet.Core;
|
||||
using Docnet.Core.Converters;
|
||||
using Docnet.Core.Models;
|
||||
@@ -69,6 +71,8 @@ public class BookService : IBookService
|
||||
private static readonly RecyclableMemoryStreamManager StreamManager = new ();
|
||||
private const string CssScopeClass = ".book-content";
|
||||
private const string BookApiUrl = "book-resources?file=";
|
||||
private readonly PdfComicInfoExtractor _pdfComicInfoExtractor;
|
||||
|
||||
public static readonly EpubReaderOptions BookReaderOptions = new()
|
||||
{
|
||||
PackageReaderOptions = new PackageReaderOptions
|
||||
@@ -84,6 +88,7 @@ public class BookService : IBookService
|
||||
_directoryService = directoryService;
|
||||
_imageService = imageService;
|
||||
_mediaErrorService = mediaErrorService;
|
||||
_pdfComicInfoExtractor = new PdfComicInfoExtractor(_logger, _mediaErrorService);
|
||||
}
|
||||
|
||||
private static bool HasClickableHrefPart(HtmlNode anchor)
|
||||
@@ -425,10 +430,8 @@ public class BookService : IBookService
|
||||
}
|
||||
}
|
||||
|
||||
public ComicInfo? GetComicInfo(string filePath)
|
||||
private ComicInfo? GetEpubComicInfo(string filePath)
|
||||
{
|
||||
if (!IsValidFile(filePath) || Parser.IsPdf(filePath)) return null;
|
||||
|
||||
try
|
||||
{
|
||||
using var epubBook = EpubReader.OpenBook(filePath, BookReaderOptions);
|
||||
@@ -442,7 +445,7 @@ public class BookService : IBookService
|
||||
var (year, month, day) = GetPublicationDate(publicationDate);
|
||||
|
||||
var summary = epubBook.Schema.Package.Metadata.Descriptions.FirstOrDefault();
|
||||
var info = new ComicInfo
|
||||
var info = new ComicInfo
|
||||
{
|
||||
Summary = string.IsNullOrEmpty(summary?.Description) ? string.Empty : summary.Description,
|
||||
Publisher = string.Join(",", epubBook.Schema.Package.Metadata.Publishers.Select(p => p.Publisher)),
|
||||
@@ -583,6 +586,20 @@ public class BookService : IBookService
|
||||
return null;
|
||||
}
|
||||
|
||||
public ComicInfo? GetComicInfo(string filePath)
|
||||
{
|
||||
if (!IsValidFile(filePath)) return null;
|
||||
|
||||
if (Parser.IsPdf(filePath))
|
||||
{
|
||||
return _pdfComicInfoExtractor.GetComicInfo(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetEpubComicInfo(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExtractSortTitle(EpubMetadataMeta metadataItem, EpubBookRef epubBook, ComicInfo info)
|
||||
{
|
||||
var titleId = metadataItem.Refines?.Replace("#", string.Empty);
|
||||
@@ -685,7 +702,7 @@ public class BookService : IBookService
|
||||
return (year, month, day);
|
||||
}
|
||||
|
||||
private static string ValidateLanguage(string? language)
|
||||
public static string ValidateLanguage(string? language)
|
||||
{
|
||||
if (string.IsNullOrEmpty(language)) return string.Empty;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user