jellyfin/MediaBrowser.Controller/Resolvers/Movies/MovieResolver.cs

109 lines
3.4 KiB
C#
Raw Normal View History

using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
2012-09-08 18:37:55 +00:00
using System.ComponentModel.Composition;
using System.Collections.Generic;
2012-07-12 06:55:27 +00:00
2012-09-08 18:37:55 +00:00
namespace MediaBrowser.Controller.Resolvers.Movies
2012-07-12 06:55:27 +00:00
{
[Export(typeof(IBaseItemResolver))]
2012-07-12 06:55:27 +00:00
public class MovieResolver : BaseVideoResolver<Movie>
{
protected override Movie Resolve(ItemResolveEventArgs args)
{
// 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;
}
}
// Optimization to avoid running all these tests against VF's
2012-08-28 18:16:35 +00:00
if (args.Parent != null && args.Parent.IsRoot)
{
return null;
}
// 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;
}
protected override void SetInitialItemValues(Movie item, ItemResolveEventArgs args)
{
base.SetInitialItemValues(item, args);
SetProviderIdFromPath(item);
}
private void SetProviderIdFromPath(Movie item)
{
2012-09-11 18:20:12 +00:00
const 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)
{
//first see if the discovery process has already determined we are a DVD or BD
if (args.IsDVDFolder)
{
return new Movie()
{
Path = args.Path,
2012-09-17 20:53:39 +00:00
VideoType = VideoType.Dvd
};
}
else if (args.IsBDFolder)
2012-07-12 06:55:27 +00:00
{
return new Movie()
{
Path = args.Path,
VideoType = VideoType.BluRay
};
}
// Loop through each child file/folder and see if we find a video
foreach (var child in args.FileSystemChildren)
{
2012-09-17 20:53:39 +00:00
var childArgs = new ItemResolveEventArgs
2012-07-12 06:55:27 +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)
{
2012-09-11 19:37:14 +00:00
return new Movie
2012-07-12 06:55:27 +00:00
{
Path = item.Path,
VideoType = item.VideoType
};
}
}
return null;
2012-07-12 06:55:27 +00:00
}
}
}