Ejemplo n.º 1
0
        /// <summary>
        /// Resolves the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="isDirectory">if set to <c>true</c> [is folder].</param>
        /// <param name="parseName">Whether or not the name should be parsed for info</param>
        /// <returns>VideoFileInfo.</returns>
        /// <exception cref="ArgumentNullException"><c>path</c> is <c>null</c>.</exception>
        public VideoFileInfo Resolve(string path, bool isDirectory, bool parseName = true)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

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

            if (!isDirectory)
            {
                var extension = Path.GetExtension(path);

                // Check supported extensions
                if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
                {
                    var stubResult = StubResolver.ResolveFile(path, _options);

                    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).Parse(flags);

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

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

            int?year = null;

            if (parseName)
            {
                var cleanDateTimeResult = CleanDateTime(name);

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

                year = cleanDateTimeResult.Year;
            }

            return(new VideoFileInfo
            {
                Path = path,
                Container = container,
                IsStub = isStub,
                Name = name,
                Year = year,
                StubType = stubType,
                Is3D = format3DResult.Is3D,
                Format3D = format3DResult.Format3D,
                ExtraType = extraResult.ExtraType,
                IsDirectory = isDirectory,
                ExtraRule = extraResult.Rule
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolves the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="isDirectory">if set to <c>true</c> [is folder].</param>
        /// <param name="namingOptions">The naming options.</param>
        /// <param name="parseName">Whether or not the name should be parsed for info.</param>
        /// <returns>VideoFileInfo.</returns>
        /// <exception cref="ArgumentNullException"><c>path</c> is <c>null</c>.</exception>
        public static VideoFileInfo?Resolve(string?path, bool isDirectory, NamingOptions namingOptions, bool parseName = true)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            bool isStub = false;
            ReadOnlySpan <char> container = ReadOnlySpan <char> .Empty;
            string?stubType = null;

            if (!isDirectory)
            {
                var extension = Path.GetExtension(path.AsSpan());

                // Check supported extensions
                if (!namingOptions.VideoFileExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase))
                {
                    // It's not supported. Check stub extensions
                    if (!StubResolver.TryResolveFile(path, namingOptions, out stubType))
                    {
                        return(null);
                    }

                    isStub = true;
                }

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

            var format3DResult = Format3DParser.Parse(path, namingOptions);

            var extraResult = ExtraResolver.GetExtraInfo(path, namingOptions);

            var name = Path.GetFileNameWithoutExtension(path);

            int?year = null;

            if (parseName)
            {
                var cleanDateTimeResult = CleanDateTime(name, namingOptions);
                name = cleanDateTimeResult.Name;
                year = cleanDateTimeResult.Year;

                if (extraResult.ExtraType == null &&
                    TryCleanString(name, namingOptions, out var newName))
                {
                    name = newName;
                }
            }

            return(new VideoFileInfo(
                       path: path,
                       container: container.IsEmpty ? null : container.ToString(),
                       isStub: isStub,
                       name: name,
                       year: year,
                       stubType: stubType,
                       is3D: format3DResult.Is3D,
                       format3D: format3DResult.Format3D,
                       extraType: extraResult.ExtraType,
                       isDirectory: isDirectory,
                       extraRule: extraResult.Rule));
        }