< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.Audio.MusicArtist
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs
Line coverage
3%
Covered lines: 2
Uncovered lines: 60
Coverable lines: 62
Total lines: 230
Line coverage: 3.2%
Branch coverage
0%
Covered branches: 0
Total branches: 26
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Linq;
 8using System.Text.Json.Serialization;
 9using System.Threading;
 10using System.Threading.Tasks;
 11using Jellyfin.Data.Entities;
 12using Jellyfin.Data.Enums;
 13using Jellyfin.Extensions;
 14using MediaBrowser.Controller.Providers;
 15using MediaBrowser.Model.Entities;
 16using Microsoft.Extensions.Logging;
 17using MetadataProvider = MediaBrowser.Model.Entities.MetadataProvider;
 18
 19namespace MediaBrowser.Controller.Entities.Audio
 20{
 21    /// <summary>
 22    /// Class MusicArtist.
 23    /// </summary>
 24    public class MusicArtist : Folder, IItemByName, IHasMusicGenres, IHasDualAccess, IHasLookupInfo<ArtistInfo>
 25    {
 26        [JsonIgnore]
 127        public bool IsAccessedByName => ParentId.IsEmpty();
 28
 29        [JsonIgnore]
 130        public override bool IsFolder => !IsAccessedByName;
 31
 32        [JsonIgnore]
 033        public override bool SupportsInheritedParentImages => false;
 34
 35        [JsonIgnore]
 036        public override bool SupportsCumulativeRunTimeTicks => true;
 37
 38        [JsonIgnore]
 039        public override bool IsDisplayedAsFolder => true;
 40
 41        [JsonIgnore]
 042        public override bool SupportsAddingToPlaylist => true;
 43
 44        [JsonIgnore]
 045        public override bool SupportsPlayedStatus => false;
 46
 47        /// <summary>
 48        /// Gets the folder containing the item.
 49        /// If the item is a folder, it returns the folder itself.
 50        /// </summary>
 51        /// <value>The containing folder path.</value>
 52        [JsonIgnore]
 053        public override string ContainingFolderPath => Path;
 54
 55        [JsonIgnore]
 56        public override IEnumerable<BaseItem> Children
 57        {
 58            get
 59            {
 060                if (IsAccessedByName)
 61                {
 062                    return Enumerable.Empty<BaseItem>();
 63                }
 64
 065                return base.Children;
 66            }
 67        }
 68
 69        [JsonIgnore]
 070        public override bool SupportsPeople => false;
 71
 72        public static string GetPath(string name)
 73        {
 074            return GetPath(name, true);
 75        }
 76
 77        public override double GetDefaultPrimaryImageAspectRatio()
 78        {
 079            return 1;
 80        }
 81
 82        public override bool CanDelete()
 83        {
 084            return !IsAccessedByName;
 85        }
 86
 87        public IList<BaseItem> GetTaggedItems(InternalItemsQuery query)
 88        {
 089            if (query.IncludeItemTypes.Length == 0)
 90            {
 091                query.IncludeItemTypes = new[] { BaseItemKind.Audio, BaseItemKind.MusicVideo, BaseItemKind.MusicAlbum };
 092                query.ArtistIds = new[] { Id };
 93            }
 94
 095            return LibraryManager.GetItemList(query);
 96        }
 97
 98        public override int GetChildCount(User user)
 99        {
 0100            return IsAccessedByName ? 0 : base.GetChildCount(user);
 101        }
 102
 103        public override bool IsSaveLocalMetadataEnabled()
 104        {
 0105            if (IsAccessedByName)
 106            {
 0107                return true;
 108            }
 109
 0110            return base.IsSaveLocalMetadataEnabled();
 111        }
 112
 113        protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMe
 114        {
 0115            if (IsAccessedByName)
 116            {
 117                // Should never get in here anyway
 0118                return Task.CompletedTask;
 119            }
 120
 0121            return base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, false, refreshOptions, direc
 122        }
 123
 124        public override List<string> GetUserDataKeys()
 125        {
 0126            var list = base.GetUserDataKeys();
 127
 0128            list.InsertRange(0, GetUserDataKeys(this));
 0129            return list;
 130        }
 131
 132        /// <summary>
 133        /// Gets the user data key.
 134        /// </summary>
 135        /// <param name="item">The item.</param>
 136        /// <returns>System.String.</returns>
 137        private static List<string> GetUserDataKeys(MusicArtist item)
 138        {
 0139            var list = new List<string>();
 0140            var id = item.GetProviderId(MetadataProvider.MusicBrainzArtist);
 141
 0142            if (!string.IsNullOrEmpty(id))
 143            {
 0144                list.Add("Artist-Musicbrainz-" + id);
 145            }
 146
 0147            list.Add("Artist-" + (item.Name ?? string.Empty).RemoveDiacritics());
 0148            return list;
 149        }
 150
 151        public override string CreatePresentationUniqueKey()
 152        {
 0153            return "Artist-" + (Name ?? string.Empty).RemoveDiacritics();
 154        }
 155
 156        protected override bool GetBlockUnratedValue(User user)
 157        {
 0158            return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Music);
 159        }
 160
 161        public override UnratedItem GetBlockUnratedType()
 162        {
 0163            return UnratedItem.Music;
 164        }
 165
 166        public ArtistInfo GetLookupInfo()
 167        {
 0168            var info = GetItemLookupInfo<ArtistInfo>();
 169
 0170            info.SongInfos = GetRecursiveChildren(i => i is Audio)
 0171                .Cast<Audio>()
 0172                .Select(i => i.GetLookupInfo())
 0173                .ToList();
 174
 0175            return info;
 176        }
 177
 178        public static string GetPath(string name, bool normalizeName)
 179        {
 180            // Trim the period at the end because windows will have a hard time with that
 0181            var validName = normalizeName ?
 0182                FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
 0183                name;
 184
 0185            return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.ArtistsPath, validName);
 186        }
 187
 188        private string GetRebasedPath()
 189        {
 0190            return GetPath(System.IO.Path.GetFileName(Path), false);
 191        }
 192
 193        public override bool RequiresRefresh()
 194        {
 0195            if (IsAccessedByName)
 196            {
 0197                var newPath = GetRebasedPath();
 0198                if (!string.Equals(Path, newPath, StringComparison.Ordinal))
 199                {
 0200                    Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
 0201                    return true;
 202                }
 203            }
 204
 0205            return base.RequiresRefresh();
 206        }
 207
 208        /// <summary>
 209        /// This is called before any metadata refresh and returns true or false indicating if changes were made.
 210        /// </summary>
 211        /// <param name="replaceAllMetadata">Option to replace metadata.</param>
 212        /// <returns>True if metadata changed.</returns>
 213        public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
 214        {
 0215            var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
 216
 0217            if (IsAccessedByName)
 218            {
 0219                var newPath = GetRebasedPath();
 0220                if (!string.Equals(Path, newPath, StringComparison.Ordinal))
 221                {
 0222                    Path = newPath;
 0223                    hasChanges = true;
 224                }
 225            }
 226
 0227            return hasChanges;
 228        }
 229    }
 230}