< Summary - Jellyfin

Information
Class: MediaBrowser.XbmcMetadata.Savers.ArtistNfoSaver
Assembly: MediaBrowser.XbmcMetadata
File(s): /srv/git/jellyfin/MediaBrowser.XbmcMetadata/Savers/ArtistNfoSaver.cs
Line coverage
12%
Covered lines: 3
Uncovered lines: 21
Coverable lines: 24
Total lines: 106
Line coverage: 12.5%
Branch coverage
25%
Covered branches: 3
Total branches: 12
Branch coverage: 25%
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%
GetLocalSavePath(...)100%210%
GetRootElementName(...)100%210%
IsEnabledFor(...)75%44100%
WriteCustomElements(...)0%620%
AddAlbums(...)0%4260%

File(s)

/srv/git/jellyfin/MediaBrowser.XbmcMetadata/Savers/ArtistNfoSaver.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Globalization;
 3using System.IO;
 4using System.Linq;
 5using System.Xml;
 6using MediaBrowser.Controller.Configuration;
 7using MediaBrowser.Controller.Entities;
 8using MediaBrowser.Controller.Entities.Audio;
 9using MediaBrowser.Controller.Library;
 10using MediaBrowser.Model.IO;
 11using MediaBrowser.XbmcMetadata.Configuration;
 12using Microsoft.Extensions.Logging;
 13
 14namespace MediaBrowser.XbmcMetadata.Savers
 15{
 16    /// <summary>
 17    /// Nfo saver for artist.
 18    /// </summary>
 19    public class ArtistNfoSaver : BaseNfoSaver
 20    {
 21        /// <summary>
 22        /// Initializes a new instance of the <see cref="ArtistNfoSaver"/> class.
 23        /// </summary>
 24        /// <param name="fileSystem">The file system.</param>
 25        /// <param name="configurationManager">the server configuration manager.</param>
 26        /// <param name="libraryManager">The library manager.</param>
 27        /// <param name="userManager">The user manager.</param>
 28        /// <param name="userDataManager">The user data manager.</param>
 29        /// <param name="logger">The logger.</param>
 30        public ArtistNfoSaver(
 31            IFileSystem fileSystem,
 32            IServerConfigurationManager configurationManager,
 33            ILibraryManager libraryManager,
 34            IUserManager userManager,
 35            IUserDataManager userDataManager,
 36            ILogger<ArtistNfoSaver> logger)
 2137            : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
 38        {
 2139        }
 40
 41        /// <inheritdoc />
 42        protected override string GetLocalSavePath(BaseItem item)
 043            => Path.Combine(item.Path, "artist.nfo");
 44
 45        /// <inheritdoc />
 46        protected override string GetRootElementName(BaseItem item)
 047            => "artist";
 48
 49        /// <inheritdoc />
 50        public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
 13151            => item.SupportsLocalMetadata && item is MusicArtist && updateType >= MinimumUpdateType;
 52
 53        /// <inheritdoc />
 54        protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
 55        {
 056            var artist = (MusicArtist)item;
 57
 058            if (artist.EndDate.HasValue)
 59            {
 060                var formatString = ConfigurationManager.GetNfoConfiguration().ReleaseDateFormat;
 61
 062                writer.WriteElementString("disbanded", artist.EndDate.Value.ToString(formatString, CultureInfo.Invariant
 63            }
 64
 065            var albums = artist
 066                .GetRecursiveChildren(i => i is MusicAlbum);
 67
 068            AddAlbums(albums, writer);
 069        }
 70
 71        private void AddAlbums(IReadOnlyList<BaseItem> albums, XmlWriter writer)
 72        {
 073            foreach (var album in albums
 074                .OrderBy(album => album.ProductionYear ?? 0)
 075                .ThenBy(album => SortNameOrName(album))
 076                .ThenBy(album => album.Name?.Trim()))
 77            {
 078                writer.WriteStartElement("album");
 79
 080                if (!string.IsNullOrEmpty(album.Name))
 81                {
 082                    writer.WriteElementString("title", album.Name);
 83                }
 84
 085                if (album.ProductionYear.HasValue)
 86                {
 087                    writer.WriteElementString("year", album.ProductionYear.Value.ToString(CultureInfo.InvariantCulture))
 88                }
 89
 090                writer.WriteEndElement();
 91            }
 092        }
 93
 94        /// <inheritdoc />
 95        protected override IEnumerable<string> GetTagsUsed(BaseItem item)
 96        {
 97            foreach (var tag in base.GetTagsUsed(item))
 98            {
 99                yield return tag;
 100            }
 101
 102            yield return "album";
 103            yield return "disbanded";
 104        }
 105    }
 106}