< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Library.Resolvers.SpecialFolderResolver
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Library/Resolvers/SpecialFolderResolver.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 86
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

0255075100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Priority()100%11100%
Resolve(...)100%88100%
GetCollectionType(...)100%11100%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Library/Resolvers/SpecialFolderResolver.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 MediaBrowser.Controller;
 10using MediaBrowser.Controller.Entities;
 11using MediaBrowser.Controller.Library;
 12using MediaBrowser.Controller.Resolvers;
 13using MediaBrowser.Model.IO;
 14
 15namespace Emby.Server.Implementations.Library.Resolvers
 16{
 17    public class SpecialFolderResolver : GenericFolderResolver<Folder>
 18    {
 19        private readonly IFileSystem _fileSystem;
 20        private readonly IServerApplicationPaths _appPaths;
 21
 2122        public SpecialFolderResolver(IFileSystem fileSystem, IServerApplicationPaths appPaths)
 23        {
 2124            _fileSystem = fileSystem;
 2125            _appPaths = appPaths;
 2126        }
 27
 28        /// <summary>
 29        /// Gets the priority.
 30        /// </summary>
 31        /// <value>The priority.</value>
 2132        public override ResolverPriority Priority => ResolverPriority.First;
 33
 34        /// <summary>
 35        /// Resolves the specified args.
 36        /// </summary>
 37        /// <param name="args">The args.</param>
 38        /// <returns>Folder.</returns>
 39        protected override Folder Resolve(ItemResolveArgs args)
 40        {
 5441            if (args.IsDirectory)
 42            {
 4743                if (args.IsPhysicalRoot)
 44                {
 2145                    return new AggregateFolder();
 46                }
 47
 2648                if (string.Equals(args.Path, _appPaths.DefaultUserViewsPath, StringComparison.OrdinalIgnoreCase))
 49                {
 2150                    return new UserRootFolder();  // if we got here and still a root - must be user root
 51                }
 52
 553                if (args.IsVf)
 54                {
 555                    return new CollectionFolder
 556                    {
 557                        CollectionType = GetCollectionType(args),
 558                        PhysicalLocationsList = args.PhysicalLocations
 559                    };
 60                }
 61            }
 62
 763            return null;
 64        }
 65
 66        private CollectionType? GetCollectionType(ItemResolveArgs args)
 67        {
 568            return args.FileSystemChildren
 569                .Where(i =>
 570                {
 571                    try
 572                    {
 573                        return !i.IsDirectory &&
 574                               string.Equals(".collection", i.Extension, StringComparison.OrdinalIgnoreCase);
 575                    }
 576                    catch (IOException)
 577                    {
 578                        return false;
 579                    }
 580                })
 581                .Select(i => _fileSystem.GetFileNameWithoutExtension(i))
 582                .Select(i => Enum.TryParse<CollectionType>(i, out var collectionType) ? collectionType : (CollectionType
 583                .FirstOrDefault(i => i is not null);
 84        }
 85    }
 86}