diff --git a/MediaBrowser.Controller/Library/ItemController.cs b/MediaBrowser.Controller/Library/ItemController.cs index bc5cea79b9..eb767d9a14 100644 --- a/MediaBrowser.Controller/Library/ItemController.cs +++ b/MediaBrowser.Controller/Library/ItemController.cs @@ -295,21 +295,12 @@ namespace MediaBrowser.Controller.Library item.DateCreated = Directory.GetCreationTime(path); item.DateModified = Directory.GetLastAccessTime(path); - if (File.Exists(Path.Combine(path, "folder.jpg"))) - { - item.PrimaryImagePath = Path.Combine(path, "folder.jpg"); - } - else if (File.Exists(Path.Combine(path, "folder.png"))) - { - item.PrimaryImagePath = Path.Combine(path, "folder.png"); - } + ItemResolveEventArgs args = new ItemResolveEventArgs(); + args.Path = path; + args.FileAttributes = File.GetAttributes(path); + args.FileSystemChildren = Directory.GetFileSystemEntries(path, "*", SearchOption.TopDirectoryOnly).Select(f => new KeyValuePair(f, File.GetAttributes(f))); - var b = false; - - if (b) - { - await Kernel.Instance.ExecuteMetadataProviders(item, null); - } + await Kernel.Instance.ExecuteMetadataProviders(item, args); return item; } diff --git a/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs b/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs index 5b086f795a..06b573ed0e 100644 --- a/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs +++ b/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs @@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Providers { public override bool Supports(BaseEntity item) { - return item is BaseItem; + return true; } public override Task Fetch(BaseEntity item, ItemResolveEventArgs args) @@ -23,11 +23,51 @@ namespace MediaBrowser.Controller.Providers { if (args.IsFolder) { - PopulateImages(item as BaseItem, args); + var baseItem = item as BaseItem; + + if (baseItem != null) + { + PopulateImages(baseItem, args); + } + else + { + PopulateImages(item, args); + } } }); } + /// + /// Fills in image paths based on files win the folder + /// + private void PopulateImages(BaseEntity item, ItemResolveEventArgs args) + { + foreach (KeyValuePair file in args.FileSystemChildren) + { + if (file.Value.HasFlag(FileAttributes.Directory)) + { + continue; + } + + string filePath = file.Key; + + string ext = Path.GetExtension(filePath); + + // Only support png and jpg files + if (!ext.EndsWith("png", StringComparison.OrdinalIgnoreCase) && !ext.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)) + { + continue; + } + + string name = Path.GetFileNameWithoutExtension(filePath); + + if (name.Equals("folder", StringComparison.OrdinalIgnoreCase)) + { + item.PrimaryImagePath = filePath; + } + } + } + /// /// Fills in image paths based on files win the folder ///