diff options
Diffstat (limited to 'MediaBrowser.Controller/Entities')
| -rw-r--r-- | MediaBrowser.Controller/Entities/Audio.cs | 14 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/BaseEntity.cs | 94 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/BaseItem.cs | 202 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Folder.cs | 619 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Genre.cs | 7 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Movies/BoxSet.cs | 7 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Movies/Movie.cs | 31 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Person.cs | 25 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Studio.cs | 7 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/TV/Episode.cs | 7 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/TV/Season.cs | 34 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/TV/Series.cs | 12 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/User.cs | 21 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/UserItemData.cs | 67 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Video.cs | 20 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Year.cs | 7 |
16 files changed, 1174 insertions, 0 deletions
diff --git a/MediaBrowser.Controller/Entities/Audio.cs b/MediaBrowser.Controller/Entities/Audio.cs new file mode 100644 index 000000000..61e901dd2 --- /dev/null +++ b/MediaBrowser.Controller/Entities/Audio.cs @@ -0,0 +1,14 @@ +
+namespace MediaBrowser.Controller.Entities
+{
+ public class Audio : BaseItem
+ {
+ public int BitRate { get; set; }
+ public int Channels { get; set; }
+ public int SampleRate { get; set; }
+
+ public string Artist { get; set; }
+ public string Album { get; set; }
+ public string AlbumArtist { get; set; }
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/BaseEntity.cs b/MediaBrowser.Controller/Entities/BaseEntity.cs new file mode 100644 index 000000000..5b4a360c1 --- /dev/null +++ b/MediaBrowser.Controller/Entities/BaseEntity.cs @@ -0,0 +1,94 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.IO;
+using MediaBrowser.Controller.Providers;
+
+namespace MediaBrowser.Controller.Entities
+{
+ /// <summary>
+ /// Provides a base entity for all of our types
+ /// </summary>
+ public abstract class BaseEntity
+ {
+ public string Name { get; set; }
+
+ public Guid Id { get; set; }
+
+ public string Path { get; set; }
+
+ public Folder Parent { get; set; }
+
+ public string PrimaryImagePath { get; set; }
+
+ public DateTime DateCreated { get; set; }
+
+ public DateTime DateModified { get; set; }
+
+ public override string ToString()
+ {
+ return Name;
+ }
+ protected Dictionary<Guid, BaseProviderInfo> _providerData;
+ /// <summary>
+ /// Holds persistent data for providers like last refresh date.
+ /// Providers can use this to determine if they need to refresh.
+ /// The BaseProviderInfo class can be extended to hold anything a provider may need.
+ ///
+ /// Keyed by a unique provider ID.
+ /// </summary>
+ public Dictionary<Guid, BaseProviderInfo> ProviderData
+ {
+ get
+ {
+ if (_providerData == null) _providerData = new Dictionary<Guid, BaseProviderInfo>();
+ return _providerData;
+ }
+ set
+ {
+ _providerData = value;
+ }
+ }
+
+ protected ItemResolveEventArgs _resolveArgs;
+ /// <summary>
+ /// We attach these to the item so that we only ever have to hit the file system once
+ /// (this includes the children of the containing folder)
+ /// Use ResolveArgs.FileSystemChildren to check for the existence of files instead of File.Exists
+ /// </summary>
+ public ItemResolveEventArgs ResolveArgs
+ {
+ get
+ {
+ if (_resolveArgs == null)
+ {
+ _resolveArgs = new ItemResolveEventArgs()
+ {
+ FileInfo = FileData.GetFileData(this.Path),
+ Parent = this.Parent,
+ Cancel = false,
+ Path = this.Path
+ };
+ _resolveArgs = FileSystemHelper.FilterChildFileSystemEntries(_resolveArgs, (this.Parent != null && this.Parent.IsRoot));
+ }
+ return _resolveArgs;
+ }
+ set
+ {
+ _resolveArgs = value;
+ }
+ }
+
+ /// <summary>
+ /// Refresh metadata on us by execution our provider chain
+ /// </summary>
+ /// <returns>true if a provider reports we changed</returns>
+ public bool RefreshMetadata()
+ {
+ Kernel.Instance.ExecuteMetadataProviders(this).ConfigureAwait(false);
+ return true;
+ }
+
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs new file mode 100644 index 000000000..4c9008b22 --- /dev/null +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -0,0 +1,202 @@ +using MediaBrowser.Model.Entities;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.IO;
+using System;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace MediaBrowser.Controller.Entities
+{
+ public abstract class BaseItem : BaseEntity, IHasProviderIds
+ {
+
+ public IEnumerable<string> PhysicalLocations
+ {
+ get
+ {
+ return _resolveArgs.PhysicalLocations;
+ }
+ }
+
+ public string SortName { get; set; }
+
+ /// <summary>
+ /// When the item first debuted. For movies this could be premiere date, episodes would be first aired
+ /// </summary>
+ public DateTime? PremiereDate { 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; }
+
+ public string CustomRating { get; set; }
+ public string CustomPin { get; set; }
+
+ public string Language { get; set; }
+ public string Overview { get; set; }
+ public List<string> Taglines { get; set; }
+
+ /// <summary>
+ /// Using a Dictionary to prevent duplicates
+ /// </summary>
+ public Dictionary<string,PersonInfo> People { get; set; }
+
+ public List<string> Studios { get; set; }
+
+ public List<string> Genres { get; set; }
+
+ public string DisplayMediaType { get; set; }
+
+ public float? CommunityRating { get; set; }
+ public long? RunTimeTicks { get; set; }
+
+ public string AspectRatio { get; set; }
+ public int? ProductionYear { get; set; }
+
+ /// <summary>
+ /// If the item is part of a series, this is it's number in the series.
+ /// This could be episode number, album track number, etc.
+ /// </summary>
+ public int? IndexNumber { get; set; }
+
+ /// <summary>
+ /// For an episode this could be the season number, or for a song this could be the disc number.
+ /// </summary>
+ public int? ParentIndexNumber { get; set; }
+
+ public IEnumerable<Video> LocalTrailers { get; set; }
+
+ public string TrailerUrl { get; set; }
+
+ public Dictionary<string, string> ProviderIds { get; set; }
+
+ public Dictionary<Guid, UserItemData> UserData { get; set; }
+
+ public UserItemData GetUserData(User user, bool createIfNull)
+ {
+ if (UserData == null || !UserData.ContainsKey(user.Id))
+ {
+ if (createIfNull)
+ {
+ AddUserData(user, new UserItemData());
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ return UserData[user.Id];
+ }
+
+ private void AddUserData(User user, UserItemData data)
+ {
+ if (UserData == null)
+ {
+ UserData = new Dictionary<Guid, UserItemData>();
+ }
+
+ UserData[user.Id] = data;
+ }
+
+ /// <summary>
+ /// Determines if a given user has access to this item
+ /// </summary>
+ internal bool IsParentalAllowed(User user)
+ {
+ return true;
+ }
+
+ /// <summary>
+ /// Finds an item by ID, recursively
+ /// </summary>
+ public virtual BaseItem FindItemById(Guid id)
+ {
+ if (Id == id)
+ {
+ return this;
+ }
+
+ if (LocalTrailers != null)
+ {
+ return LocalTrailers.FirstOrDefault(i => i.Id == id);
+ }
+
+ return null;
+ }
+
+ public virtual bool IsFolder
+ {
+ get
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Determine if we have changed vs the passed in copy
+ /// </summary>
+ /// <param name="copy"></param>
+ /// <returns></returns>
+ public virtual bool IsChanged(BaseItem copy)
+ {
+ bool changed = copy.DateModified != this.DateModified;
+ if (changed) MediaBrowser.Common.Logging.Logger.LogDebugInfo(this.Name + " changed - original creation: " + this.DateCreated + " new creation: " + copy.DateCreated + " original modified: " + this.DateModified + " new modified: " + copy.DateModified);
+ return changed;
+ }
+
+ /// <summary>
+ /// Determines if the item is considered new based on user settings
+ /// </summary>
+ public bool IsRecentlyAdded(User user)
+ {
+ return (DateTime.UtcNow - DateCreated).TotalDays < user.RecentItemDays;
+ }
+
+ public void AddPerson(PersonInfo person)
+ {
+ if (People == null)
+ {
+ People = new Dictionary<string, PersonInfo>(StringComparer.OrdinalIgnoreCase);
+ }
+
+ People[person.Name] = person;
+ }
+
+ /// <summary>
+ /// Marks the item as either played or unplayed
+ /// </summary>
+ public virtual void SetPlayedStatus(User user, bool wasPlayed)
+ {
+ UserItemData data = GetUserData(user, true);
+
+ if (wasPlayed)
+ {
+ data.PlayCount = Math.Max(data.PlayCount, 1);
+ }
+ else
+ {
+ data.PlayCount = 0;
+ data.PlaybackPositionTicks = 0;
+ }
+ }
+
+ /// <summary>
+ /// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
+ /// </summary>
+ /// <returns></returns>
+ public virtual Task ChangedExternally()
+ {
+ return Task.Run(() => RefreshMetadata());
+ }
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs new file mode 100644 index 000000000..07529c80f --- /dev/null +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -0,0 +1,619 @@ +using MediaBrowser.Model.Entities;
+using MediaBrowser.Controller.IO;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Common.Logging;
+using MediaBrowser.Controller.Resolvers;
+using System;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace MediaBrowser.Controller.Entities
+{
+ public class Folder : BaseItem
+ {
+ #region Events
+ /// <summary>
+ /// Fires whenever a validation routine updates our children. The added and removed children are properties of the args.
+ /// *** Will fire asynchronously. ***
+ /// </summary>
+ public event EventHandler<ChildrenChangedEventArgs> ChildrenChanged;
+ protected void OnChildrenChanged(ChildrenChangedEventArgs args)
+ {
+ if (ChildrenChanged != null)
+ {
+ Task.Run( () =>
+ {
+ ChildrenChanged(this, args);
+ Kernel.Instance.OnLibraryChanged(args);
+ });
+ }
+ }
+
+ #endregion
+
+ public override bool IsFolder
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ public bool IsRoot { get; set; }
+
+ public bool IsVirtualFolder
+ {
+ get
+ {
+ return Parent != null && Parent.IsRoot;
+ }
+ }
+ protected object childLock = new object();
+ protected List<BaseItem> children;
+ protected virtual List<BaseItem> ActualChildren
+ {
+ get
+ {
+ if (children == null)
+ {
+ LoadChildren();
+ }
+ return children;
+ }
+
+ set
+ {
+ children = value;
+ }
+ }
+
+ /// <summary>
+ /// thread-safe access to the actual children of this folder - without regard to user
+ /// </summary>
+ public IEnumerable<BaseItem> Children
+ {
+ get
+ {
+ lock (childLock)
+ return ActualChildren.ToList();
+ }
+ }
+
+ /// <summary>
+ /// thread-safe access to all recursive children of this folder - without regard to user
+ /// </summary>
+ public IEnumerable<BaseItem> RecursiveChildren
+ {
+ get
+ {
+ foreach (var item in Children)
+ {
+ yield return item;
+
+ var subFolder = item as Folder;
+
+ if (subFolder != null)
+ {
+ foreach (var subitem in subFolder.RecursiveChildren)
+ {
+ yield return subitem;
+ }
+ }
+ }
+ }
+ }
+
+
+ /// <summary>
+ /// Loads and validates our children
+ /// </summary>
+ protected virtual void LoadChildren()
+ {
+ //first - load our children from the repo
+ lock (childLock)
+ children = GetCachedChildren();
+
+ //then kick off a validation against the actual file system
+ Task.Run(() => ValidateChildren());
+ }
+
+ protected bool ChildrenValidating = false;
+
+ /// <summary>
+ /// Compare our current children (presumably just read from the repo) with the current state of the file system and adjust for any changes
+ /// ***Currently does not contain logic to maintain items that are unavailable in the file system***
+ /// </summary>
+ /// <returns></returns>
+ protected async virtual void ValidateChildren()
+ {
+ if (ChildrenValidating) return; //only ever want one of these going at once and don't want them to fire off in sequence so don't use lock
+ ChildrenValidating = true;
+ bool changed = false; //this will save us a little time at the end if nothing changes
+ var changedArgs = new ChildrenChangedEventArgs(this);
+ //get the current valid children from filesystem (or wherever)
+ var nonCachedChildren = await GetNonCachedChildren();
+ if (nonCachedChildren == null) return; //nothing to validate
+ //build a dictionary of the current children we have now by Id so we can compare quickly and easily
+ Dictionary<Guid, BaseItem> currentChildren;
+ lock (childLock)
+ currentChildren = ActualChildren.ToDictionary(i => i.Id);
+
+ //create a list for our validated children
+ var validChildren = new List<BaseItem>();
+ //now traverse the valid children and find any changed or new items
+ foreach (var child in nonCachedChildren)
+ {
+ BaseItem currentChild;
+ currentChildren.TryGetValue(child.Id, out currentChild);
+ if (currentChild == null)
+ {
+ //brand new item - needs to be added
+ changed = true;
+ changedArgs.ItemsAdded.Add(child);
+ //refresh it
+ child.RefreshMetadata();
+ Logger.LogInfo("New Item Added to Library: ("+child.GetType().Name+") "+ child.Name + " (" + child.Path + ")");
+ //save it in repo...
+
+ //and add it to our valid children
+ validChildren.Add(child);
+ //fire an added event...?
+ //if it is a folder we need to validate its children as well
+ Folder folder = child as Folder;
+ if (folder != null)
+ {
+ folder.ValidateChildren();
+ //probably need to refresh too...
+ }
+ }
+ else
+ {
+ //existing item - check if it has changed
+ if (currentChild.IsChanged(child))
+ {
+ changed = true;
+ //update resolve args and refresh meta
+ // Note - we are refreshing the existing child instead of the newly found one so the "Except" operation below
+ // will identify this item as the same one
+ currentChild.ResolveArgs = child.ResolveArgs;
+ currentChild.RefreshMetadata();
+ Logger.LogInfo("Item Changed: ("+currentChild.GetType().Name+") "+ currentChild.Name + " (" + currentChild.Path + ")");
+ //save it in repo...
+ validChildren.Add(currentChild);
+ }
+ else
+ {
+ //current child that didn't change - just put it in the valid children
+ validChildren.Add(currentChild);
+ }
+ }
+ }
+
+ //that's all the new and changed ones - now see if there are any that are missing
+ changedArgs.ItemsRemoved = currentChildren.Values.Except(validChildren);
+ changed |= changedArgs.ItemsRemoved != null;
+
+ //now, if anything changed - replace our children
+ if (changed)
+ {
+ if (changedArgs.ItemsRemoved != null) foreach (var item in changedArgs.ItemsRemoved) Logger.LogDebugInfo("** " + item.Name + " Removed from library.");
+
+ lock (childLock)
+ ActualChildren = validChildren;
+ //and save children in repo...
+
+ //and fire event
+ this.OnChildrenChanged(changedArgs);
+ }
+ ChildrenValidating = false;
+
+ }
+
+ /// <summary>
+ /// Get the children of this folder from the actual file system
+ /// </summary>
+ /// <returns></returns>
+ protected async virtual Task<IEnumerable<BaseItem>> GetNonCachedChildren()
+ {
+ ItemResolveEventArgs args = new ItemResolveEventArgs()
+ {
+ FileInfo = FileData.GetFileData(this.Path),
+ Parent = this.Parent,
+ Cancel = false,
+ Path = this.Path
+ };
+
+ // Gather child folder and files
+ if (args.IsDirectory)
+ {
+ args.FileSystemChildren = FileData.GetFileSystemEntries(this.Path, "*").ToArray();
+
+ bool isVirtualFolder = Parent != null && Parent.IsRoot;
+ args = FileSystemHelper.FilterChildFileSystemEntries(args, isVirtualFolder);
+ }
+ else
+ {
+ Logger.LogError("Folder has a path that is not a directory: " + this.Path);
+ return null;
+ }
+
+ if (!EntityResolutionHelper.ShouldResolvePathContents(args))
+ {
+ return null;
+ }
+ return (await Task.WhenAll<BaseItem>(GetChildren(args.FileSystemChildren)).ConfigureAwait(false))
+ .Where(i => i != null).OrderBy(f =>
+ {
+ return string.IsNullOrEmpty(f.SortName) ? f.Name : f.SortName;
+
+ });
+
+ }
+
+ /// <summary>
+ /// Resolves a path into a BaseItem
+ /// </summary>
+ protected async Task<BaseItem> GetChild(string path, WIN32_FIND_DATA? fileInfo = null)
+ {
+ ItemResolveEventArgs args = new ItemResolveEventArgs()
+ {
+ FileInfo = fileInfo ?? FileData.GetFileData(path),
+ Parent = this,
+ Cancel = false,
+ Path = path
+ };
+
+ args.FileSystemChildren = FileData.GetFileSystemEntries(path, "*").ToArray();
+ args = FileSystemHelper.FilterChildFileSystemEntries(args, false);
+
+ return Kernel.Instance.ResolveItem(args);
+
+ }
+
+ /// <summary>
+ /// Finds child BaseItems for us
+ /// </summary>
+ protected Task<BaseItem>[] GetChildren(WIN32_FIND_DATA[] fileSystemChildren)
+ {
+ Task<BaseItem>[] tasks = new Task<BaseItem>[fileSystemChildren.Length];
+
+ for (int i = 0; i < fileSystemChildren.Length; i++)
+ {
+ var child = fileSystemChildren[i];
+
+ tasks[i] = GetChild(child.Path, child);
+ }
+
+ return tasks;
+ }
+
+
+ /// <summary>
+ /// Get our children from the repo - stubbed for now
+ /// </summary>
+ /// <returns></returns>
+ protected virtual List<BaseItem> GetCachedChildren()
+ {
+ return new List<BaseItem>();
+ }
+
+ /// <summary>
+ /// Gets allowed children of an item
+ /// </summary>
+ public IEnumerable<BaseItem> GetChildren(User user)
+ {
+ lock(childLock)
+ return ActualChildren.Where(c => c.IsParentalAllowed(user));
+ }
+
+ /// <summary>
+ /// Gets allowed recursive children of an item
+ /// </summary>
+ public IEnumerable<BaseItem> GetRecursiveChildren(User user)
+ {
+ foreach (var item in GetChildren(user))
+ {
+ yield return item;
+
+ var subFolder = item as Folder;
+
+ if (subFolder != null)
+ {
+ foreach (var subitem in subFolder.GetRecursiveChildren(user))
+ {
+ yield return subitem;
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Folders need to validate and refresh
+ /// </summary>
+ /// <returns></returns>
+ public override Task ChangedExternally()
+ {
+ return Task.Run(() =>
+ {
+ if (this.IsRoot)
+ {
+ Kernel.Instance.ReloadRoot().ConfigureAwait(false);
+ }
+ else
+ {
+ RefreshMetadata();
+ ValidateChildren();
+ }
+ });
+ }
+
+ /// <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)
+ {
+ var counts = new ItemSpecialCounts();
+
+ IEnumerable<BaseItem> recursiveChildren = GetRecursiveChildren(user);
+
+ var recentlyAddedItems = GetRecentlyAddedItems(recursiveChildren, user);
+
+ counts.RecentlyAddedItemCount = recentlyAddedItems.Count;
+ counts.RecentlyAddedUnPlayedItemCount = GetRecentlyAddedUnplayedItems(recentlyAddedItems, user).Count;
+ counts.InProgressItemCount = GetInProgressItems(recursiveChildren, user).Count;
+ counts.PlayedPercentage = GetPlayedPercentage(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)
+ {
+ return GetRecursiveChildren(user).Where(f => f.Genres != null && f.Genres.Any(s => s.Equals(genre, StringComparison.OrdinalIgnoreCase)));
+ }
+
+ /// <summary>
+ /// Finds all recursive items within a top-level parent that contain the given year and are allowed for the current user
+ /// </summary>
+ public IEnumerable<BaseItem> GetItemsWithYear(int year, User user)
+ {
+ return GetRecursiveChildren(user).Where(f => f.ProductionYear.HasValue && f.ProductionYear == year);
+ }
+
+ /// <summary>
+ /// Finds all recursive items within a top-level parent that contain the given studio and are allowed for the current user
+ /// </summary>
+ public IEnumerable<BaseItem> GetItemsWithStudio(string studio, User user)
+ {
+ return GetRecursiveChildren(user).Where(f => f.Studios != null && f.Studios.Any(s => s.Equals(studio, StringComparison.OrdinalIgnoreCase)));
+ }
+
+ /// <summary>
+ /// Finds all recursive items within a top-level parent that the user has marked as a favorite
+ /// </summary>
+ public IEnumerable<BaseItem> GetFavoriteItems(User user)
+ {
+ return GetRecursiveChildren(user).Where(c =>
+ {
+ UserItemData data = c.GetUserData(user, false);
+
+ if (data != null)
+ {
+ return data.IsFavorite;
+ }
+
+ 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>
+ public IEnumerable<BaseItem> GetItemsWithPerson(string person, User user)
+ {
+ return GetRecursiveChildren(user).Where(c =>
+ {
+ if (c.People != null)
+ {
+ return c.People.ContainsKey(person);
+ }
+
+ 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, string personType, User user)
+ {
+ return GetRecursiveChildren(user).Where(c =>
+ {
+ if (c.People != null)
+ {
+ return c.People.ContainsKey(person) && c.People[person].Type.Equals(personType, StringComparison.OrdinalIgnoreCase);
+ }
+
+ return false;
+ });
+ }
+
+ /// <summary>
+ /// Gets all recently added items (recursive) within a folder, based on configuration and parental settings
+ /// </summary>
+ public List<BaseItem> GetRecentlyAddedItems(User user)
+ {
+ return GetRecentlyAddedItems(GetRecursiveChildren(user), user);
+ }
+
+ /// <summary>
+ /// Gets all recently added unplayed items (recursive) within a folder, based on configuration and parental settings
+ /// </summary>
+ public List<BaseItem> GetRecentlyAddedUnplayedItems(User user)
+ {
+ return GetRecentlyAddedUnplayedItems(GetRecursiveChildren(user), user);
+ }
+
+ /// <summary>
+ /// Gets all in-progress items (recursive) within a folder
+ /// </summary>
+ public List<BaseItem> GetInProgressItems(User user)
+ {
+ return GetInProgressItems(GetRecursiveChildren(user), user);
+ }
+
+ /// <summary>
+ /// Takes a list of items and returns the ones that are recently added
+ /// </summary>
+ private static List<BaseItem> GetRecentlyAddedItems(IEnumerable<BaseItem> itemSet, User user)
+ {
+ var list = new List<BaseItem>();
+
+ foreach (var item in itemSet)
+ {
+ if (!item.IsFolder && item.IsRecentlyAdded(user))
+ {
+ list.Add(item);
+ }
+ }
+
+ return list;
+ }
+
+ /// <summary>
+ /// Takes a list of items and returns the ones that are recently added and unplayed
+ /// </summary>
+ private static List<BaseItem> GetRecentlyAddedUnplayedItems(IEnumerable<BaseItem> itemSet, User user)
+ {
+ var list = new List<BaseItem>();
+
+ foreach (var item in itemSet)
+ {
+ if (!item.IsFolder && item.IsRecentlyAdded(user))
+ {
+ var userdata = item.GetUserData(user, false);
+
+ if (userdata == null || userdata.PlayCount == 0)
+ {
+ list.Add(item);
+ }
+ }
+ }
+
+ return list;
+ }
+
+ /// <summary>
+ /// Takes a list of items and returns the ones that are in progress
+ /// </summary>
+ private static List<BaseItem> GetInProgressItems(IEnumerable<BaseItem> itemSet, User user)
+ {
+ var list = new List<BaseItem>();
+
+ foreach (var item in itemSet)
+ {
+ if (!item.IsFolder)
+ {
+ var userdata = item.GetUserData(user, false);
+
+ if (userdata != null && userdata.PlaybackPositionTicks > 0)
+ {
+ list.Add(item);
+ }
+ }
+ }
+
+ return list;
+ }
+
+ /// <summary>
+ /// Gets the total played percentage for a set of items
+ /// </summary>
+ private static decimal GetPlayedPercentage(IEnumerable<BaseItem> itemSet, User user)
+ {
+ itemSet = itemSet.Where(i => !(i.IsFolder));
+
+ decimal totalPercent = 0;
+
+ int count = 0;
+
+ foreach (BaseItem item in itemSet)
+ {
+ count++;
+
+ UserItemData data = item.GetUserData(user, false);
+
+ 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;
+ }
+ }
+
+ if (count == 0)
+ {
+ return 0;
+ }
+
+ return totalPercent / count;
+ }
+
+ /// <summary>
+ /// Marks the item as either played or unplayed
+ /// </summary>
+ public override void SetPlayedStatus(User user, bool wasPlayed)
+ {
+ base.SetPlayedStatus(user, wasPlayed);
+
+ // Now sweep through recursively and update status
+ foreach (BaseItem item in GetChildren(user))
+ {
+ item.SetPlayedStatus(user, wasPlayed);
+ }
+ }
+
+ /// <summary>
+ /// Finds an item by ID, recursively
+ /// </summary>
+ public override BaseItem FindItemById(Guid id)
+ {
+ var result = base.FindItemById(id);
+
+ if (result != null)
+ {
+ return result;
+ }
+
+ //this should be functionally equivilent to what was here since it is IEnum and works on a thread-safe copy
+ return RecursiveChildren.FirstOrDefault(i => i.Id == id);
+ }
+
+ /// <summary>
+ /// Finds an item by path, recursively
+ /// </summary>
+ public BaseItem FindByPath(string path)
+ {
+ if (PhysicalLocations.Contains(path, StringComparer.OrdinalIgnoreCase))
+ {
+ return this;
+ }
+
+ //this should be functionally equivilent to what was here since it is IEnum and works on a thread-safe copy
+ return RecursiveChildren.FirstOrDefault(i => i.PhysicalLocations.Contains(path, StringComparer.OrdinalIgnoreCase));
+ }
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/Genre.cs b/MediaBrowser.Controller/Entities/Genre.cs new file mode 100644 index 000000000..ba343a2bc --- /dev/null +++ b/MediaBrowser.Controller/Entities/Genre.cs @@ -0,0 +1,7 @@ +
+namespace MediaBrowser.Controller.Entities
+{
+ public class Genre : BaseEntity
+ {
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs new file mode 100644 index 000000000..cb841530e --- /dev/null +++ b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs @@ -0,0 +1,7 @@ +
+namespace MediaBrowser.Controller.Entities.Movies
+{
+ public class BoxSet : Folder
+ {
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/Movies/Movie.cs b/MediaBrowser.Controller/Entities/Movies/Movie.cs new file mode 100644 index 000000000..2d98fa06e --- /dev/null +++ b/MediaBrowser.Controller/Entities/Movies/Movie.cs @@ -0,0 +1,31 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace MediaBrowser.Controller.Entities.Movies
+{
+ public class Movie : Video
+ {
+ public IEnumerable<Video> SpecialFeatures { get; set; }
+
+ /// <summary>
+ /// Finds an item by ID, recursively
+ /// </summary>
+ public override BaseItem FindItemById(Guid id)
+ {
+ var item = base.FindItemById(id);
+
+ if (item != null)
+ {
+ return item;
+ }
+
+ if (SpecialFeatures != null)
+ {
+ return SpecialFeatures.FirstOrDefault(i => i.Id == id);
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/Person.cs b/MediaBrowser.Controller/Entities/Person.cs new file mode 100644 index 000000000..a12b9e38e --- /dev/null +++ b/MediaBrowser.Controller/Entities/Person.cs @@ -0,0 +1,25 @@ +
+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 : BaseEntity
+ {
+ }
+
+ /// <summary>
+ /// This is the small Person stub that is attached to BaseItems
+ /// </summary>
+ public class PersonInfo
+ {
+ public string Name { get; set; }
+ public string Overview { get; set; }
+ public string Type { get; set; }
+
+ public override string ToString()
+ {
+ return Name;
+ }
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/Studio.cs b/MediaBrowser.Controller/Entities/Studio.cs new file mode 100644 index 000000000..b7c6e6aa4 --- /dev/null +++ b/MediaBrowser.Controller/Entities/Studio.cs @@ -0,0 +1,7 @@ +
+namespace MediaBrowser.Controller.Entities
+{
+ public class Studio : BaseEntity
+ {
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs new file mode 100644 index 000000000..5d599fca7 --- /dev/null +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -0,0 +1,7 @@ +
+namespace MediaBrowser.Controller.Entities.TV
+{
+ public class Episode : Video
+ {
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs new file mode 100644 index 000000000..f9c7fecb3 --- /dev/null +++ b/MediaBrowser.Controller/Entities/TV/Season.cs @@ -0,0 +1,34 @@ +using System;
+
+namespace MediaBrowser.Controller.Entities.TV
+{
+ public class Season : Folder
+ {
+ /// <summary>
+ /// Store these to reduce disk access in Episode Resolver
+ /// </summary>
+ public string[] MetadataFiles
+ {
+ get
+ {
+ return ResolveArgs.MetadataFiles ?? new string[] { };
+ }
+ }
+
+ /// <summary>
+ /// Determines if the metafolder contains a given file
+ /// </summary>
+ public bool ContainsMetadataFile(string file)
+ {
+ for (int i = 0; i < MetadataFiles.Length; i++)
+ {
+ if (MetadataFiles[i].Equals(file, StringComparison.OrdinalIgnoreCase))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs new file mode 100644 index 000000000..7c228a53d --- /dev/null +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -0,0 +1,12 @@ +using System;
+using System.Collections.Generic;
+
+namespace MediaBrowser.Controller.Entities.TV
+{
+ public class Series : Folder
+ {
+ public string Status { get; set; }
+ public IEnumerable<DayOfWeek> AirDays { get; set; }
+ public string AirTime { get; set; }
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs new file mode 100644 index 000000000..01eadfafb --- /dev/null +++ b/MediaBrowser.Controller/Entities/User.cs @@ -0,0 +1,21 @@ +using System;
+
+namespace MediaBrowser.Controller.Entities
+{
+ public class User : BaseEntity
+ {
+ public string Password { get; set; }
+
+ public string MaxParentalRating { get; set; }
+
+ public int RecentItemDays { get; set; }
+
+ public User()
+ {
+ RecentItemDays = 14;
+ }
+
+ public DateTime? LastLoginDate { get; set; }
+ public DateTime? LastActivityDate { get; set; }
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/UserItemData.cs b/MediaBrowser.Controller/Entities/UserItemData.cs new file mode 100644 index 000000000..bb4950046 --- /dev/null +++ b/MediaBrowser.Controller/Entities/UserItemData.cs @@ -0,0 +1,67 @@ +using System;
+using System.Runtime.Serialization;
+
+namespace MediaBrowser.Controller.Entities
+{
+ public class UserItemData
+ {
+ private float? _rating;
+ /// <summary>
+ /// Gets or sets the users 0-10 rating
+ /// </summary>
+ public float? Rating
+ {
+ get
+ {
+ return _rating;
+ }
+ set
+ {
+ if (value.HasValue)
+ {
+ if (value.Value < 0 || value.Value > 10)
+ {
+ throw new InvalidOperationException("A 0-10 rating is required for UserItemData.");
+ }
+ }
+
+ _rating = value;
+ }
+ }
+
+ public long PlaybackPositionTicks { get; set; }
+
+ public int PlayCount { get; set; }
+
+ public bool IsFavorite { get; set; }
+
+ /// <summary>
+ /// This is an interpreted property to indicate likes or dislikes
+ /// This should never be serialized.
+ /// </summary>
+ [IgnoreDataMember]
+ public bool? Likes
+ {
+ get
+ {
+ if (Rating != null)
+ {
+ return Rating >= 6.5;
+ }
+
+ return null;
+ }
+ set
+ {
+ if (value.HasValue)
+ {
+ Rating = value.Value ? 10 : 1;
+ }
+ else
+ {
+ Rating = null;
+ }
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs new file mode 100644 index 000000000..8dd82fab9 --- /dev/null +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -0,0 +1,20 @@ +using MediaBrowser.Model.Entities;
+using System.Collections.Generic;
+
+namespace MediaBrowser.Controller.Entities
+{
+ public class Video : BaseItem
+ {
+ public VideoType VideoType { get; set; }
+
+ public List<SubtitleStream> Subtitles { get; set; }
+ public List<AudioStream> AudioStreams { get; set; }
+
+ public int Height { get; set; }
+ public int Width { get; set; }
+ public string ScanType { get; set; }
+ public float FrameRate { get; set; }
+ public int BitRate { get; set; }
+ public string Codec { get; set; }
+ }
+}
diff --git a/MediaBrowser.Controller/Entities/Year.cs b/MediaBrowser.Controller/Entities/Year.cs new file mode 100644 index 000000000..d0b29de56 --- /dev/null +++ b/MediaBrowser.Controller/Entities/Year.cs @@ -0,0 +1,7 @@ +
+namespace MediaBrowser.Controller.Entities
+{
+ public class Year : BaseEntity
+ {
+ }
+}
|
