Exemplo n.º 1
0
        /// <summary>
        /// Resolves the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="isFolder">if set to <c>true</c> [is folder].</param>
        /// <returns>VideoFileInfo.</returns>
        /// <exception cref="System.ArgumentNullException">path</exception>
        public VideoFileInfo Resolve(string path, bool isFolder)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            var    isStub    = false;
            string container = null;
            string stubType  = null;

            if (!isFolder)
            {
                var extension = Path.GetExtension(path) ?? string.Empty;
                // Check supported extensions
                if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
                {
                    var stubResult = new StubResolver(_options, _logger).ResolveFile(path);

                    isStub = stubResult.IsStub;

                    // It's not supported. Check stub extensions
                    if (!isStub)
                    {
                        return(null);
                    }

                    stubType = stubResult.StubType;
                }

                container = extension.TrimStart('.');
            }

            var flags          = new FlagParser(_options).GetFlags(path);
            var format3DResult = new Format3DParser(_options, _logger).Parse(flags);

            var extraResult = new ExtraResolver(_options, _logger, _regexProvider).GetExtraInfo(path);

            var name = !isFolder
                ? Path.GetFileNameWithoutExtension(path)
                : Path.GetFileName(path);

            var cleanDateTimeResult = CleanDateTime(name);

            if (string.IsNullOrWhiteSpace(extraResult.ExtraType))
            {
                name = cleanDateTimeResult.Name;
                name = CleanString(name).Name;
            }

            return(new VideoFileInfo
            {
                Path = path,
                Container = container,
                IsStub = isStub,
                Name = name,
                Year = cleanDateTimeResult.Year,
                StubType = stubType,
                Is3D = format3DResult.Is3D,
                Format3D = format3DResult.Format3D,
                ExtraType = extraResult.ExtraType,
                IsFolder = isFolder,
                ExtraRule = extraResult.Rule
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resolves the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="isFolder">if set to <c>true</c> [is folder].</param>
        /// <returns>VideoFileInfo.</returns>
        /// <exception cref="System.ArgumentNullException">path</exception>
        public VideoFileInfo Resolve(string path, bool isFolder)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            var isStub = false;
            string container = null;
            string stubType = null;

            if (!isFolder)
            {
                var extension = Path.GetExtension(path) ?? string.Empty;
                // Check supported extensions
                if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
                {
                    var stubResult = new StubResolver(_options, _logger).ResolveFile(path);

                    isStub = stubResult.IsStub;

                    // It's not supported. Check stub extensions
                    if (!isStub)
                    {
                        return null;
                    }

                    stubType = stubResult.StubType;
                }

                container = extension.TrimStart('.');
            }

            var flags = new FlagParser(_options).GetFlags(path);
            var format3DResult = new Format3DParser(_options, _logger).Parse(flags);

            var extraResult = new ExtraResolver(_options, _logger, _regexProvider).GetExtraInfo(path);

            var name = !isFolder
                ? Path.GetFileNameWithoutExtension(path)
                : Path.GetFileName(path);

            var cleanDateTimeResult = CleanDateTime(name);

            if (string.IsNullOrWhiteSpace(extraResult.ExtraType))
            {
                name = cleanDateTimeResult.Name;
                name = CleanString(name).Name;
            }

            return new VideoFileInfo
            {
                Path = path,
                Container = container,
                IsStub = isStub,
                Name = name,
                Year = cleanDateTimeResult.Year,
                StubType = stubType,
                Is3D = format3DResult.Is3D,
                Format3D = format3DResult.Format3D,
                ExtraType = extraResult.ExtraType,
                IsFolder = isFolder,
                ExtraRule = extraResult.Rule
            };
        }