aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Kernel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Controller/Kernel.cs')
-rw-r--r--MediaBrowser.Controller/Kernel.cs127
1 files changed, 126 insertions, 1 deletions
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();
}
}
+
+ /// <summary>
+ /// Finds a library item by Id
+ /// </summary>
+ public BaseItem GetItemById(Guid id)
+ {
+ if (id == Guid.Empty)
+ {
+ return RootFolder;
+ }
+
+ return RootFolder.FindById(id);
+ }
+
+ /// <summary>
+ /// Determines if an item is allowed for a given user
+ /// </summary>
+ public bool IsParentalAllowed(BaseItem item, Guid userId)
+ {
+ // not yet implemented
+ return true;
+ }
+
+ /// <summary>
+ /// Gets allowed children of an item
+ /// </summary>
+ public IEnumerable<BaseItem> GetParentalAllowedChildren(Folder folder, Guid userId)
+ {
+ return folder.Children.ToList().Where(i => IsParentalAllowed(i, userId));
+ }
+
+ /// <summary>
+ /// Gets allowed recursive children of an item
+ /// </summary>
+ public IEnumerable<BaseItem> 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;
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets user data for an item, if there is any
+ /// </summary>
+ 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;
+ }
+
+ /// <summary>
+ /// Gets all recently added items (recursive) within a folder, based on configuration and parental settings
+ /// </summary>
+ public IEnumerable<BaseItem> GetRecentlyAddedItems(Folder parent, Guid userId)
+ {
+ DateTime now = DateTime.Now;
+
+ return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => (now - i.DateCreated).TotalDays < Configuration.RecentItemDays);
+ }
+
+ /// <summary>
+ /// Gets all recently added unplayed items (recursive) within a folder, based on configuration and parental settings
+ /// </summary>
+ public IEnumerable<BaseItem> GetRecentlyAddedUnplayedItems(Folder parent, Guid userId)
+ {
+ return GetRecentlyAddedItems(parent, userId).Where(i =>
+ {
+ var userdata = GetUserItemData(userId, i.Id);
+
+ return userdata == null || userdata.PlayCount == 0;
+ });
+ }
+
+ /// <summary>
+ /// Gets all in-progress items (recursive) within a folder
+ /// </summary>
+ public IEnumerable<BaseItem> GetInProgressItems(Folder parent, Guid userId)
+ {
+ return GetParentalAllowedRecursiveChildren(parent, userId).Where(i =>
+ {
+ var userdata = GetUserItemData(userId, i.Id);
+
+ return userdata != null && userdata.PlaybackPosition.Ticks > 0;
+ });
+ }
+
+ /// <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(Folder parent, string studio, Guid userId)
+ {
+ return GetParentalAllowedRecursiveChildren(parent, userId).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 contain the given genre and are allowed for the current user
+ /// </summary>
+ public IEnumerable<BaseItem> 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)));
+ }
+
+ /// <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(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)));
+ }
}
}