From c5b00dec8ec326bbb17cf122263b78851ce398dd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 16 Jun 2013 15:02:57 -0400 Subject: Added multi-disc movie support --- .../Library/Resolvers/Movies/MovieResolver.cs | 127 ++++++++++++++------- 1 file changed, 88 insertions(+), 39 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library') diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 136e83aa0..dbcafcbff 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -50,24 +50,21 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies if (args.IsDirectory) { // Avoid expensive tests against VF's and all their children by not allowing this - if (args.Parent == null || args.Parent.IsRoot) + if (args.Parent != null) { - return null; - } - - // If the parent is not a boxset, the only other allowed parent type is Folder - if (!(args.Parent is BoxSet)) - { - if (args.Parent.GetType() != typeof(Folder)) + if (args.Parent.IsRoot) { return null; } - } - // Optimization to avoid running all these tests against Top folders - if (args.Parent != null && args.Parent.IsRoot) - { - return null; + // If the parent is not a boxset, the only other allowed parent type is Folder + if (!(args.Parent is BoxSet)) + { + if (args.Parent.GetType() != typeof(Folder)) + { + return null; + } + } } // Since the looping is expensive, this is an optimization to help us avoid it @@ -76,16 +73,20 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies return null; } + // A shortcut to help us resolve faster in some cases + var isKnownMovie = args.ContainsMetaFileByName("movie.xml") || args.ContainsMetaFileByName("tmdb3.json") || + args.Path.IndexOf("[tmdbid", StringComparison.OrdinalIgnoreCase) != -1; + if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1) { - return FindMovie(args); + return FindMovie(args.Path, args.FileSystemChildren, isKnownMovie); } if (args.Path.IndexOf("[musicvideos]", StringComparison.OrdinalIgnoreCase) != -1) { - return FindMovie(args); + return FindMovie(args.Path, args.FileSystemChildren, isKnownMovie); } - return FindMovie(args); + return FindMovie(args.Path, args.FileSystemChildren, isKnownMovie); } return null; @@ -123,18 +124,20 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies /// /// Finds a movie based on a child file system entries /// - /// The args. + /// + /// The path. + /// The file system entries. + /// if set to true [is known movie]. /// Movie. - private T FindMovie(ItemResolveArgs args) - where T : Video, new () + private T FindMovie(string path, IEnumerable fileSystemEntries, bool isKnownMovie) + where T : Video, new() { - // Optimization to avoid having to resolve every file - bool? isKnownMovie = null; - var movies = new List(); + var multiDiscFolders = new List(); + // Loop through each child file/folder and see if we find a video - foreach (var child in args.FileSystemChildren) + foreach (var child in fileSystemEntries) { if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { @@ -142,7 +145,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { return new T { - Path = args.Path, + Path = path, VideoType = VideoType.Dvd }; } @@ -150,17 +153,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { return new T { - Path = args.Path, + Path = path, VideoType = VideoType.BluRay }; } - if (IsHdDvdDirectory(child.Name)) + + if (EntityResolutionHelper.IsMultiPartFile(child.Name)) { - return new T - { - Path = args.Path, - VideoType = VideoType.HdDvd - }; + multiDiscFolders.Add(child); } continue; @@ -183,12 +183,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies if (item != null) { // If we already know it's a movie, we can stop looping - if (!isKnownMovie.HasValue) - { - isKnownMovie = args.ContainsMetaFileByName("movie.xml") || args.ContainsMetaFileByName("tmdb3.json") || args.Path.IndexOf("[tmdbid", StringComparison.OrdinalIgnoreCase) != -1; - } - - if (isKnownMovie.Value) + if (isKnownMovie) { return item; } @@ -202,9 +197,63 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies return GetMultiFileMovie(movies); } - return movies.Count == 1 ? movies[0] : null; + if (movies.Count == 1) + { + return movies[0]; + } + + if (multiDiscFolders.Count > 0) + { + return GetMultiDiscMovie(multiDiscFolders); + } + + return null; } + /// + /// Gets the multi disc movie. + /// + /// + /// The folders. + /// ``0. + private T GetMultiDiscMovie(List folders) + where T : Video, new() + { + var videoType = VideoType.BluRay; + + folders = folders.Where(i => + { + var subfolders = Directory.GetDirectories(i.FullName).Select(Path.GetFileName).ToList(); + + if (subfolders.Any(IsDvdDirectory)) + { + videoType = VideoType.Dvd; + return true; + } + if (subfolders.Any(IsBluRayDirectory)) + { + videoType = VideoType.BluRay; + return true; + } + + return false; + + }).OrderBy(i => i.FullName).ToList(); + + if (folders.Count == 0) + { + return null; + } + + return new T + { + Path = folders[0].FullName, + + IsMultiPart = true, + + VideoType = videoType + }; + } /// /// Gets the multi file movie. @@ -216,7 +265,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies where T : Video, new() { var multiPartMovies = movies.OrderBy(i => i.Path) - .Where(i => EntityResolutionHelper.IsMultiPartFile(i.Path)) + .Where(i => EntityResolutionHelper.IsMultiPartFile(i.Name)) .ToList(); // They must all be part of the sequence -- cgit v1.2.3