From 80b3ad7bd20329e6a5bbf6eeb76af62c87434a7c Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Thu, 19 Jul 2012 22:22:44 -0400 Subject: Moved the http server to it's own assembly. added comments and made other minor re-organizations. --- MediaBrowser.Controller/Kernel.cs | 126 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 121 insertions(+), 5 deletions(-) (limited to 'MediaBrowser.Controller/Kernel.cs') diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 3f6e7bbb0..9cbef6874 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -7,7 +7,6 @@ using System.Text; using System.Threading.Tasks; using MediaBrowser.Common.Json; using MediaBrowser.Common.Logging; -using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; using MediaBrowser.Controller.Events; using MediaBrowser.Controller.IO; @@ -16,6 +15,7 @@ using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Users; +using MediaBrowser.Net; namespace MediaBrowser.Controller { @@ -79,7 +79,7 @@ namespace MediaBrowser.Controller ReloadHttpServer(); - ReloadPlugins(); + LoadPlugins(); // Get users from users folder // Load root media folder @@ -94,7 +94,7 @@ namespace MediaBrowser.Controller Logger.LoggerInstance.LogSeverity = Configuration.LogSeverity; } - private void ReloadPlugins() + private void LoadPlugins() { // Find plugins Plugins = PluginController.GetAllPlugins(); @@ -261,7 +261,7 @@ namespace MediaBrowser.Controller /// public IEnumerable GetParentalAllowedChildren(Folder folder, Guid userId) { - return folder.Children.ToList().Where(i => IsParentalAllowed(i, userId)); + return folder.Children.Where(i => IsParentalAllowed(i, userId)); } /// @@ -307,7 +307,7 @@ namespace MediaBrowser.Controller { DateTime now = DateTime.Now; - return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => (now - i.DateCreated).TotalDays < Configuration.RecentItemDays); + return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => !(i is Folder) && (now - i.DateCreated).TotalDays < Configuration.RecentItemDays); } /// @@ -330,6 +330,11 @@ namespace MediaBrowser.Controller { return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => { + if (i is Folder) + { + return false; + } + var userdata = GetUserItemData(userId, i.Id); return userdata != null && userdata.PlaybackPosition.Ticks > 0; @@ -359,5 +364,116 @@ namespace MediaBrowser.Controller { return GetParentalAllowedRecursiveChildren(parent, userId).Where(f => f.People != null && f.People.Any(s => s.Name.Equals(personName, StringComparison.OrdinalIgnoreCase))); } + + /// + /// Gets all studios from all recursive children of a folder + /// The CategoryInfo class is used to keep track of the number of times each studio appears + /// + public IEnumerable GetAllStudios(Folder parent, Guid userId) + { + Dictionary data = new Dictionary(); + + // Get all the allowed recursive children + IEnumerable allItems = Kernel.Instance.GetParentalAllowedRecursiveChildren(parent, userId); + + foreach (var item in allItems) + { + // Add each studio from the item to the data dictionary + // If the studio already exists, increment the count + if (item.Studios == null) + { + continue; + } + + foreach (string val in item.Studios) + { + if (!data.ContainsKey(val)) + { + data.Add(val, 1); + } + else + { + data[val]++; + } + } + } + + // Now go through the dictionary and create a Category for each studio + List list = new List(); + + foreach (string key in data.Keys) + { + // Get the original entity so that we can also supply the PrimaryImagePath + Studio entity = Kernel.Instance.ItemController.GetStudio(key); + + if (entity != null) + { + list.Add(new CategoryInfo() + { + Name = entity.Name, + ItemCount = data[key], + PrimaryImagePath = entity.PrimaryImagePath + }); + } + } + + return list; + } + + /// + /// Gets all genres from all recursive children of a folder + /// The CategoryInfo class is used to keep track of the number of times each genres appears + /// + public IEnumerable GetAllGenres(Folder parent, Guid userId) + { + Dictionary data = new Dictionary(); + + // Get all the allowed recursive children + IEnumerable allItems = Kernel.Instance.GetParentalAllowedRecursiveChildren(parent, userId); + + foreach (var item in allItems) + { + // Add each genre from the item to the data dictionary + // If the genre already exists, increment the count + if (item.Genres == null) + { + continue; + } + + foreach (string val in item.Genres) + { + if (!data.ContainsKey(val)) + { + data.Add(val, 1); + } + else + { + data[val]++; + } + } + } + + // Now go through the dictionary and create a Category for each genre + List list = new List(); + + foreach (string key in data.Keys) + { + // Get the original entity so that we can also supply the PrimaryImagePath + Genre entity = Kernel.Instance.ItemController.GetGenre(key); + + if (entity != null) + { + list.Add(new CategoryInfo() + { + Name = entity.Name, + ItemCount = data[key], + PrimaryImagePath = entity.PrimaryImagePath + }); + } + } + + return list; + } + } } -- cgit v1.2.3