From 4c9f77eead7148bb451de2a3f261bb3a61efe321 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Thu, 12 Jul 2012 13:09:35 -0400 Subject: [PATCH] Added some resolver improvements --- MediaBrowser.Controller/Kernel.cs | 3 -- .../Library/ItemDataCache.cs | 32 ------------------- .../MediaBrowser.Controller.csproj | 1 - .../Xml/BaseItemXmlParser.cs | 20 ++++++------ MediaBrowser.Model/Entities/BaseItem.cs | 3 +- MediaBrowser.Model/Entities/Person.cs | 15 +++++++-- .../Resolvers/MovieResolver.cs | 2 ++ MediaBrowser.TV/Resolvers/SeriesResolver.cs | 8 ++++- MediaBrowser.TV/TVUtils.cs | 21 +++++++++--- 9 files changed, 51 insertions(+), 54 deletions(-) delete mode 100644 MediaBrowser.Controller/Library/ItemDataCache.cs diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 2bb78e7e7..455a63f67 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -26,7 +26,6 @@ namespace MediaBrowser.Controller public string DataPath { get; private set; } public HttpServer HttpServer { get; private set; } - public ItemDataCache ItemDataCache { get; private set; } public ItemController ItemController { get; private set; } public UserController UserController { get; private set; } public PluginController PluginController { get; private set; } @@ -61,7 +60,6 @@ namespace MediaBrowser.Controller UserController = new UserController(Path.Combine(DataPath, "Users")); PluginController = new PluginController(Path.Combine(DataPath, "Plugins")); DirectoryWatchers = new DirectoryWatchers(); - ItemDataCache = new ItemDataCache(); ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath; ItemController.BeginResolvePath += ItemController_BeginResolvePath; @@ -86,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() diff --git a/MediaBrowser.Controller/Library/ItemDataCache.cs b/MediaBrowser.Controller/Library/ItemDataCache.cs deleted file mode 100644 index 35b3551a9..000000000 --- a/MediaBrowser.Controller/Library/ItemDataCache.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Controller.Library -{ - public class ItemDataCache - { - private Dictionary Data = new Dictionary(); - - public void SetValue(BaseItem item, string propertyName, T value) - { - Data[GetKey(item, propertyName)] = value; - } - - public T GetValue(BaseItem item, string propertyName) - { - string key = GetKey(item, propertyName); - - if (Data.ContainsKey(key)) - { - return (T)Data[key]; - } - - return default(T); - } - - private string GetKey(BaseItem item, string propertyName) - { - return item.Id.ToString() + "-" + propertyName; - } - } -} diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index a84fc8091..30b1070bc 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -51,7 +51,6 @@ - diff --git a/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs b/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs index 2addf6a1d..8948c979e 100644 --- a/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs @@ -146,16 +146,16 @@ namespace MediaBrowser.Controller.Xml case "Director": { - var list = (item.People ?? new Person[]{}).ToList(); - list.AddRange(GetSplitValues(node.InnerText, '|').Select(v => new Person() { Name = v, PersonType = PersonType.Director })); + var list = (item.People ?? new PersonInfo[]{}).ToList(); + list.AddRange(GetSplitValues(node.InnerText, '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Director })); item.People = list; break; } case "Writer": { - var list = (item.People ?? new Person[] { }).ToList(); - list.AddRange(GetSplitValues(node.InnerText, '|').Select(v => new Person() { Name = v, PersonType = PersonType.Writer })); + var list = (item.People ?? new PersonInfo[] { }).ToList(); + list.AddRange(GetSplitValues(node.InnerText, '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Writer })); item.People = list; break; @@ -164,8 +164,8 @@ namespace MediaBrowser.Controller.Xml case "Actors": case "GuestStars": { - var list = (item.People ?? new Person[] { }).ToList(); - list.AddRange(GetSplitValues(node.InnerText, '|').Select(v => new Person() { Name = v, PersonType = PersonType.Actor })); + var list = (item.People ?? new PersonInfo[] { }).ToList(); + list.AddRange(GetSplitValues(node.InnerText, '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Actor })); item.People = list; break; @@ -450,7 +450,7 @@ namespace MediaBrowser.Controller.Xml protected virtual void FetchDataFromPersonsNode(XmlNode node, T item) { - List list = (item.People ?? new Person[] { }).ToList(); + List list = (item.People ?? new PersonInfo[] { }).ToList(); foreach (XmlNode childNode in node.ChildNodes) { @@ -542,9 +542,9 @@ namespace MediaBrowser.Controller.Xml } } - private Person GetPersonFromXmlNode(XmlNode node) + private PersonInfo GetPersonFromXmlNode(XmlNode node) { - Person person = new Person(); + PersonInfo person = new PersonInfo(); foreach (XmlNode childNode in node.ChildNodes) { @@ -570,7 +570,7 @@ namespace MediaBrowser.Controller.Xml } case "Role": - person.Description = childNode.InnerText ?? string.Empty; + person.Overview = childNode.InnerText ?? string.Empty; break; default: diff --git a/MediaBrowser.Model/Entities/BaseItem.cs b/MediaBrowser.Model/Entities/BaseItem.cs index 2eaf375d9..6efdb4dee 100644 --- a/MediaBrowser.Model/Entities/BaseItem.cs +++ b/MediaBrowser.Model/Entities/BaseItem.cs @@ -38,7 +38,8 @@ namespace MediaBrowser.Model.Entities public string Overview { get; set; } public string Tagline { get; set; } - public IEnumerable People { get; set; } + [JsonIgnore] + public IEnumerable People { get; set; } public IEnumerable Studios { get; set; } diff --git a/MediaBrowser.Model/Entities/Person.cs b/MediaBrowser.Model/Entities/Person.cs index 320491d02..521adb50c 100644 --- a/MediaBrowser.Model/Entities/Person.cs +++ b/MediaBrowser.Model/Entities/Person.cs @@ -6,10 +6,21 @@ using System.Threading.Tasks; namespace MediaBrowser.Model.Entities { - public class Person + /// + /// This is the full Person object that can be retrieved with all of it's data. + /// + public class Person : BaseItem + { + public PersonType PersonType { get; set; } + } + + /// + /// This is the small Person stub that is attached to BaseItems + /// + public class PersonInfo { public string Name { get; set; } - public string Description { get; set; } + public string Overview { get; set; } public PersonType PersonType { get; set; } } diff --git a/MediaBrowser.Movies/Resolvers/MovieResolver.cs b/MediaBrowser.Movies/Resolvers/MovieResolver.cs index d2076851a..5cdd19959 100644 --- a/MediaBrowser.Movies/Resolvers/MovieResolver.cs +++ b/MediaBrowser.Movies/Resolvers/MovieResolver.cs @@ -23,6 +23,8 @@ namespace MediaBrowser.Movies.Resolvers { return GetMovie(args); } + + // There's no metadata or [tmdb in the path, now we will have to work some magic to see if this is a Movie } return null; diff --git a/MediaBrowser.TV/Resolvers/SeriesResolver.cs b/MediaBrowser.TV/Resolvers/SeriesResolver.cs index 68581eb0b..694a8576d 100644 --- a/MediaBrowser.TV/Resolvers/SeriesResolver.cs +++ b/MediaBrowser.TV/Resolvers/SeriesResolver.cs @@ -14,9 +14,15 @@ namespace MediaBrowser.TV.Resolvers { if (args.IsFolder) { + // Optimization to avoid running these tests against Seasons + if (args.Parent is Series) + { + return null; + } + var metadataFile = args.GetFileByName("series.xml"); - if (metadataFile.HasValue || Path.GetFileName(args.Path).IndexOf("[tvdbid=", StringComparison.OrdinalIgnoreCase) != -1) + if (metadataFile.HasValue || Path.GetFileName(args.Path).IndexOf("[tvdbid=", StringComparison.OrdinalIgnoreCase) != -1 || TVUtils.IsSeriesFolder(args.Path, args.FileSystemChildren)) { return new Series(); } diff --git a/MediaBrowser.TV/TVUtils.cs b/MediaBrowser.TV/TVUtils.cs index 8421ebc69..3e975a512 100644 --- a/MediaBrowser.TV/TVUtils.cs +++ b/MediaBrowser.TV/TVUtils.cs @@ -52,14 +52,27 @@ namespace MediaBrowser.TV return seasonPathExpressions.Any(r => r.IsMatch(path)); } - public static bool IsSeriesFolder(string path, IEnumerable files, IEnumerable folders) + public static bool IsSeriesFolder(string path, IEnumerable> fileSystemChildren) { - if (folders.Any(f => IsSeasonFolder(f))) + foreach (var child in fileSystemChildren) { - return true; + if (child.Value.HasFlag(FileAttributes.Directory)) + { + if (IsSeasonFolder(child.Key)) + { + return true; + } + } + else + { + if (!string.IsNullOrEmpty(EpisodeNumberFromFile(child.Key, false))) + { + return true; + } + } } - return files.Any(f => !string.IsNullOrEmpty(EpisodeNumberFromFile(f, false))); + return false; } public static bool IsEpisode(string fullPath)