Browse Source

Update IBN types to use providers

LukePulverenti Luke Pulverenti luke pulverenti 13 years ago
parent
commit
1187222842

+ 5 - 14
MediaBrowser.Controller/Library/ItemController.cs

@@ -295,21 +295,12 @@ namespace MediaBrowser.Controller.Library
             item.DateCreated = Directory.GetCreationTime(path);
             item.DateCreated = Directory.GetCreationTime(path);
             item.DateModified = Directory.GetLastAccessTime(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<string, FileAttributes>(f, File.GetAttributes(f)));
 
 
-            var b = false;
-
-            if (b)
-            {
-                await Kernel.Instance.ExecuteMetadataProviders(item, null);
-            }
+            await Kernel.Instance.ExecuteMetadataProviders(item, args);
 
 
             return item;
             return item;
         }
         }

+ 42 - 2
MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs

@@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Providers
     {
     {
         public override bool Supports(BaseEntity item)
         public override bool Supports(BaseEntity item)
         {
         {
-            return item is BaseItem;
+            return true;
         }
         }
         
         
         public override Task Fetch(BaseEntity item, ItemResolveEventArgs args)
         public override Task Fetch(BaseEntity item, ItemResolveEventArgs args)
@@ -23,11 +23,51 @@ namespace MediaBrowser.Controller.Providers
             {
             {
                 if (args.IsFolder)
                 if (args.IsFolder)
                 {
                 {
-                    PopulateImages(item as BaseItem, args);
+                    var baseItem = item as BaseItem;
+
+                    if (baseItem != null)
+                    {
+                        PopulateImages(baseItem, args);
+                    }
+                    else
+                    {
+                        PopulateImages(item, args);
+                    }
                 }
                 }
             });
             });
         }
         }
 
 
+        /// <summary>
+        /// Fills in image paths based on files win the folder
+        /// </summary>
+        private void PopulateImages(BaseEntity item, ItemResolveEventArgs args)
+        {
+            foreach (KeyValuePair<string, FileAttributes> 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;
+                }
+            }
+        }
+
         /// <summary>
         /// <summary>
         /// Fills in image paths based on files win the folder
         /// Fills in image paths based on files win the folder
         /// </summary>
         /// </summary>