From ef039884427f1239fa2786d59dd17e80b7fbbf2d Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Thu, 23 Aug 2012 08:26:08 -0400 Subject: [PATCH] comments and don't run internet providers on startup --- .../Serialization/ProtobufSerializer.cs | 11 +++++------ MediaBrowser.Controller/Kernel.cs | 10 +++++----- MediaBrowser.Controller/Library/ItemController.cs | 10 +++++----- .../Providers/VideoInfoProvider.cs | 1 + MediaBrowser.TV/Providers/EpisodeProviderFromXml.cs | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/MediaBrowser.Common/Serialization/ProtobufSerializer.cs b/MediaBrowser.Common/Serialization/ProtobufSerializer.cs index 9737c9b59..701ef7029 100644 --- a/MediaBrowser.Common/Serialization/ProtobufSerializer.cs +++ b/MediaBrowser.Common/Serialization/ProtobufSerializer.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.IO; +using System.IO; namespace MediaBrowser.Common.Serialization { + /// + /// Protocol buffers is google's binary serialization format. This is a .NET implementation of it. + /// You have to tag your classes with some annoying attributes, but in return you get the fastest serialization around with the smallest possible output. + /// public static class ProtobufSerializer { public static void SerializeToStream(T obj, Stream stream) diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 356e9e1e2..fa650e53f 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -76,7 +76,7 @@ namespace MediaBrowser.Controller ReloadUsers(); progress.Report(new TaskProgress() { Description = "Loading Media Library", PercentComplete = 25 }); - await ReloadRoot().ConfigureAwait(false); + await ReloadRoot(allowInternetProviders: false).ConfigureAwait(false); progress.Report(new TaskProgress() { Description = "Loading Complete", PercentComplete = 100 }); } @@ -140,7 +140,7 @@ namespace MediaBrowser.Controller /// /// Reloads the root media folder /// - public async Task ReloadRoot() + public async Task ReloadRoot(bool allowInternetProviders = true) { if (!Directory.Exists(MediaRootFolderPath)) { @@ -149,7 +149,7 @@ namespace MediaBrowser.Controller DirectoryWatchers.Stop(); - RootFolder = await ItemController.GetItem(MediaRootFolderPath).ConfigureAwait(false) as Folder; + RootFolder = await ItemController.GetItem(MediaRootFolderPath, allowInternetProviders: allowInternetProviders).ConfigureAwait(false) as Folder; DirectoryWatchers.Start(); } @@ -226,7 +226,7 @@ namespace MediaBrowser.Controller /// /// Runs all metadata providers for an entity /// - internal async Task ExecuteMetadataProviders(BaseEntity item, ItemResolveEventArgs args) + internal async Task ExecuteMetadataProviders(BaseEntity item, ItemResolveEventArgs args, bool allowInternetProviders = true) { // Get all supported providers BaseMetadataProvider[] supportedProviders = Kernel.Instance.MetadataProviders.Where(i => i.Supports(item)).ToArray(); @@ -236,7 +236,7 @@ namespace MediaBrowser.Controller { var provider = supportedProviders[i]; - if (provider.RequiresInternet && !Configuration.EnableInternetProviders) + if (provider.RequiresInternet && (!Configuration.EnableInternetProviders || !allowInternetProviders)) { continue; } diff --git a/MediaBrowser.Controller/Library/ItemController.cs b/MediaBrowser.Controller/Library/ItemController.cs index 94fcf1f44..df7cf8810 100644 --- a/MediaBrowser.Controller/Library/ItemController.cs +++ b/MediaBrowser.Controller/Library/ItemController.cs @@ -67,7 +67,7 @@ namespace MediaBrowser.Controller.Library /// /// Resolves a path into a BaseItem /// - public async Task GetItem(string path, Folder parent = null, WIN32_FIND_DATA? fileInfo = null) + public async Task GetItem(string path, Folder parent = null, WIN32_FIND_DATA? fileInfo = null, bool allowInternetProviders = true) { ItemResolveEventArgs args = new ItemResolveEventArgs() { @@ -109,12 +109,12 @@ namespace MediaBrowser.Controller.Library if (item != null) { - await Kernel.Instance.ExecuteMetadataProviders(item, args).ConfigureAwait(false); + await Kernel.Instance.ExecuteMetadataProviders(item, args, allowInternetProviders: allowInternetProviders).ConfigureAwait(false); if (item.IsFolder) { // If it's a folder look for child entities - (item as Folder).Children = (await Task.WhenAll(GetChildren(item as Folder, fileSystemChildren)).ConfigureAwait(false)) + (item as Folder).Children = (await Task.WhenAll(GetChildren(item as Folder, fileSystemChildren, allowInternetProviders)).ConfigureAwait(false)) .Where(i => i != null).OrderBy(f => { return string.IsNullOrEmpty(f.SortName) ? f.Name : f.SortName; @@ -129,7 +129,7 @@ namespace MediaBrowser.Controller.Library /// /// Finds child BaseItems for a given Folder /// - private Task[] GetChildren(Folder folder, WIN32_FIND_DATA[] fileSystemChildren) + private Task[] GetChildren(Folder folder, WIN32_FIND_DATA[] fileSystemChildren, bool allowInternetProviders) { Task[] tasks = new Task[fileSystemChildren.Length]; @@ -137,7 +137,7 @@ namespace MediaBrowser.Controller.Library { var child = fileSystemChildren[i]; - tasks[i] = GetItem(child.Path, folder, child); + tasks[i] = GetItem(child.Path, folder, child, allowInternetProviders: allowInternetProviders); } return tasks; diff --git a/MediaBrowser.Controller/Providers/VideoInfoProvider.cs b/MediaBrowser.Controller/Providers/VideoInfoProvider.cs index a4059f9da..2f8175b7e 100644 --- a/MediaBrowser.Controller/Providers/VideoInfoProvider.cs +++ b/MediaBrowser.Controller/Providers/VideoInfoProvider.cs @@ -184,6 +184,7 @@ namespace MediaBrowser.Controller.Providers AudioInfoProvider.EnsureCacheSubFolders(Kernel.Instance.ApplicationPaths.FFProbeVideoCacheDirectory); + // This is an optimzation. Do this now so that it doesn't have to be done upon first serialization. ProtoBuf.Meta.RuntimeTypeModel.Default.Add(typeof(FFProbeResult), true); ProtoBuf.Meta.RuntimeTypeModel.Default.Add(typeof(MediaStream), true); ProtoBuf.Meta.RuntimeTypeModel.Default.Add(typeof(MediaFormat), true); diff --git a/MediaBrowser.TV/Providers/EpisodeProviderFromXml.cs b/MediaBrowser.TV/Providers/EpisodeProviderFromXml.cs index bab746e4b..3506e2a51 100644 --- a/MediaBrowser.TV/Providers/EpisodeProviderFromXml.cs +++ b/MediaBrowser.TV/Providers/EpisodeProviderFromXml.cs @@ -36,7 +36,7 @@ namespace MediaBrowser.TV.Providers return FetchMetadata(item as Episode, args.Parent as Season, metadataFile); } - private Task FetchMetadata(Episode item, Season season, string metadataFile) + private async Task FetchMetadata(Episode item, Season season, string metadataFile) { if (season == null) { @@ -44,18 +44,18 @@ namespace MediaBrowser.TV.Providers // Need to validate it the slow way if (!File.Exists(metadataFile)) { - return Task.FromResult(null); + await Task.FromResult(null).ConfigureAwait(false); } } else { if (!season.ContainsMetadataFile(metadataFile)) { - return Task.FromResult(null); + await Task.FromResult(null).ConfigureAwait(false); } } - return Task.Run(() => { new EpisodeXmlParser().Fetch(item, metadataFile); }); + await Task.Run(() => { new EpisodeXmlParser().Fetch(item, metadataFile); }).ConfigureAwait(false); } } }