diff --git a/MediaBrowser.Controller/IO/FileData.cs b/MediaBrowser.Controller/IO/FileData.cs index 21d090a27..b9bc7ea75 100644 --- a/MediaBrowser.Controller/IO/FileData.cs +++ b/MediaBrowser.Controller/IO/FileData.cs @@ -121,6 +121,22 @@ namespace MediaBrowser.Controller.IO [DllImport("kernel32")] private static extern bool FindClose(IntPtr hFindFile); + + private const char SpaceChar = ' '; + private static char[] InvalidFileNameChars = Path.GetInvalidFileNameChars(); + + /// + /// Takes a filename and removes invalid characters + /// + public static string GetValidFilename(string filename) + { + foreach (char c in InvalidFileNameChars) + { + filename = filename.Replace(c, SpaceChar); + } + + return filename; + } } [StructLayout(LayoutKind.Sequential)] diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index ec7bf9c28..b80013206 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -15,6 +15,7 @@ using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Progress; +using MediaBrowser.Common.Logging; namespace MediaBrowser.Controller { @@ -286,7 +287,14 @@ namespace MediaBrowser.Controller continue; } - await provider.FetchAsync(item, args).ConfigureAwait(false); + try + { + await provider.FetchAsync(item, args).ConfigureAwait(false); + } + catch (Exception ex) + { + Logger.LogException(ex); + } } } diff --git a/MediaBrowser.Controller/Library/ItemController.cs b/MediaBrowser.Controller/Library/ItemController.cs index fdc2276d0..26468c656 100644 --- a/MediaBrowser.Controller/Library/ItemController.cs +++ b/MediaBrowser.Controller/Library/ItemController.cs @@ -204,9 +204,7 @@ namespace MediaBrowser.Controller.Library /// public Task GetPerson(string name) { - string path = Path.Combine(Kernel.Instance.ApplicationPaths.PeoplePath, name); - - return GetImagesByNameItem(path, name); + return GetImagesByNameItem(Kernel.Instance.ApplicationPaths.PeoplePath, name); } /// @@ -214,9 +212,7 @@ namespace MediaBrowser.Controller.Library /// public Task GetStudio(string name) { - string path = Path.Combine(Kernel.Instance.ApplicationPaths.StudioPath, name); - - return GetImagesByNameItem(path, name); + return GetImagesByNameItem(Kernel.Instance.ApplicationPaths.StudioPath, name); } /// @@ -224,9 +220,7 @@ namespace MediaBrowser.Controller.Library /// public Task GetGenre(string name) { - string path = Path.Combine(Kernel.Instance.ApplicationPaths.GenrePath, name); - - return GetImagesByNameItem(path, name); + return GetImagesByNameItem(Kernel.Instance.ApplicationPaths.GenrePath, name); } /// @@ -234,12 +228,10 @@ namespace MediaBrowser.Controller.Library /// public Task GetYear(int value) { - string path = Path.Combine(Kernel.Instance.ApplicationPaths.YearPath, value.ToString()); - - return GetImagesByNameItem(path, value.ToString()); + return GetImagesByNameItem(Kernel.Instance.ApplicationPaths.YearPath, value.ToString()); } - private ConcurrentDictionary ImagesByNameItemCache = new ConcurrentDictionary(); + private ConcurrentDictionary ImagesByNameItemCache = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); /// /// Generically retrieves an IBN item @@ -247,7 +239,9 @@ namespace MediaBrowser.Controller.Library private Task GetImagesByNameItem(string path, string name) where T : BaseEntity, new() { - string key = path.ToLower(); + name = FileData.GetValidFilename(name); + + string key = Path.Combine(path, name); // Look for it in the cache, if it's not there, create it if (!ImagesByNameItemCache.ContainsKey(key))