jellyfin/MediaBrowser.Controller/Entities/Person.cs

230 lines
6.4 KiB
C#
Raw Normal View History

2015-02-18 21:37:44 -07:00
using MediaBrowser.Controller.Providers;
using System;
using System.Collections.Generic;
2016-06-17 06:06:13 -07:00
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Extensions;
2016-01-21 11:50:43 -07:00
using MediaBrowser.Model.Entities;
2016-10-23 12:47:34 -07:00
using MediaBrowser.Model.Extensions;
2016-10-25 12:02:04 -07:00
using MediaBrowser.Model.Serialization;
2013-02-20 18:33:05 -07:00
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// This is the full Person object that can be retrieved with all of it's data.
/// </summary>
public class Person : BaseItem, IItemByName, IHasLookupInfo<PersonLookupInfo>
2013-02-20 18:33:05 -07:00
{
2016-04-30 16:05:21 -07:00
public override List<string> GetUserDataKeys()
{
2016-04-30 16:05:21 -07:00
var list = base.GetUserDataKeys();
2016-06-17 06:06:13 -07:00
list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics());
2016-04-30 16:05:21 -07:00
return list;
}
public override string CreatePresentationUniqueKey()
2016-06-17 06:06:13 -07:00
{
return GetUserDataKeys()[0];
2016-06-17 06:06:13 -07:00
}
public PersonLookupInfo GetLookupInfo()
2014-02-06 20:10:13 -07:00
{
return GetItemLookupInfo<PersonLookupInfo>();
}
2017-02-10 13:06:52 -07:00
public override double? GetDefaultPrimaryImageAspectRatio()
{
double value = 2;
value /= 3;
return value;
}
2016-05-07 10:47:41 -07:00
public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
{
2016-11-20 13:20:01 -07:00
query.PersonIds = new[] { Id.ToString("N") };
2016-05-07 10:47:41 -07:00
return LibraryManager.GetItemList(query);
}
/// <summary>
/// Returns the folder containing the item.
/// If the item is a folder, it returns the folder itself
/// </summary>
/// <value>The containing folder path.</value>
2015-01-26 15:47:16 -07:00
[IgnoreDataMember]
public override string ContainingFolderPath
{
get
{
return Path;
}
}
2015-02-05 22:39:07 -07:00
public override bool CanDelete()
{
return false;
}
2015-02-18 21:37:44 -07:00
public override bool IsSaveLocalMetadataEnabled()
{
return true;
}
2015-07-14 12:04:16 -07:00
[IgnoreDataMember]
public override bool EnableAlphaNumericSorting
{
get
{
return false;
}
}
/// <summary>
/// Gets a value indicating whether this instance is owned item.
/// </summary>
/// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
2015-01-26 15:47:16 -07:00
[IgnoreDataMember]
public override bool IsOwnedItem
{
get
{
return false;
}
2014-02-06 20:10:13 -07:00
}
2015-06-28 18:10:45 -07:00
[IgnoreDataMember]
public override bool SupportsPeople
{
get
{
return false;
}
}
2015-10-29 06:28:05 -07:00
[IgnoreDataMember]
public override bool SupportsAncestors
{
get
{
return false;
}
}
2016-08-17 22:56:10 -07:00
2017-03-12 21:08:23 -07:00
public static string GetPath(string name)
{
return GetPath(name, true);
}
public static string GetPath(string name, bool normalizeName)
2016-08-17 22:56:10 -07:00
{
// Trim the period at the end because windows will have a hard time with that
var validFilename = normalizeName ?
FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
name;
string subFolderPrefix = null;
foreach (char c in validFilename)
{
if (char.IsLetterOrDigit(c))
{
subFolderPrefix = c.ToString();
break;
}
}
var path = ConfigurationManager.ApplicationPaths.PeoplePath;
return string.IsNullOrEmpty(subFolderPrefix) ?
System.IO.Path.Combine(path, validFilename) :
System.IO.Path.Combine(path, subFolderPrefix, validFilename);
}
private string GetRebasedPath()
{
return GetPath(System.IO.Path.GetFileName(Path), false);
}
public override bool RequiresRefresh()
{
var newPath = GetRebasedPath();
if (!string.Equals(Path, newPath, StringComparison.Ordinal))
{
Logger.Debug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
return true;
}
return base.RequiresRefresh();
}
/// <summary>
/// This is called before any metadata refresh and returns true or false indicating if changes were made
/// </summary>
public override bool BeforeMetadataRefresh()
{
var hasChanges = base.BeforeMetadataRefresh();
var newPath = GetRebasedPath();
if (!string.Equals(Path, newPath, StringComparison.Ordinal))
{
Path = newPath;
hasChanges = true;
}
return hasChanges;
}
2013-02-20 18:33:05 -07:00
}
/// <summary>
/// This is the small Person stub that is attached to BaseItems
/// </summary>
2016-01-21 11:50:43 -07:00
public class PersonInfo : IHasProviderIds
2013-02-20 18:33:05 -07:00
{
2016-01-21 11:50:43 -07:00
public PersonInfo()
{
ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
2015-07-08 09:10:34 -07:00
public Guid ItemId { get; set; }
2013-02-20 18:33:05 -07:00
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the role.
/// </summary>
/// <value>The role.</value>
public string Role { get; set; }
/// <summary>
/// Gets or sets the type.
/// </summary>
/// <value>The type.</value>
public string Type { get; set; }
/// <summary>
/// Gets or sets the sort order - ascending
/// </summary>
/// <value>The sort order.</value>
public int? SortOrder { get; set; }
2016-01-21 11:50:43 -07:00
public string ImageUrl { get; set; }
public Dictionary<string, string> ProviderIds { get; set; }
2013-02-20 18:33:05 -07:00
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
public override string ToString()
{
return Name;
}
2014-06-30 06:28:38 -07:00
public bool IsType(string type)
{
return string.Equals(Type, type, StringComparison.OrdinalIgnoreCase) || string.Equals(Role, type, StringComparison.OrdinalIgnoreCase);
}
2013-02-20 18:33:05 -07:00
}
}