< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.Books.OpenPackagingFormat.EpubProvider
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/Books/OpenPackagingFormat/EpubProvider.cs
Line coverage
10%
Covered lines: 3
Uncovered lines: 27
Coverable lines: 30
Total lines: 100
Line coverage: 10%
Branch coverage
0%
Covered branches: 0
Total branches: 14
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 1/29/2026 - 12:13:32 AM Line coverage: 10% (3/30) Branch coverage: 0% (0/14) Total lines: 100 1/29/2026 - 12:13:32 AM Line coverage: 10% (3/30) Branch coverage: 0% (0/14) Total lines: 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%210%
GetMetadata(...)0%4260%
GetEpubFile(...)0%2040%
ReadEpubAsZip(...)0%2040%

File(s)

/srv/git/jellyfin/MediaBrowser.Providers/Books/OpenPackagingFormat/EpubProvider.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.IO.Compression;
 4using System.Threading;
 5using System.Threading.Tasks;
 6using System.Xml;
 7using MediaBrowser.Controller.Entities;
 8using MediaBrowser.Controller.Providers;
 9using MediaBrowser.Model.IO;
 10using Microsoft.Extensions.Logging;
 11
 12namespace MediaBrowser.Providers.Books.OpenPackagingFormat
 13{
 14    /// <summary>
 15    /// Provides book metadata from OPF content in an EPUB item.
 16    /// </summary>
 17    public class EpubProvider : ILocalMetadataProvider<Book>
 18    {
 19        private readonly IFileSystem _fileSystem;
 20        private readonly ILogger<EpubProvider> _logger;
 21
 22        /// <summary>
 23        /// Initializes a new instance of the <see cref="EpubProvider"/> class.
 24        /// </summary>
 25        /// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
 26        /// <param name="logger">Instance of the <see cref="ILogger{EpubProvider}"/> interface.</param>
 27        public EpubProvider(IFileSystem fileSystem, ILogger<EpubProvider> logger)
 28        {
 2129            _fileSystem = fileSystem;
 2130            _logger = logger;
 2131        }
 32
 33        /// <inheritdoc />
 034        public string Name => "EPUB Metadata";
 35
 36        /// <inheritdoc />
 37        public Task<MetadataResult<Book>> GetMetadata(ItemInfo info, IDirectoryService directoryService, CancellationTok
 38        {
 039            var path = GetEpubFile(info.Path)?.FullName;
 40
 041            if (path is null)
 42            {
 043                return Task.FromResult(new MetadataResult<Book> { HasMetadata = false });
 44            }
 45
 046            var result = ReadEpubAsZip(path, cancellationToken);
 47
 048            if (result is null)
 49            {
 050                return Task.FromResult(new MetadataResult<Book> { HasMetadata = false });
 51            }
 52            else
 53            {
 054                return Task.FromResult(result);
 55            }
 56        }
 57
 58        private FileSystemMetadata? GetEpubFile(string path)
 59        {
 060            var fileInfo = _fileSystem.GetFileSystemInfo(path);
 61
 062            if (fileInfo.IsDirectory)
 63            {
 064                return null;
 65            }
 66
 067            if (!string.Equals(Path.GetExtension(fileInfo.FullName), ".epub", StringComparison.OrdinalIgnoreCase))
 68            {
 069                return null;
 70            }
 71
 072            return fileInfo;
 73        }
 74
 75        private MetadataResult<Book>? ReadEpubAsZip(string path, CancellationToken cancellationToken)
 76        {
 077            using var epub = ZipFile.OpenRead(path);
 78
 079            var opfFilePath = EpubUtils.ReadContentFilePath(epub);
 080            if (opfFilePath == null)
 81            {
 082                return null;
 83            }
 84
 085            var opf = epub.GetEntry(opfFilePath);
 086            if (opf == null)
 87            {
 088                return null;
 89            }
 90
 091            using var opfStream = opf.Open();
 92
 093            var opfDocument = new XmlDocument();
 094            opfDocument.Load(opfStream);
 95
 096            var utilities = new OpfReader<EpubProvider>(opfDocument, _logger);
 097            return utilities.ReadOpfData(cancellationToken);
 098        }
 99    }
 100}