mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-10-26 16:45:09 +00:00
Fix EPUB metadata and covers not loading on Windows
Original-merge: 56989b0c80
Merged-by: crobibero <cody@robibe.ro>
Backported-by: Cody Robibero <cody@robibe.ro>
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using System.IO.Compression;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
|
|
namespace MediaBrowser.Providers.Books.OpenPackagingFormat
|
|
{
|
|
/// <summary>
|
|
/// Utilities for EPUB files.
|
|
/// </summary>
|
|
public static class EpubUtils
|
|
{
|
|
/// <summary>
|
|
/// Attempt to read content from ZIP archive.
|
|
/// </summary>
|
|
/// <param name="epub">The ZIP archive.</param>
|
|
/// <returns>The content file path.</returns>
|
|
public static string? ReadContentFilePath(ZipArchive epub)
|
|
{
|
|
var container = epub.GetEntry("META-INF/container.xml");
|
|
if (container == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
using var containerStream = container.Open();
|
|
|
|
XNamespace containerNamespace = "urn:oasis:names:tc:opendocument:xmlns:container";
|
|
var containerDocument = XDocument.Load(containerStream);
|
|
var element = containerDocument.Descendants(containerNamespace + "rootfile").FirstOrDefault();
|
|
|
|
return element?.Attribute("full-path")?.Value;
|
|
}
|
|
}
|
|
}
|