< Summary - Jellyfin

Information
Class: Emby.Naming.TV.EpisodeResolver
Assembly: Emby.Naming
File(s): /srv/git/jellyfin/Emby.Naming/TV/EpisodeResolver.cs
Line coverage
96%
Covered lines: 32
Uncovered lines: 1
Coverable lines: 33
Total lines: 93
Line coverage: 96.9%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Resolve(...)90%101096.77%

File(s)

/srv/git/jellyfin/Emby.Naming/TV/EpisodeResolver.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using Emby.Naming.Common;
 4using Emby.Naming.Video;
 5using Jellyfin.Extensions;
 6
 7namespace Emby.Naming.TV
 8{
 9    /// <summary>
 10    /// Used to resolve information about episode from path.
 11    /// </summary>
 12    public class EpisodeResolver
 13    {
 14        private readonly NamingOptions _options;
 15
 16        /// <summary>
 17        /// Initializes a new instance of the <see cref="EpisodeResolver"/> class.
 18        /// </summary>
 19        /// <param name="options"><see cref="NamingOptions"/> object containing VideoFileExtensions and passed to <see c
 20        public EpisodeResolver(NamingOptions options)
 21        {
 8422            _options = options;
 8423        }
 24
 25        /// <summary>
 26        /// Resolve information about episode from path.
 27        /// </summary>
 28        /// <param name="path">Path.</param>
 29        /// <param name="isDirectory">Is path for a directory or file.</param>
 30        /// <param name="isNamed">Do we want to use IsNamed expressions.</param>
 31        /// <param name="isOptimistic">Do we want to use Optimistic expressions.</param>
 32        /// <param name="supportsAbsoluteNumbers">Do we want to use expressions supporting absolute episode numbers.</pa
 33        /// <param name="fillExtendedInfo">Should we attempt to retrieve extended information.</param>
 34        /// <returns>Returns null or <see cref="EpisodeInfo"/> object if successful.</returns>
 35        public EpisodeInfo? Resolve(
 36            string path,
 37            bool isDirectory,
 38            bool? isNamed = null,
 39            bool? isOptimistic = null,
 40            bool? supportsAbsoluteNumbers = null,
 41            bool fillExtendedInfo = true)
 42        {
 8443            bool isStub = false;
 8444            string? container = null;
 8445            string? stubType = null;
 46
 8447            if (!isDirectory)
 48            {
 8449                var extension = Path.GetExtension(path);
 50                // Check supported extensions
 8451                if (!_options.VideoFileExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase))
 52                {
 53                    // It's not supported. Check stub extensions
 254                    if (!StubResolver.TryResolveFile(path, _options, out stubType))
 55                    {
 156                        return null;
 57                    }
 58
 159                    isStub = true;
 60                }
 61
 8362                container = extension.TrimStart('.');
 63            }
 64
 8365            var format3DResult = Format3DParser.Parse(path, _options);
 66
 8367            var parsingResult = new EpisodePathParser(_options)
 8368                .Parse(path, isDirectory, isNamed, isOptimistic, supportsAbsoluteNumbers, fillExtendedInfo);
 69
 8370            if (!parsingResult.Success && !isStub)
 71            {
 072                return null;
 73            }
 74
 8375            return new EpisodeInfo(path)
 8376            {
 8377                Container = container,
 8378                IsStub = isStub,
 8379                EndingEpisodeNumber = parsingResult.EndingEpisodeNumber,
 8380                EpisodeNumber = parsingResult.EpisodeNumber,
 8381                SeasonNumber = parsingResult.SeasonNumber,
 8382                SeriesName = parsingResult.SeriesName,
 8383                StubType = stubType,
 8384                Is3D = format3DResult.Is3D,
 8385                Format3D = format3DResult.Format3D,
 8386                IsByDate = parsingResult.IsByDate,
 8387                Day = parsingResult.Day,
 8388                Month = parsingResult.Month,
 8389                Year = parsingResult.Year
 8390            };
 91        }
 92    }
 93}