blob: e5d2987312a14da0ea988cbf4b8e23d25061e060 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
using System.IO;
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(Path.Combine("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;
}
}
}
|