< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Library.Resolvers.Books.BookResolver
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs
Line coverage
14%
Covered lines: 4
Uncovered lines: 24
Coverable lines: 28
Total lines: 74
Line coverage: 14.2%
Branch coverage
12%
Covered branches: 1
Total branches: 8
Branch coverage: 12.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
Resolve(...)16.66%22.39623.07%
GetBook(...)0%620%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.IO;
 7using System.Linq;
 8using Jellyfin.Data.Enums;
 9using Jellyfin.Extensions;
 10using MediaBrowser.Controller.Entities;
 11using MediaBrowser.Controller.Library;
 12using MediaBrowser.Controller.Resolvers;
 13using MediaBrowser.Model.Entities;
 14
 15namespace Emby.Server.Implementations.Library.Resolvers.Books
 16{
 17    public class BookResolver : ItemResolver<Book>
 18    {
 2219        private readonly string[] _validExtensions = { ".azw", ".azw3", ".cb7", ".cbr", ".cbt", ".cbz", ".epub", ".mobi"
 20
 21        protected override Book Resolve(ItemResolveArgs args)
 22        {
 323            var collectionType = args.GetCollectionType();
 24
 25            // Only process items that are in a collection folder containing books
 326            if (collectionType != CollectionType.books)
 27            {
 328                return null;
 29            }
 30
 031            if (args.IsDirectory)
 32            {
 033                return GetBook(args);
 34            }
 35
 036            var extension = Path.GetExtension(args.Path.AsSpan());
 37
 038            if (_validExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase))
 39            {
 40                // It's a book
 041                return new Book
 042                {
 043                    Path = args.Path,
 044                    IsInMixedFolder = true
 045                };
 46            }
 47
 048            return null;
 49        }
 50
 51        private Book GetBook(ItemResolveArgs args)
 52        {
 053            var bookFiles = args.FileSystemChildren.Where(f =>
 054            {
 055                var fileExtension = Path.GetExtension(f.FullName.AsSpan());
 056
 057                return _validExtensions.Contains(
 058                    fileExtension,
 059                    StringComparison.OrdinalIgnoreCase);
 060            }).ToList();
 61
 62            // Don't return a Book if there is more (or less) than one document in the directory
 063            if (bookFiles.Count != 1)
 64            {
 065                return null;
 66            }
 67
 068            return new Book
 069            {
 070                Path = bookFiles[0].FullName
 071            };
 72        }
 73    }
 74}