diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs | 261 |
1 files changed, 199 insertions, 62 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs index 1b4903641..8e2218b0a 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs @@ -1,10 +1,12 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; -using MediaBrowser.Naming.Audio; using MediaBrowser.Naming.Common; using MediaBrowser.Naming.Video; using System; +using System.IO; +using System.Linq; namespace MediaBrowser.Server.Implementations.Library.Resolvers { @@ -29,7 +31,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers /// <returns>`0.</returns> protected override T Resolve(ItemResolveArgs args) { - return ResolveVideo<T>(args); + return ResolveVideo<T>(args, false); } /// <summary> @@ -37,14 +39,93 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers /// </summary> /// <typeparam name="TVideoType">The type of the T video type.</typeparam> /// <param name="args">The args.</param> + /// <param name="parseName">if set to <c>true</c> [parse name].</param> /// <returns>``0.</returns> - protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args) + protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args, bool parseName) 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; + } + } + else if (IsDvdFile(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 (video != null) + { + video.Name = parseName ? + videoInfo.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) @@ -52,74 +133,24 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers return null; } - var isShortcut = string.Equals(videoInfo.Container, "strm", StringComparison.OrdinalIgnoreCase); - - if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub || isShortcut) + if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub) { - var type = string.Equals(videoInfo.Container, "iso", StringComparison.OrdinalIgnoreCase) || string.Equals(videoInfo.Container, "img", StringComparison.OrdinalIgnoreCase) ? - VideoType.Iso : - VideoType.VideoFile; - var path = args.Path; var video = new TVideoType { - VideoType = type, Path = path, IsInMixedFolder = true, - IsPlaceHolder = videoInfo.IsStub, - IsShortcut = isShortcut, - Name = videoInfo.Name, ProductionYear = videoInfo.Year }; - if (videoInfo.IsStub) - { - if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase)) - { - video.VideoType = VideoType.Dvd; - } - else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase)) - { - video.VideoType = VideoType.HdDvd; - } - else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase)) - { - video.VideoType = VideoType.BluRay; - } - } + SetVideoType(video, videoInfo); + + video.Name = parseName ? + videoInfo.Name : + Path.GetFileNameWithoutExtension(args.Path); - 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; } @@ -127,5 +158,111 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers return null; } + + protected void SetVideoType(Video video, VideoFileInfo videoInfo) + { + var extension = Path.GetExtension(video.Path); + video.VideoType = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || + string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ? + VideoType.Iso : + VideoType.VideoFile; + + video.IsShortcut = string.Equals(extension, ".strm", StringComparison.OrdinalIgnoreCase); + video.IsPlaceHolder = videoInfo.IsStub; + + if (videoInfo.IsStub) + { + if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase)) + { + video.VideoType = VideoType.Dvd; + } + else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase)) + { + video.VideoType = VideoType.HdDvd; + } + else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase)) + { + video.VideoType = VideoType.BluRay; + } + } + } + + protected void Set3DFormat(Video video, bool is3D, string format3D) + { + if (is3D) + { + if (string.Equals(format3D, "fsbs", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.FullSideBySide; + } + else if (string.Equals(format3D, "ftab", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.FullTopAndBottom; + } + else if (string.Equals(format3D, "hsbs", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfSideBySide; + } + else if (string.Equals(format3D, "htab", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfTopAndBottom; + } + else if (string.Equals(format3D, "sbs", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfSideBySide; + } + else if (string.Equals(format3D, "sbs3d", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfSideBySide; + } + else if (string.Equals(format3D, "tab", StringComparison.OrdinalIgnoreCase)) + { + video.Video3DFormat = Video3DFormat.HalfTopAndBottom; + } + } + } + + protected void Set3DFormat(Video video, VideoFileInfo videoInfo) + { + Set3DFormat(video, videoInfo.Is3D, videoInfo.Format3D); + } + + protected void Set3DFormat(Video video) + { + var resolver = new Format3DParser(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); + var result = resolver.Parse(video.Path); + + Set3DFormat(video, result.Is3D, result.Format3D); + } + + /// <summary> + /// Determines whether [is DVD directory] [the specified directory name]. + /// </summary> + /// <param name="directoryName">Name of the directory.</param> + /// <returns><c>true</c> if [is DVD directory] [the specified directory name]; otherwise, <c>false</c>.</returns> + protected bool IsDvdDirectory(string directoryName) + { + return string.Equals(directoryName, "video_ts", StringComparison.OrdinalIgnoreCase); + } + + /// <summary> + /// Determines whether [is DVD file] [the specified name]. + /// </summary> + /// <param name="name">The name.</param> + /// <returns><c>true</c> if [is DVD file] [the specified name]; otherwise, <c>false</c>.</returns> + protected bool IsDvdFile(string name) + { + return string.Equals(name, "video_ts.ifo", StringComparison.OrdinalIgnoreCase); + } + + /// <summary> + /// Determines whether [is blu ray directory] [the specified directory name]. + /// </summary> + /// <param name="directoryName">Name of the directory.</param> + /// <returns><c>true</c> if [is blu ray directory] [the specified directory name]; otherwise, <c>false</c>.</returns> + protected bool IsBluRayDirectory(string directoryName) + { + return string.Equals(directoryName, "bdmv", StringComparison.OrdinalIgnoreCase); + } } } |
