diff options
Diffstat (limited to 'MediaBrowser.Model/Entities')
| -rw-r--r-- | MediaBrowser.Model/Entities/BaseItem.cs | 65 | ||||
| -rw-r--r-- | MediaBrowser.Model/Entities/Folder.cs | 144 | ||||
| -rw-r--r-- | MediaBrowser.Model/Entities/IHasProviderIds.cs | 57 | ||||
| -rw-r--r-- | MediaBrowser.Model/Entities/ItemSpecialCounts.cs | 14 | ||||
| -rw-r--r-- | MediaBrowser.Model/Entities/Person.cs | 11 | ||||
| -rw-r--r-- | MediaBrowser.Model/Entities/User.cs | 15 | ||||
| -rw-r--r-- | MediaBrowser.Model/Entities/UserItemData.cs | 20 | ||||
| -rw-r--r-- | MediaBrowser.Model/Entities/Video.cs | 17 |
8 files changed, 251 insertions, 92 deletions
diff --git a/MediaBrowser.Model/Entities/BaseItem.cs b/MediaBrowser.Model/Entities/BaseItem.cs index c9d5b936b..506c051c5 100644 --- a/MediaBrowser.Model/Entities/BaseItem.cs +++ b/MediaBrowser.Model/Entities/BaseItem.cs @@ -1,11 +1,10 @@ using System;
using System.Collections.Generic;
-using System.Runtime.Serialization;
-using MediaBrowser.Model.Users;
+using System.Linq;
namespace MediaBrowser.Model.Entities
{
- public abstract class BaseItem : BaseEntity
+ public abstract class BaseItem : BaseEntity, IHasProviderIds
{
public string SortName { get; set; }
@@ -16,25 +15,25 @@ namespace MediaBrowser.Model.Entities public string Path { get; set; }
- [IgnoreDataMember]
public Folder Parent { get; set; }
public string LogoImagePath { get; set; }
+
public string ArtImagePath { get; set; }
+
public string ThumbnailImagePath { get; set; }
+
public string BannerImagePath { get; set; }
public IEnumerable<string> BackdropImagePaths { get; set; }
public string OfficialRating { get; set; }
- [IgnoreDataMember]
public string CustomRating { get; set; }
public string Overview { get; set; }
- public string Tagline { get; set; }
+ public IEnumerable<string> Taglines { get; set; }
- [IgnoreDataMember]
public IEnumerable<PersonInfo> People { get; set; }
public IEnumerable<string> Studios { get; set; }
@@ -44,7 +43,7 @@ namespace MediaBrowser.Model.Entities public string DisplayMediaType { get; set; }
public float? UserRating { get; set; }
- public int? RunTimeInMilliseconds { get; set; }
+ public long? RunTimeTicks { get; set; }
public string AspectRatio { get; set; }
public int? ProductionYear { get; set; }
@@ -61,54 +60,52 @@ namespace MediaBrowser.Model.Entities public Dictionary<string, string> ProviderIds { get; set; }
- /// <summary>
- /// Gets a provider id
- /// </summary>
- public string GetProviderId(MetadataProviders provider)
- {
- return GetProviderId(provider.ToString());
- }
+ public Dictionary<Guid, UserItemData> UserData { get; set; }
- /// <summary>
- /// Gets a provider id
- /// </summary>
- public string GetProviderId(string name)
+ public UserItemData GetUserData(User user)
{
- if (ProviderIds == null)
+ if (UserData == null || !UserData.ContainsKey(user.Id))
{
return null;
}
- return ProviderIds[name];
+ return UserData[user.Id];
}
- /// <summary>
- /// Sets a provider id
- /// </summary>
- public void SetProviderId(string name, string value)
+ public void AddUserData(User user, UserItemData data)
{
- if (ProviderIds == null)
+ if (UserData == null)
{
- ProviderIds = new Dictionary<string, string>();
+ UserData = new Dictionary<Guid, UserItemData>();
}
- ProviderIds[name] = value;
+ UserData[user.Id] = data;
}
/// <summary>
- /// Sets a provider id
+ /// Determines if a given user has access to this item
/// </summary>
- public void SetProviderId(MetadataProviders provider, string value)
+ internal bool IsParentalAllowed(User user)
{
- SetProviderId(provider.ToString(), value);
+ return true;
}
/// <summary>
- /// Determines if a given user has access to this item
+ /// Finds an item by ID, recursively
/// </summary>
- internal bool IsParentalAllowed(User user)
+ public virtual BaseItem FindItemById(Guid id)
{
- return true;
+ if (Id == id)
+ {
+ return this;
+ }
+
+ if (LocalTrailers != null)
+ {
+ return LocalTrailers.FirstOrDefault(i => i.Id == id);
+ }
+
+ return null;
}
}
}
diff --git a/MediaBrowser.Model/Entities/Folder.cs b/MediaBrowser.Model/Entities/Folder.cs index 98f1d8229..105151f31 100644 --- a/MediaBrowser.Model/Entities/Folder.cs +++ b/MediaBrowser.Model/Entities/Folder.cs @@ -1,8 +1,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
-using System.Runtime.Serialization;
-using MediaBrowser.Model.Users;
namespace MediaBrowser.Model.Entities
{
@@ -18,7 +16,6 @@ namespace MediaBrowser.Model.Entities }
}
- [IgnoreDataMember]
public BaseItem[] Children { get; set; }
/// <summary>
@@ -51,6 +48,23 @@ namespace MediaBrowser.Model.Entities }
/// <summary>
+ /// Since it can be slow to make all of these calculations at once, this method will provide a way to get them all back together
+ /// </summary>
+ public ItemSpecialCounts GetSpecialCounts(User user)
+ {
+ ItemSpecialCounts counts = new ItemSpecialCounts();
+
+ IEnumerable<BaseItem> recursiveChildren = GetParentalAllowedRecursiveChildren(user);
+
+ counts.RecentlyAddedItemCount = GetRecentlyAddedItems(recursiveChildren, user).Count();
+ counts.RecentlyAddedUnPlayedItemCount = GetRecentlyAddedUnplayedItems(recursiveChildren, user).Count();
+ counts.InProgressItemCount = GetInProgressItems(recursiveChildren, user).Count();
+ counts.WatchedPercentage = GetWatchedPercentage(recursiveChildren, user);
+
+ return counts;
+ }
+
+ /// <summary>
/// Finds all recursive items within a top-level parent that contain the given genre and are allowed for the current user
/// </summary>
public IEnumerable<BaseItem> GetItemsWithGenre(string genre, User user)
@@ -77,21 +91,30 @@ namespace MediaBrowser.Model.Entities /// <summary>
/// Finds all recursive items within a top-level parent that contain the given person and are allowed for the current user
/// </summary>
+ public IEnumerable<BaseItem> GetItemsWithPerson(string person, User user)
+ {
+ return GetParentalAllowedRecursiveChildren(user).Where(c =>
+ {
+ if (c.People != null)
+ {
+ return c.People.Any(p => p.Name.Equals(person, StringComparison.OrdinalIgnoreCase));
+ }
+
+ return false;
+ });
+ }
+
+ /// <summary>
+ /// Finds all recursive items within a top-level parent that contain the given person and are allowed for the current user
+ /// </summary>
/// <param name="personType">Specify this to limit results to a specific PersonType</param>
- public IEnumerable<BaseItem> GetItemsWithPerson(string person, PersonType? personType, User user)
+ public IEnumerable<BaseItem> GetItemsWithPerson(string person, string personType, User user)
{
return GetParentalAllowedRecursiveChildren(user).Where(c =>
{
if (c.People != null)
{
- if (personType.HasValue)
- {
- return c.People.Any(p => p.Name.Equals(person, StringComparison.OrdinalIgnoreCase) && p.PersonType == personType.Value);
- }
- else
- {
- return c.People.Any(p => p.Name.Equals(person, StringComparison.OrdinalIgnoreCase));
- }
+ return c.People.Any(p => p.Name.Equals(person, StringComparison.OrdinalIgnoreCase) && p.Type == personType);
}
return false;
@@ -103,9 +126,7 @@ namespace MediaBrowser.Model.Entities /// </summary>
public IEnumerable<BaseItem> GetRecentlyAddedItems(User user)
{
- DateTime now = DateTime.Now;
-
- return GetParentalAllowedRecursiveChildren(user).Where(i => !(i is Folder) && (now - i.DateCreated).TotalDays < user.RecentItemDays);
+ return GetRecentlyAddedItems(GetParentalAllowedRecursiveChildren(user), user);
}
/// <summary>
@@ -113,12 +134,7 @@ namespace MediaBrowser.Model.Entities /// </summary>
public IEnumerable<BaseItem> GetRecentlyAddedUnplayedItems(User user)
{
- return GetRecentlyAddedItems(user).Where(i =>
- {
- var userdata = user.GetItemData(i.Id);
-
- return userdata == null || userdata.PlayCount == 0;
- });
+ return GetRecentlyAddedUnplayedItems(GetParentalAllowedRecursiveChildren(user), user);
}
/// <summary>
@@ -126,45 +142,95 @@ namespace MediaBrowser.Model.Entities /// </summary>
public IEnumerable<BaseItem> GetInProgressItems(User user)
{
- return GetParentalAllowedRecursiveChildren(user).Where(i =>
+ return GetInProgressItems(GetParentalAllowedRecursiveChildren(user), user);
+ }
+
+ private static IEnumerable<BaseItem> GetRecentlyAddedItems(IEnumerable<BaseItem> itemSet, User user)
+ {
+ DateTime now = DateTime.Now;
+
+ return itemSet.Where(i => !(i is Folder) && (now - i.DateCreated).TotalDays < user.RecentItemDays);
+ }
+
+ private static IEnumerable<BaseItem> GetRecentlyAddedUnplayedItems(IEnumerable<BaseItem> itemSet, User user)
+ {
+ return GetRecentlyAddedItems(itemSet, user).Where(i =>
+ {
+ var userdata = i.GetUserData(user);
+
+ return userdata == null || userdata.PlayCount == 0;
+ });
+ }
+
+ private static IEnumerable<BaseItem> GetInProgressItems(IEnumerable<BaseItem> itemSet, User user)
+ {
+ return itemSet.Where(i =>
{
if (i is Folder)
{
return false;
}
- var userdata = user.GetItemData(i.Id);
+ var userdata = i.GetUserData(user);
- return userdata != null && userdata.PlaybackPosition.Ticks > 0;
+ return userdata != null && userdata.PlaybackPositionTicks > 0;
});
}
+ private static decimal GetWatchedPercentage(IEnumerable<BaseItem> itemSet, User user)
+ {
+ itemSet = itemSet.Where(i => !(i is Folder));
+
+ if (!itemSet.Any())
+ {
+ return 0;
+ }
+
+ decimal totalPercent = 0;
+
+ foreach (BaseItem item in itemSet)
+ {
+ UserItemData data = item.GetUserData(user);
+
+ if (data == null)
+ {
+ continue;
+ }
+
+ if (data.PlayCount > 0)
+ {
+ totalPercent += 100;
+ }
+ else if (data.PlaybackPositionTicks > 0 && item.RunTimeTicks.HasValue)
+ {
+ decimal itemPercent = data.PlaybackPositionTicks;
+ itemPercent /= item.RunTimeTicks.Value;
+ totalPercent += itemPercent;
+ }
+ }
+
+ return totalPercent / itemSet.Count();
+ }
+
/// <summary>
/// Finds an item by ID, recursively
/// </summary>
- public BaseItem FindById(Guid id)
+ public override BaseItem FindItemById(Guid id)
{
- if (Id == id)
+ var result = base.FindItemById(id);
+
+ if (result != null)
{
- return this;
+ return result;
}
foreach (BaseItem item in Children)
{
- var folder = item as Folder;
+ result = item.FindItemById(id);
- if (folder != null)
+ if (result != null)
{
- var foundItem = folder.FindById(id);
-
- if (foundItem != null)
- {
- return foundItem;
- }
- }
- else if (item.Id == id)
- {
- return item;
+ return result;
}
}
diff --git a/MediaBrowser.Model/Entities/IHasProviderIds.cs b/MediaBrowser.Model/Entities/IHasProviderIds.cs new file mode 100644 index 000000000..3406d618b --- /dev/null +++ b/MediaBrowser.Model/Entities/IHasProviderIds.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic;
+
+namespace MediaBrowser.Model.Entities
+{
+ /// <summary>
+ /// Since BaseItem and DTOBaseItem both have ProviderIds, this interface helps avoid code repition using extension methods
+ /// </summary>
+ public interface IHasProviderIds
+ {
+ Dictionary<string, string> ProviderIds { get; set; }
+ }
+
+ public static class IProviderIdsExtensions
+ {
+ /// <summary>
+ /// Gets a provider id
+ /// </summary>
+ public static string GetProviderId(this IHasProviderIds instance, MetadataProviders provider)
+ {
+ return instance.GetProviderId(provider.ToString());
+ }
+
+ /// <summary>
+ /// Gets a provider id
+ /// </summary>
+ public static string GetProviderId(this IHasProviderIds instance, string name)
+ {
+ if (instance.ProviderIds == null)
+ {
+ return null;
+ }
+
+ return instance.ProviderIds[name];
+ }
+
+ /// <summary>
+ /// Sets a provider id
+ /// </summary>
+ public static void SetProviderId(this IHasProviderIds instance, string name, string value)
+ {
+ if (instance.ProviderIds == null)
+ {
+ instance.ProviderIds = new Dictionary<string, string>();
+ }
+
+ instance.ProviderIds[name] = value;
+ }
+
+ /// <summary>
+ /// Sets a provider id
+ /// </summary>
+ public static void SetProviderId(this IHasProviderIds instance, MetadataProviders provider, string value)
+ {
+ instance.SetProviderId(provider.ToString(), value);
+ }
+ }
+}
diff --git a/MediaBrowser.Model/Entities/ItemSpecialCounts.cs b/MediaBrowser.Model/Entities/ItemSpecialCounts.cs new file mode 100644 index 000000000..9add9fe99 --- /dev/null +++ b/MediaBrowser.Model/Entities/ItemSpecialCounts.cs @@ -0,0 +1,14 @@ +
+namespace MediaBrowser.Model.Entities
+{
+ /// <summary>
+ /// Since it can be slow to collect this data. This class helps provide a way to calculate them all at once.
+ /// </summary>
+ public class ItemSpecialCounts
+ {
+ public int RecentlyAddedItemCount { get; set; }
+ public int RecentlyAddedUnPlayedItemCount { get; set; }
+ public int InProgressItemCount { get; set; }
+ public decimal WatchedPercentage { get; set; }
+ }
+}
diff --git a/MediaBrowser.Model/Entities/Person.cs b/MediaBrowser.Model/Entities/Person.cs index e85f8a905..2bd383802 100644 --- a/MediaBrowser.Model/Entities/Person.cs +++ b/MediaBrowser.Model/Entities/Person.cs @@ -15,20 +15,11 @@ namespace MediaBrowser.Model.Entities {
public string Name { get; set; }
public string Overview { get; set; }
- public PersonType PersonType { get; set; }
+ public string Type { get; set; }
public override string ToString()
{
return Name;
}
}
-
- public enum PersonType
- {
- Other,
- Actor,
- Director,
- Writer,
- Producer
- }
}
diff --git a/MediaBrowser.Model/Entities/User.cs b/MediaBrowser.Model/Entities/User.cs new file mode 100644 index 000000000..921727631 --- /dev/null +++ b/MediaBrowser.Model/Entities/User.cs @@ -0,0 +1,15 @@ +
+namespace MediaBrowser.Model.Entities
+{
+ public class User : BaseEntity
+ {
+ public string MaxParentalRating { get; set; }
+
+ public int RecentItemDays { get; set; }
+
+ public User()
+ {
+ RecentItemDays = 14;
+ }
+ }
+}
diff --git a/MediaBrowser.Model/Entities/UserItemData.cs b/MediaBrowser.Model/Entities/UserItemData.cs new file mode 100644 index 000000000..817cf640e --- /dev/null +++ b/MediaBrowser.Model/Entities/UserItemData.cs @@ -0,0 +1,20 @@ +using System;
+
+namespace MediaBrowser.Model.Entities
+{
+ public class UserItemData
+ {
+ public UserItemRating Rating { get; set; }
+
+ public long PlaybackPositionTicks { get; set; }
+
+ public int PlayCount { get; set; }
+ }
+
+ public enum UserItemRating
+ {
+ Likes,
+ Dislikes,
+ Favorite
+ }
+}
diff --git a/MediaBrowser.Model/Entities/Video.cs b/MediaBrowser.Model/Entities/Video.cs index b99cacd13..688226634 100644 --- a/MediaBrowser.Model/Entities/Video.cs +++ b/MediaBrowser.Model/Entities/Video.cs @@ -6,28 +6,27 @@ namespace MediaBrowser.Model.Entities {
public VideoType VideoType { get; set; }
- private IEnumerable<string> _Subtitles = new string[] { };
- public IEnumerable<string> Subtitles { get { return _Subtitles; } set { _Subtitles = value; } }
-
- private IEnumerable<AudioStream> _AudioStreams = new AudioStream[] { };
- public IEnumerable<AudioStream> AudioStreams { get { return _AudioStreams; } set { _AudioStreams = value; } }
+ public IEnumerable<string> Subtitles { get; set; }
+ public IEnumerable<AudioStream> AudioStreams { get; set; }
public int Height { get; set; }
public int Width { get; set; }
public string ScanType { get; set; }
public string FrameRate { get; set; }
- public int VideoBitRate { get; set; }
- public string VideoCodec { get; set; }
+ public int BitRate { get; set; }
+ public string Codec { get; set; }
}
public class AudioStream
{
- public string AudioFormat { get; set; }
- public string AudioProfile { get; set; }
+ public string Format { get; set; }
+ public string Profile { get; set; }
public string Language { get; set; }
public int BitRate { get; set; }
public int Channels { get; set; }
public int SampleRate { get; set; }
+ public bool IsDefault { get; set; }
+ public bool IsForced { get; set; }
}
public enum VideoType
|
