From 0f078d8098e60804c4f9b13c82566286362a83f2 Mon Sep 17 00:00:00 2001 From: ebr11 Eric Reed spam Date: Tue, 18 Sep 2012 15:18:15 -0400 Subject: [PATCH] Move NeedsRefresh to async task and fix problem finding episode metadata --- .../Extensions/BaseExtensions.cs | 21 +++++++++++++++++++ MediaBrowser.Controller/Entities/Folder.cs | 3 ++- MediaBrowser.Controller/Kernel.cs | 13 ++++++------ .../Providers/BaseItemXmlParser.cs | 1 + .../Providers/BaseMetadataProvider.cs | 14 ++++++++++--- .../Resolvers/EntityResolutionHelper.cs | 6 +++++- 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/MediaBrowser.Common/Extensions/BaseExtensions.cs b/MediaBrowser.Common/Extensions/BaseExtensions.cs index ceb008629c..10ff019aa4 100644 --- a/MediaBrowser.Common/Extensions/BaseExtensions.cs +++ b/MediaBrowser.Common/Extensions/BaseExtensions.cs @@ -36,5 +36,26 @@ namespace MediaBrowser.Common.Extensions } return false; } + + /// + /// Helper method for Dictionaries since they throw on not-found keys + /// + /// + /// + /// + /// + /// + /// + public static U GetValueOrDefault(this Dictionary dictionary, T key, U defaultValue) + { + U val; + if (!dictionary.TryGetValue(key, out val)) + { + val = defaultValue; + } + return val; + + } + } } diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 1cad13f22e..249921f0fd 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -153,9 +153,9 @@ namespace MediaBrowser.Controller.Entities //brand new item - needs to be added changed = true; changedArgs.ItemsAdded.Add(child); - //Logger.LogInfo("New Item Added to Library: ("+child.GetType().Name+")"+ child.Name + "(" + child.Path + ")"); //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 @@ -180,6 +180,7 @@ namespace MediaBrowser.Controller.Entities // 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); } diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 6baae88113..1daa43dcd2 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -198,8 +198,13 @@ namespace MediaBrowser.Controller //re-start the directory watchers DirectoryWatchers.Stop(); DirectoryWatchers.Start(); + //Task.Delay(30000); //let's wait and see if more data gets filled in... var allChildren = RootFolder.RecursiveChildren; Logger.LogInfo(string.Format("Loading complete. Movies: {0} Episodes: {1}", allChildren.OfType().Count(), allChildren.OfType().Count())); + foreach (var child in allChildren) + { + Logger.LogDebugInfo("(" + child.GetType().Name + ") " + child.Name + " Overview " + (child.Overview != null ? child.Overview.Substring(0,Math.Min(25,child.Overview.Length)): "") + " (" + child.Path + ")"); + } } /// @@ -368,15 +373,9 @@ namespace MediaBrowser.Controller continue; } - // Skip if provider says we don't need to run - if (!provider.NeedsRefresh(item)) - { - continue; - } - try { - await provider.FetchAsync(item, item.ResolveArgs).ConfigureAwait(false); + await provider.FetchIfNeededAsync(item).ConfigureAwait(false); } catch (Exception ex) { diff --git a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs index 1cb2e2af34..45343b0511 100644 --- a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Xml; using MediaBrowser.Model.Entities; +using MediaBrowser.Common.Logging; using System; using System.Collections.Generic; using System.Linq; diff --git a/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs b/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs index 80a264af27..50004be442 100644 --- a/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs +++ b/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs @@ -36,7 +36,7 @@ namespace MediaBrowser.Controller.Providers /// protected virtual DateTime LastRefreshed(BaseEntity item) { - return (item.ProviderData[this.Id] ?? new BaseProviderInfo()).LastRefreshed; + return (item.ProviderData.GetValueOrDefault(this.Id, new BaseProviderInfo())).LastRefreshed; } /// @@ -46,7 +46,7 @@ namespace MediaBrowser.Controller.Providers /// protected virtual void SetLastRefreshed(BaseEntity item, DateTime value) { - var data = item.ProviderData[this.Id] ?? new BaseProviderInfo(); + var data = item.ProviderData.GetValueOrDefault(this.Id, new BaseProviderInfo()); data.LastRefreshed = value; item.ProviderData[this.Id] = data; } @@ -68,7 +68,15 @@ namespace MediaBrowser.Controller.Providers /// protected virtual DateTime CompareDate(BaseEntity item) { - return DateTime.MinValue; + return DateTime.MinValue.AddMinutes(1); // want this to be greater than mindate so new items will refresh + } + + public virtual Task FetchIfNeededAsync(BaseEntity item) + { + if (this.NeedsRefresh(item)) + return FetchAsync(item, item.ResolveArgs); + else + return new Task(() => { }); } public abstract Task FetchAsync(BaseEntity item, ItemResolveEventArgs args); diff --git a/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs index 76541e0efe..ab2f07ecfd 100644 --- a/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs +++ b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs @@ -18,7 +18,6 @@ namespace MediaBrowser.Controller.Resolvers public static List IgnoreFolders = new List() { "trailers", - "metadata", "bdmv", "certificate", "backup", @@ -61,6 +60,11 @@ namespace MediaBrowser.Controller.Resolvers // Ignore any folders containing a file called .ignore resolve = false; } + else if (args.FileInfo.cFileName.Equals("metadata", StringComparison.OrdinalIgnoreCase)) + { + // Ignore metadata folders + resolve = false; + } return resolve; }