| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | #pragma warning disable CS1591 |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Text.Json.Serialization; |
| | 8 | | using Jellyfin.Extensions; |
| | 9 | | using MediaBrowser.Controller.Providers; |
| | 10 | | using Microsoft.Extensions.Logging; |
| | 11 | |
|
| | 12 | | namespace 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] |
| 0 | 25 | | public override string ContainingFolderPath => Path; |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Gets a value indicating whether to enable alpha numeric sorting. |
| | 29 | | /// </summary> |
| | 30 | | [JsonIgnore] |
| 0 | 31 | | public override bool EnableAlphaNumericSorting => false; |
| | 32 | |
|
| | 33 | | [JsonIgnore] |
| 0 | 34 | | public override bool SupportsPeople => false; |
| | 35 | |
|
| | 36 | | [JsonIgnore] |
| 0 | 37 | | public override bool SupportsAncestors => false; |
| | 38 | |
|
| | 39 | | public override List<string> GetUserDataKeys() |
| | 40 | | { |
| 0 | 41 | | var list = base.GetUserDataKeys(); |
| | 42 | |
|
| 0 | 43 | | list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics()); |
| 0 | 44 | | return list; |
| | 45 | | } |
| | 46 | |
|
| | 47 | | public override string CreatePresentationUniqueKey() |
| | 48 | | { |
| 0 | 49 | | return GetUserDataKeys()[0]; |
| | 50 | | } |
| | 51 | |
|
| | 52 | | public PersonLookupInfo GetLookupInfo() |
| | 53 | | { |
| 0 | 54 | | return GetItemLookupInfo<PersonLookupInfo>(); |
| | 55 | | } |
| | 56 | |
|
| | 57 | | public override double GetDefaultPrimaryImageAspectRatio() |
| | 58 | | { |
| 0 | 59 | | double value = 2; |
| 0 | 60 | | value /= 3; |
| | 61 | |
|
| 0 | 62 | | return value; |
| | 63 | | } |
| | 64 | |
|
| | 65 | | public IList<BaseItem> GetTaggedItems(InternalItemsQuery query) |
| | 66 | | { |
| 0 | 67 | | query.PersonIds = new[] { Id }; |
| | 68 | |
|
| 0 | 69 | | return LibraryManager.GetItemList(query); |
| | 70 | | } |
| | 71 | |
|
| | 72 | | public override bool CanDelete() |
| | 73 | | { |
| 0 | 74 | | return false; |
| | 75 | | } |
| | 76 | |
|
| | 77 | | public override bool IsSaveLocalMetadataEnabled() |
| | 78 | | { |
| 0 | 79 | | return true; |
| | 80 | | } |
| | 81 | |
|
| | 82 | | public static string GetPath(string name) |
| | 83 | | { |
| 1 | 84 | | 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 |
| 1 | 90 | | var validFilename = normalizeName ? |
| 1 | 91 | | FileSystem.GetValidFilename(name).Trim().TrimEnd('.') : |
| 1 | 92 | | name; |
| | 93 | |
|
| 1 | 94 | | string subFolderPrefix = null; |
| | 95 | |
|
| 3 | 96 | | foreach (char c in validFilename) |
| | 97 | | { |
| 1 | 98 | | if (char.IsLetterOrDigit(c)) |
| | 99 | | { |
| 1 | 100 | | subFolderPrefix = c.ToString(); |
| 1 | 101 | | break; |
| | 102 | | } |
| | 103 | | } |
| | 104 | |
|
| 1 | 105 | | var path = ConfigurationManager.ApplicationPaths.PeoplePath; |
| | 106 | |
|
| 1 | 107 | | return string.IsNullOrEmpty(subFolderPrefix) ? |
| 1 | 108 | | System.IO.Path.Combine(path, validFilename) : |
| 1 | 109 | | System.IO.Path.Combine(path, subFolderPrefix, validFilename); |
| | 110 | | } |
| | 111 | |
|
| | 112 | | private string GetRebasedPath() |
| | 113 | | { |
| 0 | 114 | | return GetPath(System.IO.Path.GetFileName(Path), false); |
| | 115 | | } |
| | 116 | |
|
| | 117 | | public override bool RequiresRefresh() |
| | 118 | | { |
| 0 | 119 | | var newPath = GetRebasedPath(); |
| 0 | 120 | | if (!string.Equals(Path, newPath, StringComparison.Ordinal)) |
| | 121 | | { |
| 0 | 122 | | Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath); |
| 0 | 123 | | return true; |
| | 124 | | } |
| | 125 | |
|
| 0 | 126 | | 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 | | { |
| 0 | 136 | | var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata); |
| | 137 | |
|
| 0 | 138 | | var newPath = GetRebasedPath(); |
| 0 | 139 | | if (!string.Equals(Path, newPath, StringComparison.Ordinal)) |
| | 140 | | { |
| 0 | 141 | | Path = newPath; |
| 0 | 142 | | hasChanges = true; |
| | 143 | | } |
| | 144 | |
|
| 0 | 145 | | return hasChanges; |
| | 146 | | } |
| | 147 | | } |
| | 148 | | } |