From 56f6b0335ce40aeab275f1038b96a8ecc642f18f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 2 Dec 2014 22:13:03 -0500 Subject: updated nuget --- .../Library/Resolvers/BaseVideoResolver.cs | 160 ++++++++++++++++----- .../Library/Resolvers/LocalTrailerResolver.cs | 61 -------- .../Library/Resolvers/Movies/MovieResolver.cs | 101 +++++-------- .../Library/Resolvers/TV/EpisodeResolver.cs | 34 +---- .../Library/Resolvers/VideoResolver.cs | 6 + 5 files changed, 172 insertions(+), 190 deletions(-) delete mode 100644 MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs index 35519b9321..f8cd209a17 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Model.Entities; using MediaBrowser.Naming.Common; +using MediaBrowser.Naming.Video; using System; using System.IO; @@ -42,9 +43,75 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers where TVideoType : Video, new() { // If the path is a file check for a matching extensions - if (!args.IsDirectory) + var parser = new Naming.Video.VideoResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); + + if (args.IsDirectory) + { + TVideoType video = null; + VideoFileInfo videoInfo = null; + + // Loop through each child file/folder and see if we find a video + foreach (var child in args.FileSystemChildren) + { + var filename = child.Name; + + if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory) + { + if (IsDvdDirectory(filename)) + { + videoInfo = parser.ResolveDirectory(args.Path); + + if (videoInfo == null) + { + return null; + } + + video = new TVideoType + { + Path = args.Path, + VideoType = VideoType.Dvd, + ProductionYear = videoInfo.Year + }; + break; + } + if (IsBluRayDirectory(filename)) + { + videoInfo = parser.ResolveDirectory(args.Path); + + if (videoInfo == null) + { + return null; + } + + video = new TVideoType + { + Path = args.Path, + VideoType = VideoType.BluRay, + ProductionYear = videoInfo.Year + }; + break; + } + } + } + + if (video != null) + { + if (parseName) + { + video.Name = videoInfo.Name; + } + else + { + video.Name = Path.GetFileName(args.Path); + } + + Set3DFormat(video, videoInfo); + } + + return video; + } + else { - var parser = new Naming.Video.VideoResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); var videoInfo = parser.ResolveFile(args.Path); if (videoInfo == null) @@ -57,7 +124,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub || isShortcut) { var type = string.Equals(videoInfo.Container, "iso", StringComparison.OrdinalIgnoreCase) || string.Equals(videoInfo.Container, "img", StringComparison.OrdinalIgnoreCase) ? - VideoType.Iso : + VideoType.Iso : VideoType.VideoFile; var path = args.Path; @@ -97,37 +164,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers } } - if (videoInfo.Is3D) - { - if (string.Equals(videoInfo.Format3D, "fsbs", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.FullSideBySide; - } - else if (string.Equals(videoInfo.Format3D, "ftab", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.FullTopAndBottom; - } - else if (string.Equals(videoInfo.Format3D, "hsbs", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.HalfSideBySide; - } - else if (string.Equals(videoInfo.Format3D, "htab", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.HalfTopAndBottom; - } - else if (string.Equals(videoInfo.Format3D, "sbs", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.HalfSideBySide; - } - else if (string.Equals(videoInfo.Format3D, "sbs3d", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.HalfSideBySide; - } - else if (string.Equals(videoInfo.Format3D, "tab", StringComparison.OrdinalIgnoreCase)) - { - video.Video3DFormat = Video3DFormat.HalfTopAndBottom; - } - } + Set3DFormat(video, videoInfo); return video; } @@ -135,5 +172,60 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers return null; } + + private void Set3DFormat(Video video, VideoFileInfo videoInfo) + { + if (videoInfo.Is3D) + { + if (string.Equals(videoInfo.Format3D, "fsbs", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.FullSideBySide; + } + else if (string.Equals(videoInfo.Format3D, "ftab", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.FullTopAndBottom; + } + else if (string.Equals(videoInfo.Format3D, "hsbs", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfSideBySide; + } + else if (string.Equals(videoInfo.Format3D, "htab", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfTopAndBottom; + } + else if (string.Equals(videoInfo.Format3D, "sbs", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfSideBySide; + } + else if (string.Equals(videoInfo.Format3D, "sbs3d", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfSideBySide; + } + else if (string.Equals(videoInfo.Format3D, "tab", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfTopAndBottom; + } + } + } + + /// + /// Determines whether [is DVD directory] [the specified directory name]. + /// + /// Name of the directory. + /// true if [is DVD directory] [the specified directory name]; otherwise, false. + protected bool IsDvdDirectory(string directoryName) + { + return string.Equals(directoryName, "video_ts", StringComparison.OrdinalIgnoreCase); + } + + /// + /// Determines whether [is blu ray directory] [the specified directory name]. + /// + /// Name of the directory. + /// true if [is blu ray directory] [the specified directory name]; otherwise, false. + protected bool IsBluRayDirectory(string directoryName) + { + return string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase); + } } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs deleted file mode 100644 index dfeefb74fc..0000000000 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs +++ /dev/null @@ -1,61 +0,0 @@ -using MediaBrowser.Common.IO; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Resolvers; -using MediaBrowser.Model.Entities; -using System; -using System.IO; -using System.Linq; - -namespace MediaBrowser.Server.Implementations.Library.Resolvers -{ - /// - /// Class LocalTrailerResolver - /// - public class LocalTrailerResolver : BaseVideoResolver - { - private readonly IFileSystem _fileSystem; - - public LocalTrailerResolver(ILibraryManager libraryManager, IFileSystem fileSystem) : base(libraryManager) - { - _fileSystem = fileSystem; - } - - /// - /// Resolves the specified args. - /// - /// The args. - /// Trailer. - protected override Trailer Resolve(ItemResolveArgs args) - { - // Trailers are not Children, therefore this can never happen - if (args.Parent != null) - { - return null; - } - - // If the file is within a trailers folder, see if the VideoResolver returns something - if (!args.IsDirectory) - { - if (string.Equals(Path.GetFileName(Path.GetDirectoryName(args.Path)), BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase)) - { - return base.Resolve(args); - } - - // Support xbmc local trailer convention, but only when looking for local trailers (hence the parent == null check) - if (args.Parent == null) - { - var nameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(args.Path); - var suffix = BaseItem.ExtraSuffixes.First(i => i.Value == ExtraType.Trailer); - - if (nameWithoutExtension.EndsWith(suffix.Key, StringComparison.OrdinalIgnoreCase)) - { - return base.Resolve(args); - } - } - } - - return null; - } - } -} diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index c928c5e656..6d396ad9cc 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.IO; +using MediaBrowser.Common.IO; using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; @@ -64,44 +63,44 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies } } - var isDirectory = args.IsDirectory; - - if (isDirectory) - { - // Since the looping is expensive, this is an optimization to help us avoid it - if (args.ContainsMetaFileByName("series.xml")) - { - return null; - } - } - var collectionType = args.GetCollectionType(); // Find movies with their own folders - if (isDirectory) + if (args.IsDirectory) { - if (string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase)) - { - return FindMovie(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false, collectionType); - } - if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false, collectionType); + return FindMovie(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, collectionType); } if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie