From f89279fc4bd33d47623284ad337d3bc5aa6dd282 Mon Sep 17 00:00:00 2001 From: chino Date: Mon, 5 Oct 2026 19:19:09 -0400 Subject: Backport pull request #18283 from jellyfin/release-12.z Fix EPUB metadata and covers not loading on Windows Original-merge: 56989b0c8057275b38805ab977e1f1fa7c6d3e95 Merged-by: crobibero Backported-by: Cody Robibero --- CONTRIBUTORS.md | 1 + .../Books/OpenPackagingFormat/EpubImageProvider.cs | 3 +- .../Books/OpenPackagingFormat/EpubUtils.cs | 3 +- .../Books/EpubUtilsTests.cs | 34 ++++++++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 tests/Jellyfin.Providers.Tests/Books/EpubUtilsTests.cs diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8240b458e6..31cef1437e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -246,6 +246,7 @@ - [Mateus Bandeira](https://github.com/mateusbandeiraa) - [excelsior](https://github.com/excelsior-dev) - [TheDreadPirate](https://github.com/thedreaddpirate) + - [Daniel Aquino](https://github.com/chino) - [klizas](https://github.com/klizas) # Emby Contributors diff --git a/MediaBrowser.Providers/Books/OpenPackagingFormat/EpubImageProvider.cs b/MediaBrowser.Providers/Books/OpenPackagingFormat/EpubImageProvider.cs index 69cae77628..dbd8b28198 100644 --- a/MediaBrowser.Providers/Books/OpenPackagingFormat/EpubImageProvider.cs +++ b/MediaBrowser.Providers/Books/OpenPackagingFormat/EpubImageProvider.cs @@ -64,7 +64,8 @@ namespace MediaBrowser.Providers.Books.OpenPackagingFormat } var cover = coverReference.Value; - var coverFile = epub.GetEntry(cover.Path); + // ZIP entry names always use '/', but the cover path is built with Path.Combine, which uses '\' on Windows + var coverFile = epub.GetEntry(cover.Path.Replace('\\', '/')); if (coverFile == null) { diff --git a/MediaBrowser.Providers/Books/OpenPackagingFormat/EpubUtils.cs b/MediaBrowser.Providers/Books/OpenPackagingFormat/EpubUtils.cs index e5d2987312..d60b50701e 100644 --- a/MediaBrowser.Providers/Books/OpenPackagingFormat/EpubUtils.cs +++ b/MediaBrowser.Providers/Books/OpenPackagingFormat/EpubUtils.cs @@ -1,4 +1,3 @@ -using System.IO; using System.IO.Compression; using System.Linq; using System.Xml.Linq; @@ -17,7 +16,7 @@ namespace MediaBrowser.Providers.Books.OpenPackagingFormat /// The content file path. public static string? ReadContentFilePath(ZipArchive epub) { - var container = epub.GetEntry(Path.Combine("META-INF", "container.xml")); + var container = epub.GetEntry("META-INF/container.xml"); if (container == null) { return null; diff --git a/tests/Jellyfin.Providers.Tests/Books/EpubUtilsTests.cs b/tests/Jellyfin.Providers.Tests/Books/EpubUtilsTests.cs new file mode 100644 index 0000000000..a5a3af6210 --- /dev/null +++ b/tests/Jellyfin.Providers.Tests/Books/EpubUtilsTests.cs @@ -0,0 +1,34 @@ +using System.IO; +using System.IO.Compression; +using System.Text; +using MediaBrowser.Providers.Books.OpenPackagingFormat; +using Xunit; + +namespace Jellyfin.Providers.Tests.Books; + +public class EpubUtilsTests +{ + [Fact] + public void ReadContentFilePath_ReadsRootFileFromContainer() + { + using var stream = new MemoryStream(); + using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true)) + { + using var writer = new StreamWriter(archive.CreateEntry("META-INF/container.xml").Open(), Encoding.UTF8); + writer.Write( + """ + + + + + + + """); + } + + stream.Position = 0; + using var epub = new ZipArchive(stream, ZipArchiveMode.Read); + + Assert.Equal("OEBPS/content.opf", EpubUtils.ReadContentFilePath(epub)); + } +} -- cgit v1.2.3