From 6fbd5cf46407a212fadb52eee00c7ac7690430ea Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Mon, 16 Jul 2012 12:50:44 -0400 Subject: All calls to get items now require passing in a userId. Made the model project portable. Also filled in more api calls. --- MediaBrowser.Controller/Kernel.cs | 127 ++++++++++++++++++++- MediaBrowser.Controller/Library/ItemController.cs | 18 +++ .../MediaBrowser.Controller.csproj | 2 +- 3 files changed, 145 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 3db0cca8f..3f6e7bbb0 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -84,7 +84,6 @@ namespace MediaBrowser.Controller // Get users from users folder // Load root media folder Parallel.Invoke(ReloadUsers, ReloadRoot); - var b = true; } private void ReloadConfiguration() @@ -234,5 +233,131 @@ namespace MediaBrowser.Controller item.Parent.Children = children.ToArray(); } } + + /// + /// Finds a library item by Id + /// + public BaseItem GetItemById(Guid id) + { + if (id == Guid.Empty) + { + return RootFolder; + } + + return RootFolder.FindById(id); + } + + /// + /// Determines if an item is allowed for a given user + /// + public bool IsParentalAllowed(BaseItem item, Guid userId) + { + // not yet implemented + return true; + } + + /// + /// Gets allowed children of an item + /// + public IEnumerable GetParentalAllowedChildren(Folder folder, Guid userId) + { + return folder.Children.ToList().Where(i => IsParentalAllowed(i, userId)); + } + + /// + /// Gets allowed recursive children of an item + /// + public IEnumerable GetParentalAllowedRecursiveChildren(Folder folder, Guid userId) + { + foreach (var item in GetParentalAllowedChildren(folder, userId)) + { + yield return item; + + var subFolder = item as Folder; + + if (subFolder != null) + { + foreach (var subitem in GetParentalAllowedRecursiveChildren(subFolder, userId)) + { + yield return subitem; + } + } + } + } + + /// + /// Gets user data for an item, if there is any + /// + public UserItemData GetUserItemData(Guid userId, Guid itemId) + { + User user = Users.First(u => u.Id == userId); + + if (user.ItemData.ContainsKey(itemId)) + { + return user.ItemData[itemId]; + } + + return null; + } + + /// + /// Gets all recently added items (recursive) within a folder, based on configuration and parental settings + /// + public IEnumerable GetRecentlyAddedItems(Folder parent, Guid userId) + { + DateTime now = DateTime.Now; + + return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => (now - i.DateCreated).TotalDays < Configuration.RecentItemDays); + } + + /// + /// Gets all recently added unplayed items (recursive) within a folder, based on configuration and parental settings + /// + public IEnumerable GetRecentlyAddedUnplayedItems(Folder parent, Guid userId) + { + return GetRecentlyAddedItems(parent, userId).Where(i => + { + var userdata = GetUserItemData(userId, i.Id); + + return userdata == null || userdata.PlayCount == 0; + }); + } + + /// + /// Gets all in-progress items (recursive) within a folder + /// + public IEnumerable GetInProgressItems(Folder parent, Guid userId) + { + return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => + { + var userdata = GetUserItemData(userId, i.Id); + + return userdata != null && userdata.PlaybackPosition.Ticks > 0; + }); + } + + /// + /// Finds all recursive items within a top-level parent that contain the given studio and are allowed for the current user + /// + public IEnumerable GetItemsWithStudio(Folder parent, string studio, Guid userId) + { + return GetParentalAllowedRecursiveChildren(parent, userId).Where(f => f.Studios != null && f.Studios.Any(s => s.Equals(studio, StringComparison.OrdinalIgnoreCase))); + } + + /// + /// Finds all recursive items within a top-level parent that contain the given genre and are allowed for the current user + /// + public IEnumerable GetItemsWithGenre(Folder parent, string genre, Guid userId) + { + return GetParentalAllowedRecursiveChildren(parent, userId).Where(f => f.Genres != null && f.Genres.Any(s => s.Equals(genre, StringComparison.OrdinalIgnoreCase))); + } + + /// + /// Finds all recursive items within a top-level parent that contain the given person and are allowed for the current user + /// + public IEnumerable GetItemsWithPerson(Folder parent, string personName, Guid userId) + { + return GetParentalAllowedRecursiveChildren(parent, userId).Where(f => f.People != null && f.People.Any(s => s.Name.Equals(personName, StringComparison.OrdinalIgnoreCase))); + } } } diff --git a/MediaBrowser.Controller/Library/ItemController.cs b/MediaBrowser.Controller/Library/ItemController.cs index f0be2baf9..b872e8dba 100644 --- a/MediaBrowser.Controller/Library/ItemController.cs +++ b/MediaBrowser.Controller/Library/ItemController.cs @@ -310,5 +310,23 @@ namespace MediaBrowser.Controller.Library return returnFiles; } + + public Person GetPerson(string name) + { + // not yet implemented + return null; + } + + public Studio GetStudio(string name) + { + // not yet implemented + return null; + } + + public Year GetYear(int value) + { + // not yet implemented + return null; + } } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index c89a32c26..719d279ee 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -63,7 +63,7 @@ MediaBrowser.Common - {9b1ddd79-5134-4df3-ace3-d1957a7350d8} + {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} MediaBrowser.Model -- cgit v1.2.3