2012-08-27 12:18:59 +00:00
|
|
|
|
using System.ComponentModel.Composition;
|
2012-08-20 23:53:32 +00:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
2012-08-23 20:51:10 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2012-08-23 20:51:10 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
using MediaBrowser.Movies.Entities;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Movies.Resolvers
|
|
|
|
|
{
|
2012-07-26 02:33:11 +00:00
|
|
|
|
[Export(typeof(IBaseItemResolver))]
|
2012-07-12 06:55:27 +00:00
|
|
|
|
public class MovieResolver : BaseVideoResolver<Movie>
|
|
|
|
|
{
|
|
|
|
|
protected override Movie Resolve(ItemResolveEventArgs args)
|
|
|
|
|
{
|
2012-08-23 18:35:44 +00:00
|
|
|
|
// Must be a directory and under a 'Movies' VF
|
2012-08-27 12:18:59 +00:00
|
|
|
|
if (args.IsDirectory)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-08-27 12:18:59 +00:00
|
|
|
|
// If the parent is not a boxset, the only other allowed parent type is Folder
|
|
|
|
|
if (!(args.Parent is BoxSet))
|
|
|
|
|
{
|
|
|
|
|
if (args.Parent != null && args.Parent.GetType() != typeof(Folder))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-28 16:36:31 +00:00
|
|
|
|
// Optimization to avoid running all these tests against VF's
|
|
|
|
|
if (args.Parent != null && args.Parent.IsVirtualFolder)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 18:35:44 +00:00
|
|
|
|
// Return a movie if the video resolver finds something in the folder
|
|
|
|
|
return GetMovie(args);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 20:51:10 +00:00
|
|
|
|
protected override void SetInitialItemValues(Movie item, ItemResolveEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
base.SetInitialItemValues(item, args);
|
|
|
|
|
|
|
|
|
|
SetProviderIdFromPath(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetProviderIdFromPath(Movie item)
|
|
|
|
|
{
|
|
|
|
|
string srch = "[tmdbid=";
|
|
|
|
|
int index = item.Path.IndexOf(srch, System.StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
string id = item.Path.Substring(index + srch.Length);
|
|
|
|
|
|
|
|
|
|
id = id.Substring(0, id.IndexOf(']'));
|
|
|
|
|
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tmdb, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-12 06:55:27 +00:00
|
|
|
|
private Movie GetMovie(ItemResolveEventArgs args)
|
|
|
|
|
{
|
2012-08-23 18:35:44 +00:00
|
|
|
|
// Loop through each child file/folder and see if we find a video
|
2012-08-21 01:51:00 +00:00
|
|
|
|
for (var i = 0; i < args.FileSystemChildren.Length; i++)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
var child = args.FileSystemChildren[i];
|
|
|
|
|
|
2012-07-12 06:55:27 +00:00
|
|
|
|
ItemResolveEventArgs childArgs = new ItemResolveEventArgs()
|
|
|
|
|
{
|
2012-08-23 05:45:26 +00:00
|
|
|
|
FileInfo = child,
|
|
|
|
|
FileSystemChildren = new WIN32_FIND_DATA[] { },
|
|
|
|
|
Path = child.Path
|
2012-07-12 06:55:27 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var item = base.Resolve(childArgs);
|
|
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
|
|
|
|
return new Movie()
|
|
|
|
|
{
|
|
|
|
|
Path = item.Path,
|
|
|
|
|
VideoType = item.VideoType
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-13 03:50:50 +00:00
|
|
|
|
return null;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|