コード例 #1
0
ファイル: BaseVideoResolver.cs プロジェクト: ypid/jellyfin
        /// <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 virtual 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 VideoResolver(namingOptions);

            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.IsDirectory)
                    {
                        if (IsDvdDirectory(child.FullName, filename, args.DirectoryService))
                        {
                            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(child.FullName, filename, args.DirectoryService))
                        {
                            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.Resolve(args.Path, false, false);

                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);
        }
コード例 #2
0
ファイル: BaseVideoResolver.cs プロジェクト: weweyes/jellyfin
        protected virtual TVideoType ResolveVideo <TVideoType>(ItemResolveArgs args, bool parseName)
            where TVideoType : Video, new()
        {
            VideoFileInfo videoInfo = null;
            VideoType?    videoType = null;

            // If the path is a file check for a matching extensions
            if (args.IsDirectory)
            {
                // 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.IsDirectory)
                    {
                        if (IsDvdDirectory(child.FullName, filename, args.DirectoryService))
                        {
                            videoType = VideoType.Dvd;
                        }
                        else if (IsBluRayDirectory(filename))
                        {
                            videoType = VideoType.BluRay;
                        }
                    }
                    else if (IsDvdFile(filename))
                    {
                        videoType = VideoType.Dvd;
                    }

                    if (videoType == null)
                    {
                        continue;
                    }

                    videoInfo = VideoResolver.ResolveDirectory(args.Path, NamingOptions, parseName);
                    break;
                }
            }
            else
            {
                videoInfo = VideoResolver.Resolve(args.Path, false, NamingOptions, parseName);
            }

            if (videoInfo == null || (!videoInfo.IsStub && !VideoResolver.IsVideoFile(args.Path, NamingOptions)))
            {
                return(null);
            }

            var video = new TVideoType
            {
                Name           = videoInfo.Name,
                Path           = args.Path,
                ProductionYear = videoInfo.Year,
                ExtraType      = videoInfo.ExtraType
            };

            if (videoType.HasValue)
            {
                video.VideoType = videoType.Value;
            }
            else
            {
                SetVideoType(video, videoInfo);
            }

            Set3DFormat(video, videoInfo);

            return(video);
        }