Update IBN types to use providers

pull/702/head
LukePulverenti Luke Pulverenti luke pulverenti 12 years ago
parent ab01b49f64
commit 1187222842

@ -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"))) ItemResolveEventArgs args = new ItemResolveEventArgs();
{ args.Path = path;
item.PrimaryImagePath = Path.Combine(path, "folder.jpg"); args.FileAttributes = File.GetAttributes(path);
} args.FileSystemChildren = Directory.GetFileSystemEntries(path, "*", SearchOption.TopDirectoryOnly).Select(f => new KeyValuePair<string, FileAttributes>(f, File.GetAttributes(f)));
else if (File.Exists(Path.Combine(path, "folder.png")))
{
item.PrimaryImagePath = Path.Combine(path, "folder.png");
}
var b = false; await Kernel.Instance.ExecuteMetadataProviders(item, args);
if (b)
{
await Kernel.Instance.ExecuteMetadataProviders(item, null);
}
return item; return item;
} }

@ -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>

Loading…
Cancel
Save