< Summary - Jellyfin

Information
Class: Emby.Naming.Audio.AlbumParser
Assembly: Emby.Naming
File(s): /srv/git/jellyfin/Emby.Naming/Audio/AlbumParser.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 70
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
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%
IsMultiPart(...)100%88100%

File(s)

/srv/git/jellyfin/Emby.Naming/Audio/AlbumParser.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3using System.IO;
 4using System.Text.RegularExpressions;
 5using Emby.Naming.Common;
 6using Jellyfin.Extensions;
 7
 8namespace Emby.Naming.Audio
 9{
 10    /// <summary>
 11    /// Helper class to determine if Album is multipart.
 12    /// </summary>
 13    public partial class AlbumParser
 14    {
 15        private readonly NamingOptions _options;
 16
 17        /// <summary>
 18        /// Initializes a new instance of the <see cref="AlbumParser"/> class.
 19        /// </summary>
 20        /// <param name="options">Naming options containing AlbumStackingPrefixes.</param>
 21        public AlbumParser(NamingOptions options)
 22        {
 3123            _options = options;
 3124        }
 25
 26        [GeneratedRegex(@"[-\.\(\)\s]+")]
 27        private static partial Regex CleanRegex();
 28
 29        /// <summary>
 30        /// Function that determines if album is multipart.
 31        /// </summary>
 32        /// <param name="path">Path to file.</param>
 33        /// <returns>True if album is multipart.</returns>
 34        public bool IsMultiPart(string path)
 35        {
 3136            var filename = Path.GetFileName(path);
 3137            if (filename.Length == 0)
 38            {
 339                return false;
 40            }
 41
 42            // TODO: Move this logic into options object
 43            // Even better, remove the prefixes and come up with regexes
 44            // But Kodi documentation seems to be weak for audio
 45
 46            // Normalize
 47            // Remove whitespace
 2848            filename = CleanRegex().Replace(filename, " ");
 49
 2850            ReadOnlySpan<char> trimmedFilename = filename.AsSpan().TrimStart();
 51
 27752            foreach (var prefix in _options.AlbumStackingPrefixes)
 53            {
 11954                if (!trimmedFilename.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
 55                {
 56                    continue;
 57                }
 58
 2459                var tmp = trimmedFilename.Slice(prefix.Length).Trim();
 60
 2461                if (int.TryParse(tmp.LeftPart(' '), CultureInfo.InvariantCulture, out _))
 62                {
 1763                    return true;
 64                }
 65            }
 66
 1167            return false;
 68        }
 69    }
 70}