jellyfin/MediaBrowser.Controller/Entities/Person.cs

253 lines
7.2 KiB
C#
Raw Normal View History

2015-02-19 05:37:44 +01:00
using MediaBrowser.Controller.Providers;
using System;
using System.Collections.Generic;
using System.Linq;
2016-06-17 15:06:13 +02:00
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Extensions;
2016-01-21 19:50:43 +01:00
using MediaBrowser.Model.Entities;
2016-10-23 21:47:34 +02:00
using MediaBrowser.Model.Extensions;
2016-10-25 21:02:04 +02:00
using MediaBrowser.Model.Serialization;
2013-02-21 02:33:05 +01: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-21 02:33:05 +01:00
{
/// <summary>
/// Gets or sets the place of birth.
/// </summary>
/// <value>The place of birth.</value>
public string PlaceOfBirth { get; set; }
2015-01-26 23:47:16 +01:00
2016-05-01 01:05:21 +02:00
public override List<string> GetUserDataKeys()
{
2016-05-01 01:05:21 +02:00
var list = base.GetUserDataKeys();
2016-06-17 15:06:13 +02:00
list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics());
2016-05-01 01:05:21 +02:00
return list;
}
public override string CreatePresentationUniqueKey()
2016-06-17 15:06:13 +02:00
{
return GetUserDataKeys()[0];
2016-06-17 15:06:13 +02:00
}
public PersonLookupInfo GetLookupInfo()
2014-02-07 04:10:13 +01:00
{
return GetItemLookupInfo<PersonLookupInfo>();
}
2017-02-10 21:06:52 +01:00
public override double? GetDefaultPrimaryImageAspectRatio()
{
double value = 2;
value /= 3;
return value;
}
2016-05-07 19:47:41 +02:00
public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
{
2016-11-20 21:20:01 +01:00
query.PersonIds = new[] { Id.ToString("N") };
2016-05-07 19:47:41 +02: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 23:47:16 +01:00
[IgnoreDataMember]
public override string ContainingFolderPath
{
get
{
return Path;
}
}
2015-02-06 06:39:07 +01:00
public override bool CanDelete()
{
return false;
}
2015-02-19 05:37:44 +01:00
public override bool IsSaveLocalMetadataEnabled()
{
return true;
}
2015-07-14 21:04:16 +02: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 23:47:16 +01:00
[IgnoreDataMember]
public override bool IsOwnedItem
{
get
{
return false;
}
2014-02-07 04:10:13 +01:00
}
public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
{
2015-07-07 04:25:23 +02:00
var itemsWithPerson = LibraryManager.GetItemIds(new InternalItemsQuery
{
2016-11-20 21:20:01 +01:00
PersonIds = new[] { Id.ToString("N") }
2015-07-07 04:25:23 +02:00
});
return inputItems.Where(i => itemsWithPerson.Contains(i.Id));
2015-01-25 07:34:50 +01:00
}
2015-01-26 23:47:16 +01:00
public Func<BaseItem, bool> GetItemFilter()
2015-01-25 07:34:50 +01:00
{
2015-06-28 18:36:25 +02:00
return i => LibraryManager.GetPeople(i).Any(p => string.Equals(p.Name, Name, StringComparison.OrdinalIgnoreCase));
}
2015-06-29 03:10:45 +02:00
[IgnoreDataMember]
public override bool SupportsPeople
{
get
{
return false;
}
}
2015-10-29 14:28:05 +01:00
[IgnoreDataMember]
public override bool SupportsAncestors
{
get
{
return false;
}
}
2016-08-18 07:56:10 +02:00
2017-03-13 05:08:23 +01:00
public static string GetPath(string name)
{
return GetPath(name, true);
}
public static string GetPath(string name, bool normalizeName)
2016-08-18 07:56:10 +02: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-21 02:33:05 +01:00
}
/// <summary>
/// This is the small Person stub that is attached to BaseItems
/// </summary>
2016-01-21 19:50:43 +01:00
public class PersonInfo : IHasProviderIds
2013-02-21 02:33:05 +01:00
{
2016-01-21 19:50:43 +01:00
public PersonInfo()
{
ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
2015-07-08 18:10:34 +02:00
public Guid ItemId { get; set; }
2013-02-21 02:33:05 +01: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 19:50:43 +01:00
public string ImageUrl { get; set; }
public Dictionary<string, string> ProviderIds { get; set; }
2013-02-21 02:33:05 +01: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 15:28:38 +02:00
public bool IsType(string type)
{
return string.Equals(Type, type, StringComparison.OrdinalIgnoreCase) || string.Equals(Role, type, StringComparison.OrdinalIgnoreCase);
}
2013-02-21 02:33:05 +01:00
}
}