Ejemplo n.º 1
0
        /// <summary>
        /// Resolve information about episode from path.
        /// </summary>
        /// <param name="path">Path.</param>
        /// <param name="isDirectory">Is path for a directory or file.</param>
        /// <param name="isNamed">Do we want to use IsNamed expressions.</param>
        /// <param name="isOptimistic">Do we want to use Optimistic expressions.</param>
        /// <param name="supportsAbsoluteNumbers">Do we want to use expressions supporting absolute episode numbers.</param>
        /// <param name="fillExtendedInfo">Should we attempt to retrieve extended information.</param>
        /// <returns>Returns null or <see cref="EpisodeInfo"/> object if successful.</returns>
        public EpisodeInfo?Resolve(
            string path,
            bool isDirectory,
            bool?isNamed                 = null,
            bool?isOptimistic            = null,
            bool?supportsAbsoluteNumbers = null,
            bool fillExtendedInfo        = true)
        {
            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))
                {
                    // It's not supported. Check stub extensions
                    if (!StubResolver.TryResolveFile(path, _options, out stubType))
                    {
                        return(null);
                    }

                    isStub = true;
                }

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

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

            var parsingResult = new EpisodePathParser(_options)
                                .Parse(path, isDirectory, isNamed, isOptimistic, supportsAbsoluteNumbers, fillExtendedInfo);

            if (!parsingResult.Success && !isStub)
            {
                return(null);
            }

            return(new EpisodeInfo(path)
            {
                Container = container,
                IsStub = isStub,
                EndingEpisodeNumber = parsingResult.EndingEpisodeNumber,
                EpisodeNumber = parsingResult.EpisodeNumber,
                SeasonNumber = parsingResult.SeasonNumber,
                SeriesName = parsingResult.SeriesName,
                StubType = stubType,
                Is3D = format3DResult.Is3D,
                Format3D = format3DResult.Format3D,
                IsByDate = parsingResult.IsByDate,
                Day = parsingResult.Day,
                Month = parsingResult.Month,
                Year = parsingResult.Year
            });
        }
Ejemplo n.º 2
0
        public EpisodeInfo Resolve(string path, bool IsDirectory, bool?isNamed = null, bool?isOptimistic = null, bool?supportsAbsoluteNumbers = null, bool fillExtendedInfo = true)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

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

            if (!IsDirectory)
            {
                var extension = Path.GetExtension(path) ?? string.Empty;
                // Check supported extensions
                if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
                {
                    var stubResult = new StubResolver(_options).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).Parse(flags);

            var parsingResult = new EpisodePathParser(_options)
                                .Parse(path, IsDirectory, isNamed, isOptimistic, supportsAbsoluteNumbers, fillExtendedInfo);

            return(new EpisodeInfo
            {
                Path = path,
                Container = container,
                IsStub = isStub,
                EndingEpsiodeNumber = parsingResult.EndingEpsiodeNumber,
                EpisodeNumber = parsingResult.EpisodeNumber,
                SeasonNumber = parsingResult.SeasonNumber,
                SeriesName = parsingResult.SeriesName,
                StubType = stubType,
                Is3D = format3DResult.Is3D,
                Format3D = format3DResult.Format3D,
                IsByDate = parsingResult.IsByDate,
                Day = parsingResult.Day,
                Month = parsingResult.Month,
                Year = parsingResult.Year
            });
        }
Ejemplo n.º 3
0
        public EpisodeInfo Resolve(string path, bool IsDirectory, bool?isNamed = null, bool?isOptimistic = null, bool?supportsAbsoluteNumbers = null, bool fillExtendedInfo = true)
        {
            var parsingResult = new EpisodePathParser(_options)
                                .Parse(path, IsDirectory, isNamed, isOptimistic, supportsAbsoluteNumbers, fillExtendedInfo);

            return(new EpisodeInfo
            {
                Path = path,
                EndingEpsiodeNumber = parsingResult.EndingEpsiodeNumber,
                EpisodeNumber = parsingResult.EpisodeNumber,
                SeasonNumber = parsingResult.SeasonNumber,
                SeriesName = parsingResult.SeriesName,
                IsByDate = parsingResult.IsByDate,
                Day = parsingResult.Day,
                Month = parsingResult.Month,
                Year = parsingResult.Year
            });
        }
Ejemplo n.º 4
0
        public void ParseEpisodeWithoutSeason(string path, string name, int episode)
        {
            NamingOptions     o = new NamingOptions();
            EpisodePathParser p = new EpisodePathParser(o);
            var res             = p.Parse(path, true, null, null, true);

            Assert.True(res.Success);
            Assert.Equal(name, res.SeriesName);
            Assert.True(res.SeasonNumber == null);
            Assert.Equal(episode, res.EpisodeNumber);

            //testing other paths delimeter
            var res2 = p.Parse(path.Replace("/", "\\"), false, null, null, true);

            Assert.True(res2.Success);
            Assert.Equal(name, res2.SeriesName);
            Assert.True(res2.SeasonNumber == null);
            Assert.Equal(episode, res2.EpisodeNumber);
        }