< Summary - Jellyfin

Information
Class: Emby.Naming.AudioBook.AudioBookFilePathParser
Assembly: Emby.Naming
File(s): /srv/git/jellyfin/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 67
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
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%
Parse(...)100%1616100%

File(s)

/srv/git/jellyfin/Emby.Naming/AudioBook/AudioBookFilePathParser.cs

#LineLine coverage
 1using System.Globalization;
 2using System.IO;
 3using System.Text.RegularExpressions;
 4using Emby.Naming.Common;
 5
 6namespace Emby.Naming.AudioBook
 7{
 8    /// <summary>
 9    /// Parser class to extract part and/or chapter number from audiobook filename.
 10    /// </summary>
 11    public class AudioBookFilePathParser
 12    {
 13        private readonly NamingOptions _options;
 14
 15        /// <summary>
 16        /// Initializes a new instance of the <see cref="AudioBookFilePathParser"/> class.
 17        /// </summary>
 18        /// <param name="options">Naming options containing AudioBookPartsExpressions.</param>
 19        public AudioBookFilePathParser(NamingOptions options)
 20        {
 11721            _options = options;
 11722        }
 23
 24        /// <summary>
 25        /// Based on regex determines if filename includes part/chapter number.
 26        /// </summary>
 27        /// <param name="path">Path to audiobook file.</param>
 28        /// <returns>Returns <see cref="AudioBookFilePathParser"/> object.</returns>
 29        public AudioBookFilePathParserResult Parse(string path)
 30        {
 11731            AudioBookFilePathParserResult result = default;
 11732            var fileName = Path.GetFileNameWithoutExtension(path);
 163833            foreach (var expression in _options.AudioBookPartsExpressions)
 34            {
 70235                var match = Regex.Match(fileName, expression, RegexOptions.IgnoreCase);
 70236                if (match.Success)
 37                {
 10338                    if (!result.ChapterNumber.HasValue)
 39                    {
 7840                        var value = match.Groups["chapter"];
 7841                        if (value.Success)
 42                        {
 4643                            if (int.TryParse(value.ValueSpan, NumberStyles.Integer, CultureInfo.InvariantCulture, out va
 44                            {
 4645                                result.ChapterNumber = intValue;
 46                            }
 47                        }
 48                    }
 49
 10350                    if (!result.PartNumber.HasValue)
 51                    {
 8352                        var value = match.Groups["part"];
 8353                        if (value.Success)
 54                        {
 3755                            if (int.TryParse(value.ValueSpan, NumberStyles.Integer, CultureInfo.InvariantCulture, out va
 56                            {
 3757                                result.PartNumber = intValue;
 58                            }
 59                        }
 60                    }
 61                }
 62            }
 63
 11764            return result;
 65        }
 66    }
 67}