< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.Person
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/Person.cs
Line coverage
31%
Covered lines: 13
Uncovered lines: 28
Coverable lines: 41
Total lines: 148
Line coverage: 31.7%
Branch coverage
35%
Covered branches: 5
Total branches: 14
Branch coverage: 35.7%
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/Person.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Text.Json.Serialization;
 8using Jellyfin.Extensions;
 9using MediaBrowser.Controller.Providers;
 10using Microsoft.Extensions.Logging;
 11
 12namespace MediaBrowser.Controller.Entities
 13{
 14    /// <summary>
 15    /// This is the full Person object that can be retrieved with all of it's data.
 16    /// </summary>
 17    public class Person : BaseItem, IItemByName, IHasLookupInfo<PersonLookupInfo>
 18    {
 19        /// <summary>
 20        /// Gets the folder containing the item.
 21        /// If the item is a folder, it returns the folder itself.
 22        /// </summary>
 23        /// <value>The containing folder path.</value>
 24        [JsonIgnore]
 025        public override string ContainingFolderPath => Path;
 26
 27        /// <summary>
 28        /// Gets a value indicating whether to enable alpha numeric sorting.
 29        /// </summary>
 30        [JsonIgnore]
 031        public override bool EnableAlphaNumericSorting => false;
 32
 33        [JsonIgnore]
 034        public override bool SupportsPeople => false;
 35
 36        [JsonIgnore]
 037        public override bool SupportsAncestors => false;
 38
 39        public override List<string> GetUserDataKeys()
 40        {
 041            var list = base.GetUserDataKeys();
 42
 043            list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics());
 044            return list;
 45        }
 46
 47        public override string CreatePresentationUniqueKey()
 48        {
 049            return GetUserDataKeys()[0];
 50        }
 51
 52        public PersonLookupInfo GetLookupInfo()
 53        {
 054            return GetItemLookupInfo<PersonLookupInfo>();
 55        }
 56
 57        public override double GetDefaultPrimaryImageAspectRatio()
 58        {
 059            double value = 2;
 060            value /= 3;
 61
 062            return value;
 63        }
 64
 65        public IList<BaseItem> GetTaggedItems(InternalItemsQuery query)
 66        {
 067            query.PersonIds = new[] { Id };
 68
 069            return LibraryManager.GetItemList(query);
 70        }
 71
 72        public override bool CanDelete()
 73        {
 074            return false;
 75        }
 76
 77        public override bool IsSaveLocalMetadataEnabled()
 78        {
 079            return true;
 80        }
 81
 82        public static string GetPath(string name)
 83        {
 184            return GetPath(name, true);
 85        }
 86
 87        public static string GetPath(string name, bool normalizeName)
 88        {
 89            // Trim the period at the end because windows will have a hard time with that
 190            var validFilename = normalizeName ?
 191                FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
 192                name;
 93
 194            string subFolderPrefix = null;
 95
 396            foreach (char c in validFilename)
 97            {
 198                if (char.IsLetterOrDigit(c))
 99                {
 1100                    subFolderPrefix = c.ToString();
 1101                    break;
 102                }
 103            }
 104
 1105            var path = ConfigurationManager.ApplicationPaths.PeoplePath;
 106
 1107            return string.IsNullOrEmpty(subFolderPrefix) ?
 1108                System.IO.Path.Combine(path, validFilename) :
 1109                System.IO.Path.Combine(path, subFolderPrefix, validFilename);
 110        }
 111
 112        private string GetRebasedPath()
 113        {
 0114            return GetPath(System.IO.Path.GetFileName(Path), false);
 115        }
 116
 117        public override bool RequiresRefresh()
 118        {
 0119            var newPath = GetRebasedPath();
 0120            if (!string.Equals(Path, newPath, StringComparison.Ordinal))
 121            {
 0122                Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
 0123                return true;
 124            }
 125
 0126            return base.RequiresRefresh();
 127        }
 128
 129        /// <summary>
 130        /// This is called before any metadata refresh and returns true or false indicating if changes were made.
 131        /// </summary>
 132        /// <param name="replaceAllMetadata"><c>true</c> to replace all metadata, <c>false</c> to not.</param>
 133        /// <returns><c>true</c> if changes were made, <c>false</c> if not.</returns>
 134        public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
 135        {
 0136            var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
 137
 0138            var newPath = GetRebasedPath();
 0139            if (!string.Equals(Path, newPath, StringComparison.Ordinal))
 140            {
 0141                Path = newPath;
 0142                hasChanges = true;
 143            }
 144
 0145            return hasChanges;
 146        }
 147    }
 148}