Added a VirtualFolder entity, a resolver, and a CollectionType property.

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti 2012-08-18 15:38:27 -04:00
parent a201eb060b
commit a508a997d9
18 changed files with 128 additions and 19 deletions

View File

@ -97,7 +97,7 @@ namespace MediaBrowser.Api
dto.SpecialCounts = folder.GetSpecialCounts(user);
dto.IsRoot = folder.IsRoot;
dto.IsVirtualFolder = folder.IsVirtualFolder;
dto.IsVirtualFolder = folder is VirtualFolder;
}
return dto;

View File

@ -97,5 +97,32 @@ namespace MediaBrowser.Controller.Events
}
}
public VirtualFolder VirtualFolder
{
get
{
if (Parent != null)
{
return Parent.VirtualFolder;
}
return null;
}
}
public string VirtualFolderCollectionType
{
get
{
VirtualFolder vf = VirtualFolder;
if (vf == null)
{
return null;
}
return vf.CollectionType;
}
}
}
}

View File

@ -77,6 +77,7 @@ namespace MediaBrowser.Controller
// Add the internal resolvers
resolvers.Add(new VideoResolver());
resolvers.Add(new AudioResolver());
resolvers.Add(new VirtualFolderResolver());
resolvers.Add(new FolderResolver());
EntityResolvers = resolvers;

View File

@ -60,6 +60,7 @@
<Compile Include="Resolvers\BaseItemResolver.cs" />
<Compile Include="Resolvers\FolderResolver.cs" />
<Compile Include="Resolvers\VideoResolver.cs" />
<Compile Include="Resolvers\VirtualFolderResolver.cs" />
<Compile Include="Xml\BaseItemXmlParser.cs" />
<Compile Include="Xml\FolderXmlParser.cs" />
<Compile Include="Xml\XmlExtensions.cs" />

View File

@ -19,10 +19,10 @@ namespace MediaBrowser.Controller.Resolvers
}
}
public abstract class BaseFolderResolver<T> : BaseItemResolver<T>
where T : Folder, new ()
public abstract class BaseFolderResolver<TItemType> : BaseItemResolver<TItemType>
where TItemType : Folder, new()
{
protected override void SetItemValues(T item, ItemResolveEventArgs args)
protected override void SetItemValues(TItemType item, ItemResolveEventArgs args)
{
base.SetItemValues(item, args);
@ -32,7 +32,7 @@ namespace MediaBrowser.Controller.Resolvers
PopulateFolderMetadata(item, args);
}
private void PopulateFolderMetadata(Folder folder, ItemResolveEventArgs args)
private void PopulateFolderMetadata(TItemType folder, ItemResolveEventArgs args)
{
var metadataFile = args.GetFileByName("folder.xml");

View File

@ -0,0 +1,41 @@
using System.ComponentModel.Composition;
using System.IO;
using MediaBrowser.Controller.Events;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Resolvers
{
[Export(typeof(IBaseItemResolver))]
public class VirtualFolderResolver : BaseFolderResolver<VirtualFolder>
{
protected override VirtualFolder Resolve(ItemResolveEventArgs args)
{
if (args.IsFolder && args.Parent != null && args.Parent.IsRoot)
{
return new VirtualFolder();
}
return null;
}
protected override void SetItemValues(VirtualFolder item, ItemResolveEventArgs args)
{
// Set the name initially by stripping off the [CollectionType=...]
// The name can always be overridden later by folder.xml
string pathName = Path.GetFileNameWithoutExtension(args.Path);
string srch = "[collectiontype=";
int index = pathName.IndexOf(srch, System.StringComparison.OrdinalIgnoreCase);
if (index != -1)
{
item.Name = pathName.Substring(0, index).Trim();
item.CollectionType = pathName.Substring(index + srch.Length).TrimEnd(']');
}
base.SetItemValues(item, args);
}
}
}

View File

@ -3,7 +3,7 @@
namespace MediaBrowser.Controller.Xml
{
/// <summary>
/// Fetches metadata fro a folder.
/// Fetches metadata for a folder.
/// Since folder.xml contains no folder-specific values, no overrides are needed
/// </summary>
public class FolderXmlParser : BaseItemXmlParser<Folder>

View File

@ -6,6 +6,29 @@ namespace MediaBrowser.Model.Entities
{
public abstract class BaseItem : BaseEntity, IHasProviderIds
{
/// <summary>
/// Goes up the tree to find the virtual folder parent
/// </summary>
public VirtualFolder VirtualFolder
{
get
{
var vf = this as VirtualFolder;
if (vf != null)
{
return vf;
}
if (Parent != null)
{
return Parent.VirtualFolder;
}
return null;
}
}
public string SortName { get; set; }
/// <summary>

View File

@ -8,14 +8,6 @@ namespace MediaBrowser.Model.Entities
{
public bool IsRoot { get; set; }
public bool IsVirtualFolder
{
get
{
return Parent != null && Parent.IsRoot;
}
}
public BaseItem[] Children { get; set; }
/// <summary>

View File

@ -3,7 +3,7 @@
namespace MediaBrowser.Model.Entities
{
/// <summary>
/// Since BaseItem and DTOBaseItem both have ProviderIds, this interface helps avoid code repition using extension methods
/// Since BaseItem and DTOBaseItem both have ProviderIds, this interface helps avoid code repition by using extension methods
/// </summary>
public interface IHasProviderIds
{

View File

@ -2,7 +2,7 @@
namespace MediaBrowser.Model.Entities
{
/// <summary>
/// Since it can be slow to collect this data. This class helps provide a way to calculate them all at once.
/// Since it can be slow to collect this data, this class helps provide a way to calculate them all at once.
/// </summary>
public class ItemSpecialCounts
{

View File

@ -0,0 +1,8 @@

namespace MediaBrowser.Model.Entities
{
public class VirtualFolder : Folder
{
public string CollectionType { get; set; }
}
}

View File

@ -46,6 +46,7 @@
<Compile Include="Entities\Person.cs" />
<Compile Include="Entities\Studio.cs" />
<Compile Include="Entities\Video.cs" />
<Compile Include="Entities\VirtualFolder.cs" />
<Compile Include="Entities\Year.cs" />
<Compile Include="Plugins\BasePluginConfiguration.cs" />
<Compile Include="DTO\PluginInfo.cs" />

View File

@ -12,7 +12,7 @@ namespace MediaBrowser.Movies.Resolvers
{
protected override BoxSet Resolve(ItemResolveEventArgs args)
{
if (args.IsFolder)
if (args.IsFolder && (args.VirtualFolderCollectionType ?? string.Empty).Equals("Movies", StringComparison.OrdinalIgnoreCase))
{
if (Path.GetFileName(args.Path).IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1)
{

View File

@ -17,7 +17,7 @@ namespace MediaBrowser.Movies.Resolvers
{
protected override Movie Resolve(ItemResolveEventArgs args)
{
if (args.IsFolder)
if (args.IsFolder && (args.VirtualFolderCollectionType ?? string.Empty).Equals("Movies", StringComparison.OrdinalIgnoreCase))
{
// Optimization to avoid running these tests against VF's
if (args.Parent != null && args.Parent.IsRoot)

View File

@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Windows;
using MediaBrowser.Common.Logging;
using MediaBrowser.Controller;
using MediaBrowser.Model.Progress;
@ -26,11 +27,18 @@ namespace MediaBrowser.ServerApplication
try
{
DateTime now = DateTime.Now;
new Kernel().Init(progress);
double seconds = (DateTime.Now - now).TotalSeconds;
Logger.LogInfo("Kernel.Init completed in {0} seconds.", seconds);
}
catch (Exception ex)
{
MessageBox.Show("There was an error launching Media Browser Server: " + ex.Message);
Close();
}
finally
{

View File

@ -3,6 +3,7 @@ using System.IO;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.TV.Entities;
using MediaBrowser.TV.Metadata;
namespace MediaBrowser.TV.Resolvers
{

View File

@ -13,7 +13,7 @@ namespace MediaBrowser.TV.Resolvers
{
protected override Series Resolve(ItemResolveEventArgs args)
{
if (args.IsFolder)
if (args.IsFolder && (args.VirtualFolderCollectionType ?? string.Empty).Equals("TV", StringComparison.OrdinalIgnoreCase))
{
// Optimization to avoid running these tests against VF's
if (args.Parent != null && args.Parent.IsRoot)
@ -42,6 +42,12 @@ namespace MediaBrowser.TV.Resolvers
{
base.SetItemValues(item, args);
// Read data from series.xml, if it exists
PopulateFolderMetadata(item, args);
}
private void PopulateFolderMetadata(Series item, ItemResolveEventArgs args)
{
var metadataFile = args.GetFileByName("series.xml");
if (metadataFile.HasValue)