2012-07-12 06:55:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2012-07-26 02:33:11 +00:00
|
|
|
|
using System.ComponentModel.Composition;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
using MediaBrowser.Controller.Events;
|
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
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-18 19:38:27 +00:00
|
|
|
|
if (args.IsFolder && (args.VirtualFolderCollectionType ?? string.Empty).Equals("Movies", StringComparison.OrdinalIgnoreCase))
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-13 03:50:50 +00:00
|
|
|
|
// Optimization to avoid running these tests against VF's
|
|
|
|
|
if (args.Parent != null && args.Parent.IsRoot)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-12 06:55:27 +00:00
|
|
|
|
var metadataFile = args.GetFileByName("movie.xml");
|
|
|
|
|
|
|
|
|
|
if (metadataFile.HasValue || Path.GetFileName(args.Path).IndexOf("[tmdbid=", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
|
{
|
2012-07-13 03:50:50 +00:00
|
|
|
|
return GetMovie(args) ?? new Movie();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If it's 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-07-12 06:55:27 +00:00
|
|
|
|
}
|
2012-07-12 17:09:35 +00:00
|
|
|
|
|
|
|
|
|
// There's no metadata or [tmdb in the path, now we will have to work some magic to see if this is a Movie
|
2012-07-13 03:50:50 +00:00
|
|
|
|
if (args.Parent != null)
|
|
|
|
|
{
|
|
|
|
|
return GetMovie(args);
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Movie GetMovie(ItemResolveEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
foreach (var child in args.FileSystemChildren)
|
|
|
|
|
{
|
|
|
|
|
ItemResolveEventArgs childArgs = new ItemResolveEventArgs()
|
|
|
|
|
{
|
|
|
|
|
Path = child.Key,
|
|
|
|
|
FileAttributes = child.Value,
|
|
|
|
|
FileSystemChildren = new KeyValuePair<string, FileAttributes>[] { }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PopulateBonusFeatures(Movie item, ItemResolveEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var trailerPath = args.GetFolderByName("specials");
|
|
|
|
|
|
|
|
|
|
if (trailerPath.HasValue)
|
|
|
|
|
{
|
|
|
|
|
string[] allFiles = Directory.GetFileSystemEntries(trailerPath.Value.Key, "*", SearchOption.TopDirectoryOnly);
|
|
|
|
|
|
2012-08-19 15:58:35 +00:00
|
|
|
|
item.SpecialFeatures = allFiles.Select(f => Kernel.Instance.ItemController.GetItem(null, f)).OfType<Video>();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 20:38:31 +00:00
|
|
|
|
protected override void SetInitialItemValues(Movie item, ItemResolveEventArgs args)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-08-19 20:38:31 +00:00
|
|
|
|
base.SetInitialItemValues(item, args);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
PopulateBonusFeatures(item, args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|