mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
Implemented ability to generate Series summary from ComicInfo.xml (if present)
This commit is contained in:
parent
5be01b529b
commit
265f7dcc8c
@ -10,8 +10,10 @@ namespace API.Parser
|
|||||||
{
|
{
|
||||||
public static readonly string MangaFileExtensions = @"\.cbz|\.zip"; // |\.rar|\.cbr
|
public static readonly string MangaFileExtensions = @"\.cbz|\.zip"; // |\.rar|\.cbr
|
||||||
public static readonly string ImageFileExtensions = @"\.png|\.jpeg|\.jpg|\.gif";
|
public static readonly string ImageFileExtensions = @"\.png|\.jpeg|\.jpg|\.gif";
|
||||||
|
private static readonly string XmlRegexExtensions = @"\.xml";
|
||||||
private static readonly Regex ImageRegex = new Regex(ImageFileExtensions, RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
private static readonly Regex ImageRegex = new Regex(ImageFileExtensions, RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
private static readonly Regex MangaFileRegex = new Regex(MangaFileExtensions, RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
private static readonly Regex MangaFileRegex = new Regex(MangaFileExtensions, RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
|
private static readonly Regex XmlRegex = new Regex(XmlRegexExtensions, RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
|
|
||||||
//?: is a non-capturing group in C#, else anything in () will be a group
|
//?: is a non-capturing group in C#, else anything in () will be a group
|
||||||
private static readonly Regex[] MangaVolumeRegex = new[]
|
private static readonly Regex[] MangaVolumeRegex = new[]
|
||||||
@ -406,6 +408,12 @@ namespace API.Parser
|
|||||||
return ImageRegex.IsMatch(fileInfo.Extension);
|
return ImageRegex.IsMatch(fileInfo.Extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsXml(string filePath)
|
||||||
|
{
|
||||||
|
var fileInfo = new FileInfo(filePath);
|
||||||
|
return XmlRegex.IsMatch(fileInfo.Extension);
|
||||||
|
}
|
||||||
|
|
||||||
public static float MinimumNumberFromRange(string range)
|
public static float MinimumNumberFromRange(string range)
|
||||||
{
|
{
|
||||||
var tokens = range.Split("-");
|
var tokens = range.Split("-");
|
||||||
@ -416,5 +424,7 @@ namespace API.Parser
|
|||||||
{
|
{
|
||||||
return name.ToLower().Replace("-", "").Replace(" ", "");
|
return name.ToLower().Replace("-", "").Replace(" ", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,6 +3,9 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using System.Xml.Serialization;
|
||||||
using API.Extensions;
|
using API.Extensions;
|
||||||
using API.Interfaces;
|
using API.Interfaces;
|
||||||
using API.Interfaces.Services;
|
using API.Interfaces.Services;
|
||||||
@ -146,7 +149,34 @@ namespace API.Services
|
|||||||
|
|
||||||
public string GetSummaryInfo(string archivePath)
|
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>
|
/// <summary>
|
||||||
|
15
API/Services/ComicInfo.cs
Normal file
15
API/Services/ComicInfo.cs
Normal file
@ -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;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user