< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Library.Resolvers.Audio.MusicArtistResolver
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs
Line coverage
22%
Covered lines: 11
Uncovered lines: 39
Coverable lines: 50
Total lines: 122
Line coverage: 22%
Branch coverage
7%
Covered branches: 1
Total branches: 14
Branch coverage: 7.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(...)7.14%182.74144.87%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs

#LineLine coverage
 1#nullable disable
 2
 3using System;
 4using System.Linq;
 5using System.Threading.Tasks;
 6using Emby.Naming.Audio;
 7using Emby.Naming.Common;
 8using Jellyfin.Data.Enums;
 9using MediaBrowser.Controller.Entities.Audio;
 10using MediaBrowser.Controller.Library;
 11using MediaBrowser.Controller.Providers;
 12using MediaBrowser.Controller.Resolvers;
 13using MediaBrowser.Model.Entities;
 14using Microsoft.Extensions.Logging;
 15
 16namespace Emby.Server.Implementations.Library.Resolvers.Audio
 17{
 18    /// <summary>
 19    /// The music artist resolver.
 20    /// </summary>
 21    public class MusicArtistResolver : ItemResolver<MusicArtist>
 22    {
 23        private readonly ILogger<MusicAlbumResolver> _logger;
 24        private readonly NamingOptions _namingOptions;
 25        private readonly IDirectoryService _directoryService;
 26
 27        /// <summary>
 28        /// Initializes a new instance of the <see cref="MusicArtistResolver"/> class.
 29        /// </summary>
 30        /// <param name="logger">Instance of the <see cref="MusicAlbumResolver"/> interface.</param>
 31        /// <param name="namingOptions">The <see cref="NamingOptions"/>.</param>
 32        /// <param name="directoryService">The directory service.</param>
 2233        public MusicArtistResolver(
 2234            ILogger<MusicAlbumResolver> logger,
 2235            NamingOptions namingOptions,
 2236            IDirectoryService directoryService)
 37        {
 2238            _logger = logger;
 2239            _namingOptions = namingOptions;
 2240            _directoryService = directoryService;
 2241        }
 42
 43        /// <summary>
 44        /// Gets the priority.
 45        /// </summary>
 46        /// <value>The priority.</value>
 2247        public override ResolverPriority Priority => ResolverPriority.Second;
 48
 49        /// <summary>
 50        /// Resolves the specified resolver arguments.
 51        /// </summary>
 52        /// <param name="args">The resolver arguments.</param>
 53        /// <returns>A <see cref="MusicArtist"/>.</returns>
 54        protected override MusicArtist Resolve(ItemResolveArgs args)
 55        {
 356            if (!args.IsDirectory)
 57            {
 358                return null;
 59            }
 60
 61            // Don't allow nested artists
 062            if (args.HasParent<MusicArtist>() || args.HasParent<MusicAlbum>())
 63            {
 064                return null;
 65            }
 66
 067            var collectionType = args.GetCollectionType();
 68
 069            var isMusicMediaFolder = collectionType == CollectionType.music;
 70
 71            // If there's a collection type and it's not music, it can't be a music artist
 072            if (!isMusicMediaFolder)
 73            {
 074                return null;
 75            }
 76
 077            if (args.ContainsFileSystemEntryByName("artist.nfo"))
 78            {
 079                return new MusicArtist();
 80            }
 81
 82            // Avoid mis-identifying top folders
 083            if (args.Parent.IsRoot)
 84            {
 085                return null;
 86            }
 87
 088            var albumResolver = new MusicAlbumResolver(_logger, _namingOptions, _directoryService);
 089            var albumParser = new AlbumParser(_namingOptions);
 90
 091            var directories = args.FileSystemChildren.Where(i => i.IsDirectory);
 92
 093            var result = Parallel.ForEach(directories, (fileSystemInfo, state) =>
 094            {
 095                // If we contain a artist subfolder assume we are an artist folder
 096                foreach (var subfolder in _namingOptions.ArtistSubfolders)
 097                {
 098                    if (fileSystemInfo.Name.Equals(subfolder, StringComparison.OrdinalIgnoreCase))
 099                    {
 0100                        // Stop once we see an artist subfolder
 0101                        state.Stop();
 0102                    }
 0103                }
 0104
 0105                // If the folder is a multi-disc folder, then it is not an artist folder
 0106                if (albumParser.IsMultiPart(fileSystemInfo.FullName))
 0107                {
 0108                    return;
 0109                }
 0110
 0111                // If we contain a music album assume we are an artist folder
 0112                if (albumResolver.IsMusicAlbum(fileSystemInfo.FullName, _directoryService))
 0113                {
 0114                    // Stop once we see a music album
 0115                    state.Stop();
 0116                }
 0117            });
 118
 0119            return !result.IsCompleted ? new MusicArtist() : null;
 120        }
 121    }
 122}