| | | 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.Database.Implementations.Entities; |
| | | 9 | | using Jellyfin.Extensions; |
| | | 10 | | using MediaBrowser.Controller.Providers; |
| | | 11 | | using Microsoft.Extensions.Logging; |
| | | 12 | | |
| | | 13 | | namespace MediaBrowser.Controller.Entities |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// This is the full Person object that can be retrieved with all of it's data. |
| | | 17 | | /// </summary> |
| | | 18 | | [Common.RequiresSourceSerialisation] |
| | | 19 | | public class Person : BaseItem, IItemByName, IHasLookupInfo<PersonLookupInfo> |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the folder containing the item. |
| | | 23 | | /// If the item is a folder, it returns the folder itself. |
| | | 24 | | /// </summary> |
| | | 25 | | /// <value>The containing folder path.</value> |
| | | 26 | | [JsonIgnore] |
| | 0 | 27 | | public override string ContainingFolderPath => Path; |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets a value indicating whether to enable alpha numeric sorting. |
| | | 31 | | /// </summary> |
| | | 32 | | [JsonIgnore] |
| | 0 | 33 | | public override bool EnableAlphaNumericSorting => false; |
| | | 34 | | |
| | | 35 | | [JsonIgnore] |
| | 0 | 36 | | public override bool SupportsPeople => false; |
| | | 37 | | |
| | | 38 | | [JsonIgnore] |
| | 0 | 39 | | public override bool SupportsAncestors => false; |
| | | 40 | | |
| | | 41 | | public override List<string> GetUserDataKeys() |
| | | 42 | | { |
| | 0 | 43 | | var list = base.GetUserDataKeys(); |
| | | 44 | | |
| | 0 | 45 | | list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics()); |
| | 0 | 46 | | return list; |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | public override string CreatePresentationUniqueKey() |
| | | 50 | | { |
| | 0 | 51 | | return GetUserDataKeys()[0]; |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | public PersonLookupInfo GetLookupInfo() |
| | | 55 | | { |
| | 0 | 56 | | return GetItemLookupInfo<PersonLookupInfo>(); |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | public override double GetDefaultPrimaryImageAspectRatio() |
| | | 60 | | { |
| | 0 | 61 | | double value = 2; |
| | 0 | 62 | | value /= 3; |
| | | 63 | | |
| | 0 | 64 | | return value; |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | public IReadOnlyList<BaseItem> GetTaggedItems(InternalItemsQuery query) |
| | | 68 | | { |
| | 0 | 69 | | query.PersonIds = new[] { Id }; |
| | | 70 | | |
| | 0 | 71 | | return LibraryManager.GetItemList(query); |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | public override bool CanDelete() |
| | | 75 | | { |
| | 0 | 76 | | return false; |
| | | 77 | | } |
| | | 78 | | |
| | | 79 | | /// <inheritdoc /> |
| | | 80 | | /// <remarks> |
| | | 81 | | /// People don't carry the tags of the media they appear in, so the allowed tags check |
| | | 82 | | /// is skipped for them; otherwise no person would be visible to users with allowed tags configured. |
| | | 83 | | /// </remarks> |
| | | 84 | | public override bool IsVisible(User user, bool skipAllowedTagsCheck = false) |
| | | 85 | | { |
| | 0 | 86 | | return base.IsVisible(user, true); |
| | | 87 | | } |
| | | 88 | | |
| | | 89 | | public override bool IsSaveLocalMetadataEnabled() |
| | | 90 | | { |
| | 0 | 91 | | return true; |
| | | 92 | | } |
| | | 93 | | |
| | | 94 | | public static string GetPath(string name) |
| | | 95 | | { |
| | 1 | 96 | | return GetPath(name, true); |
| | | 97 | | } |
| | | 98 | | |
| | | 99 | | public static string GetPath(string name, bool normalizeName) |
| | | 100 | | { |
| | | 101 | | // Trim the period at the end because windows will have a hard time with that |
| | 1 | 102 | | var validFilename = normalizeName ? |
| | 1 | 103 | | FileSystem.GetValidFilename(name).Trim().TrimEnd('.') : |
| | 1 | 104 | | name; |
| | | 105 | | |
| | 1 | 106 | | string subFolderPrefix = null; |
| | | 107 | | |
| | 3 | 108 | | foreach (char c in validFilename) |
| | | 109 | | { |
| | 1 | 110 | | if (char.IsLetterOrDigit(c)) |
| | | 111 | | { |
| | 1 | 112 | | subFolderPrefix = c.ToString(); |
| | 1 | 113 | | break; |
| | | 114 | | } |
| | | 115 | | } |
| | | 116 | | |
| | 1 | 117 | | var path = ConfigurationManager.ApplicationPaths.PeoplePath; |
| | | 118 | | |
| | 1 | 119 | | return string.IsNullOrEmpty(subFolderPrefix) ? |
| | 1 | 120 | | System.IO.Path.Combine(path, validFilename) : |
| | 1 | 121 | | System.IO.Path.Combine(path, subFolderPrefix, validFilename); |
| | | 122 | | } |
| | | 123 | | |
| | | 124 | | private string GetRebasedPath() |
| | | 125 | | { |
| | 0 | 126 | | return GetPath(System.IO.Path.GetFileName(Path), false); |
| | | 127 | | } |
| | | 128 | | |
| | | 129 | | public override bool RequiresRefresh() |
| | | 130 | | { |
| | 0 | 131 | | var newPath = GetRebasedPath(); |
| | 0 | 132 | | if (!string.Equals(Path, newPath, StringComparison.Ordinal)) |
| | | 133 | | { |
| | 0 | 134 | | Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath); |
| | 0 | 135 | | return true; |
| | | 136 | | } |
| | | 137 | | |
| | 0 | 138 | | return base.RequiresRefresh(); |
| | | 139 | | } |
| | | 140 | | |
| | | 141 | | /// <summary> |
| | | 142 | | /// This is called before any metadata refresh and returns true or false indicating if changes were made. |
| | | 143 | | /// </summary> |
| | | 144 | | /// <param name="replaceAllMetadata"><c>true</c> to replace all metadata, <c>false</c> to not.</param> |
| | | 145 | | /// <returns><c>true</c> if changes were made, <c>false</c> if not.</returns> |
| | | 146 | | public override bool BeforeMetadataRefresh(bool replaceAllMetadata) |
| | | 147 | | { |
| | 0 | 148 | | var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata); |
| | | 149 | | |
| | 0 | 150 | | var newPath = GetRebasedPath(); |
| | 0 | 151 | | if (!string.Equals(Path, newPath, StringComparison.Ordinal)) |
| | | 152 | | { |
| | 0 | 153 | | Path = newPath; |
| | 0 | 154 | | hasChanges = true; |
| | | 155 | | } |
| | | 156 | | |
| | 0 | 157 | | return hasChanges; |
| | | 158 | | } |
| | | 159 | | } |
| | | 160 | | } |