mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-05-25 00:52:33 -04:00
Implemented ability to generate Series summary from ComicInfo.xml (if present)
This commit is contained in:
@@ -3,6 +3,9 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using API.Extensions;
|
||||
using API.Interfaces;
|
||||
using API.Interfaces.Services;
|
||||
@@ -146,7 +149,34 @@ namespace API.Services
|
||||
|
||||
public string GetSummaryInfo(string archivePath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var summary = "";
|
||||
if (!IsValidArchive(archivePath)) return summary;
|
||||
|
||||
using var archive = ZipFile.OpenRead(archivePath);
|
||||
if (!archive.HasFiles()) return summary;
|
||||
|
||||
var info = archive.Entries.SingleOrDefault(x => Path.GetFileNameWithoutExtension(x.Name).ToLower() == "comicinfo" && Parser.Parser.IsXml(x.FullName));
|
||||
if (info == null) return summary;
|
||||
|
||||
// Parse XML file
|
||||
try
|
||||
{
|
||||
using var stream = info.Open();
|
||||
var serializer = new XmlSerializer(typeof(ComicInfo));
|
||||
ComicInfo comicInfo =
|
||||
(ComicInfo)serializer.Deserialize(stream);
|
||||
|
||||
if (comicInfo != null)
|
||||
{
|
||||
return comicInfo.Summary;
|
||||
}
|
||||
}
|
||||
catch (AggregateException ex)
|
||||
{
|
||||
_logger.LogError(ex, "There was an issue parsing ComicInfo.xml from {ArchivePath}", archivePath);
|
||||
}
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace API.Services
|
||||
{
|
||||
public class ComicInfo
|
||||
{
|
||||
public string Summary;
|
||||
public string Title;
|
||||
public string Series;
|
||||
public string Notes;
|
||||
public string Publisher;
|
||||
public string Genre;
|
||||
public int PageCount;
|
||||
public string LanguageISO;
|
||||
public string Web;
|
||||
}
|
||||
}
|
||||
@@ -65,10 +65,14 @@ namespace API.Services
|
||||
}
|
||||
series.CoverImage = firstCover?.CoverImage;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(series.Summary) && !forceUpdate) return;
|
||||
|
||||
if (string.IsNullOrEmpty(series.Summary) || forceUpdate)
|
||||
var firstVolume = series.Volumes.FirstOrDefault(v => v.Chapters.Any() && v.Number == 1);
|
||||
var firstChapter = firstVolume?.Chapters.FirstOrDefault(c => c.Files.Any());
|
||||
if (firstChapter != null)
|
||||
{
|
||||
series.Summary = _archiveService.GetSummaryInfo(series.Volumes.First().Chapters.First().Files.First().FilePath);
|
||||
series.Summary = _archiveService.GetSummaryInfo(firstChapter.Files.FirstOrDefault()?.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user