< 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

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        {
 36625            ExtraResult result = new ExtraResult();
 26
 36627            bool isAudioFile = AudioFileParser.IsAudioFile(path, namingOptions);
 36628            bool isVideoFile = VideoResolver.IsVideoFile(path, namingOptions);
 29
 36630            ReadOnlySpan<char> pathSpan = path.AsSpan();
 36631            ReadOnlySpan<char> fileName = Path.GetFileName(pathSpan);
 36632            ReadOnlySpan<char> fileNameWithoutExtension = Path.GetFileNameWithoutExtension(pathSpan);
 33            // Trim the digits from the end of the filename so we can recognize things like -trailer2
 36634            ReadOnlySpan<char> trimmedFileNameWithoutExtension = fileNameWithoutExtension.TrimEnd(_digits);
 36635            ReadOnlySpan<char> directoryName = Path.GetFileName(Path.GetDirectoryName(pathSpan));
 36636            string fullDirectory = Path.GetDirectoryName(pathSpan).ToString();
 37
 2023638            foreach (ExtraRule rule in namingOptions.VideoExtraRules)
 39            {
 982440                if ((rule.MediaType == MediaType.Audio && !isAudioFile)
 982441                    || (rule.MediaType == MediaType.Video && !isVideoFile))
 42                {
 43                    continue;
 44                }
 45
 856046                bool isMatch = rule.RuleType switch
 856047                {
 54148                    ExtraRuleType.Filename => fileNameWithoutExtension.Equals(rule.Token, StringComparison.OrdinalIgnore
 402349                    ExtraRuleType.Suffix => trimmedFileNameWithoutExtension.EndsWith(rule.Token, StringComparison.Ordina
 150                    ExtraRuleType.Regex => Regex.IsMatch(fileName, rule.Token, RegexOptions.IgnoreCase | RegexOptions.Co
 399551                    ExtraRuleType.DirectoryName => directoryName.Equals(rule.Token, StringComparison.OrdinalIgnoreCase)
 399552                                                 && !string.Equals(fullDirectory, libraryRoot, StringComparison.OrdinalI
 053                    _ => false,
 856054                };
 55
 856056                if (!isMatch)
 57                {
 58                    continue;
 59                }
 60
 14461                result.ExtraType = rule.ExtraType;
 14462                result.Rule = rule;
 14463                return result;
 64            }
 65
 22266            return result;
 67        }
 68    }
 69}