< Summary - Jellyfin

Information
Class: Emby.Naming.Video.ExtraRuleResolver
Assembly: Emby.Naming
File(s): /srv/git/jellyfin/Emby.Naming/Video/ExtraRuleResolver.cs
Line coverage
96%
Covered lines: 26
Uncovered lines: 1
Coverable lines: 27
Total lines: 69
Line coverage: 96.2%
Branch coverage
94%
Covered branches: 18
Total branches: 19
Branch coverage: 94.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 5/12/2026 - 12:15:57 AM Line coverage: 96.2% (26/27) Branch coverage: 94.7% (18/19) Total lines: 69 5/12/2026 - 12:15:57 AM Line coverage: 96.2% (26/27) Branch coverage: 94.7% (18/19) Total lines: 69

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
GetExtraInfo(...)94.73%191996.15%

File(s)

/srv/git/jellyfin/Emby.Naming/Video/ExtraRuleResolver.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Text.RegularExpressions;
 4using Emby.Naming.Audio;
 5using Emby.Naming.Common;
 6
 7namespace Emby.Naming.Video
 8{
 9    /// <summary>
 10    /// Resolve if file is extra for video.
 11    /// </summary>
 12    public static class ExtraRuleResolver
 13    {
 214        private static readonly char[] _digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
 15
 16        /// <summary>
 17        /// Attempts to resolve if file is extra.
 18        /// </summary>
 19        /// <param name="path">Path to file.</param>
 20        /// <param name="namingOptions">The naming options.</param>
 21        /// <param name="libraryRoot">Top-level folder for the containing library.</param>
 22        /// <returns>Returns <see cref="ExtraResult"/> object.</returns>
 23        public static ExtraResult GetExtraInfo(string path, NamingOptions namingOptions, string? libraryRoot = "")
 24        {
 59525            ExtraResult result = new ExtraResult();
 26
 59527            bool isAudioFile = AudioFileParser.IsAudioFile(path, namingOptions);
 59528            bool isVideoFile = VideoResolver.IsVideoFile(path, namingOptions);
 29
 59530            ReadOnlySpan<char> pathSpan = path.AsSpan();
 59531            ReadOnlySpan<char> fileName = Path.GetFileName(pathSpan);
 59532            ReadOnlySpan<char> fileNameWithoutExtension = Path.GetFileNameWithoutExtension(pathSpan);
 33            // Trim the digits from the end of the filename so we can recognize things like -trailer2 or sample1
 59534            ReadOnlySpan<char> trimmedFileNameWithoutExtension = fileNameWithoutExtension.TrimEnd(_digits);
 59535            ReadOnlySpan<char> directoryName = Path.GetFileName(Path.GetDirectoryName(pathSpan));
 59536            string fullDirectory = Path.GetDirectoryName(pathSpan).ToString();
 37
 3566238            foreach (ExtraRule rule in namingOptions.VideoExtraRules)
 39            {
 1733540                if ((rule.MediaType == MediaType.Audio && !isAudioFile)
 1733541                    || (rule.MediaType == MediaType.Video && !isVideoFile))
 42                {
 43                    continue;
 44                }
 45
 1558746                bool isMatch = rule.RuleType switch
 1558747                {
 97248                    ExtraRuleType.Filename => trimmedFileNameWithoutExtension.Equals(rule.Token, StringComparison.Ordina
 728049                    ExtraRuleType.Suffix => trimmedFileNameWithoutExtension.EndsWith(rule.Token, StringComparison.Ordina
 150                    ExtraRuleType.Regex => Regex.IsMatch(fileName, rule.Token, RegexOptions.IgnoreCase | RegexOptions.Co
 733451                    ExtraRuleType.DirectoryName => directoryName.Equals(rule.Token, StringComparison.OrdinalIgnoreCase)
 733452                                                 && !string.Equals(fullDirectory, libraryRoot, StringComparison.OrdinalI
 053                    _ => false,
 1558754                };
 55
 1558756                if (!isMatch)
 57                {
 58                    continue;
 59                }
 60
 19861                result.ExtraType = rule.ExtraType;
 19862                result.Rule = rule;
 19863                return result;
 64            }
 65
 39766            return result;
 67        }
 68    }
 69}