< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Library.Resolvers.PhotoAlbumResolver
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Library/Resolvers/PhotoAlbumResolver.cs
Line coverage
25%
Covered lines: 7
Uncovered lines: 20
Coverable lines: 27
Total lines: 95
Line coverage: 25.9%
Branch coverage
18%
Covered branches: 4
Total branches: 22
Branch coverage: 18.1%
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%
get_Priority()100%11100%
Resolve(...)40%61.21020%
HasPhotos(...)0%156120%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Library/Resolvers/PhotoAlbumResolver.cs

#LineLine coverage
 1#nullable disable
 2
 3using System;
 4using Emby.Naming.Common;
 5using Jellyfin.Data.Enums;
 6using MediaBrowser.Controller.Drawing;
 7using MediaBrowser.Controller.Entities;
 8using MediaBrowser.Controller.Library;
 9using MediaBrowser.Controller.Resolvers;
 10using MediaBrowser.Model.Entities;
 11
 12namespace Emby.Server.Implementations.Library.Resolvers
 13{
 14    /// <summary>
 15    /// Class PhotoAlbumResolver.
 16    /// </summary>
 17    public class PhotoAlbumResolver : GenericFolderResolver<PhotoAlbum>
 18    {
 19        private readonly IImageProcessor _imageProcessor;
 20        private readonly NamingOptions _namingOptions;
 21
 22        /// <summary>
 23        /// Initializes a new instance of the <see cref="PhotoAlbumResolver"/> class.
 24        /// </summary>
 25        /// <param name="imageProcessor">The image processor.</param>
 26        /// <param name="namingOptions">The naming options.</param>
 2227        public PhotoAlbumResolver(IImageProcessor imageProcessor, NamingOptions namingOptions)
 28        {
 2229            _imageProcessor = imageProcessor;
 2230            _namingOptions = namingOptions;
 2231        }
 32
 33        /// <inheritdoc />
 2234        public override ResolverPriority Priority => ResolverPriority.Second;
 35
 36        /// <summary>
 37        /// Resolves the specified args.
 38        /// </summary>
 39        /// <param name="args">The args.</param>
 40        /// <returns>Trailer.</returns>
 41        protected override PhotoAlbum Resolve(ItemResolveArgs args)
 42        {
 43            // Must be an image file within a photo collection
 344            if (args.IsDirectory)
 45            {
 46                // Must be an image file within a photo collection
 047                var collectionType = args.GetCollectionType();
 48
 049                if (collectionType == CollectionType.photos
 050                    || (collectionType == CollectionType.homevideos && args.LibraryOptions.EnablePhotos))
 51                {
 052                    if (HasPhotos(args))
 53                    {
 054                        return new PhotoAlbum
 055                        {
 056                            Path = args.Path
 057                        };
 58                    }
 59                }
 60            }
 61
 362            return null;
 63        }
 64
 65        private bool HasPhotos(ItemResolveArgs args)
 66        {
 067            var files = args.FileSystemChildren;
 68
 069            foreach (var file in files)
 70            {
 071                if (!file.IsDirectory && PhotoResolver.IsImageFile(file.FullName, _imageProcessor))
 72                {
 073                    var filename = file.Name;
 074                    var ownedByMedia = false;
 75
 076                    foreach (var siblingFile in files)
 77                    {
 078                        if (PhotoResolver.IsOwnedByMedia(_namingOptions, siblingFile.FullName, filename))
 79                        {
 080                            ownedByMedia = true;
 081                            break;
 82                        }
 83                    }
 84
 085                    if (!ownedByMedia)
 86                    {
 087                        return true;
 88                    }
 89                }
 90            }
 91
 092            return false;
 93        }
 94    }
 95}