Ejemplo n.º 1
0
        /// <summary>
        /// Resolves the video.
        /// </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, bool parseName)
            where TVideoType : Video, new()
        {
            var namingOptions = ((LibraryManager)LibraryManager).GetNamingOptions();

            // If the path is a file check for a matching extensions
            var parser = new Naming.Video.VideoResolver(namingOptions, 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 videoInfo = parser.ResolveFile(args.Path);

                if (videoInfo == null)
                {
                    return(null);
                }

                if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub)
                {
                    var path = args.Path;

                    var video = new TVideoType
                    {
                        Path            = path,
                        IsInMixedFolder = true,
                        ProductionYear  = videoInfo.Year
                    };

                    SetVideoType(video, videoInfo);

                    video.Name = parseName ?
                                 videoInfo.Name :
                                 Path.GetFileNameWithoutExtension(args.Path);

                    Set3DFormat(video, videoInfo);

                    return(video);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolves the video.
        /// </summary>
        /// <typeparam name="TVideoType">The type of the T video type.</typeparam>
        /// <param name="args">The args.</param>
        /// <returns>``0.</returns>
        protected TVideoType ResolveVideo <TVideoType>(ItemResolveArgs args)
            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());
                var videoInfo = parser.ResolveFile(args.Path);

                if (videoInfo == null)
                {
                    return(null);
                }

                var isShortcut = string.Equals(videoInfo.Container, "strm", StringComparison.OrdinalIgnoreCase);

                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.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;
                        }
                    }

                    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;
                        }
                    }

                    return(video);
                }
            }

            return(null);
        }