< Summary - Jellyfin

Information
Class: MediaBrowser.XbmcMetadata.Savers.AlbumNfoSaver
Assembly: MediaBrowser.XbmcMetadata
File(s): /srv/git/jellyfin/MediaBrowser.XbmcMetadata/Savers/AlbumNfoSaver.cs
Line coverage
10%
Covered lines: 3
Uncovered lines: 26
Coverable lines: 29
Total lines: 121
Line coverage: 10.3%
Branch coverage
13%
Covered branches: 3
Total branches: 22
Branch coverage: 13.6%
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%2040%
AddTracks(...)0%210140%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Globalization;
 4using System.IO;
 5using System.Linq;
 6using System.Xml;
 7using Jellyfin.Extensions;
 8using MediaBrowser.Controller.Configuration;
 9using MediaBrowser.Controller.Entities;
 10using MediaBrowser.Controller.Entities.Audio;
 11using MediaBrowser.Controller.Library;
 12using MediaBrowser.Model.IO;
 13using Microsoft.Extensions.Logging;
 14
 15namespace MediaBrowser.XbmcMetadata.Savers
 16{
 17    /// <summary>
 18    /// Nfo saver for albums.
 19    /// </summary>
 20    public class AlbumNfoSaver : BaseNfoSaver
 21    {
 22        /// <summary>
 23        /// Initializes a new instance of the <see cref="AlbumNfoSaver"/> class.
 24        /// </summary>
 25        /// <param name="fileSystem">The file system.</param>
 26        /// <param name="configurationManager">the server configuration manager.</param>
 27        /// <param name="libraryManager">The library manager.</param>
 28        /// <param name="userManager">The user manager.</param>
 29        /// <param name="userDataManager">The user data manager.</param>
 30        /// <param name="logger">The logger.</param>
 31        public AlbumNfoSaver(
 32            IFileSystem fileSystem,
 33            IServerConfigurationManager configurationManager,
 34            ILibraryManager libraryManager,
 35            IUserManager userManager,
 36            IUserDataManager userDataManager,
 37            ILogger<AlbumNfoSaver> logger)
 2138            : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
 39        {
 2140        }
 41
 42        /// <inheritdoc />
 43        protected override string GetLocalSavePath(BaseItem item)
 044            => Path.Combine(item.Path, "album.nfo");
 45
 46        /// <inheritdoc />
 47        protected override string GetRootElementName(BaseItem item)
 048            => "album";
 49
 50        /// <inheritdoc />
 51        public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
 13152            => item.SupportsLocalMetadata && item is MusicAlbum && updateType >= MinimumUpdateType;
 53
 54        /// <inheritdoc />
 55        protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
 56        {
 057            var album = (MusicAlbum)item;
 58
 059            foreach (var artist in album.Artists.Trimmed().OrderBy(artist => artist))
 60            {
 061                writer.WriteElementString("artist", artist);
 62            }
 63
 064            foreach (var artist in album.AlbumArtists.Trimmed().OrderBy(artist => artist))
 65            {
 066                writer.WriteElementString("albumartist", artist);
 67            }
 68
 069            AddTracks(album.Tracks, writer);
 070        }
 71
 72        private void AddTracks(IEnumerable<BaseItem> tracks, XmlWriter writer)
 73        {
 074            foreach (var track in tracks
 075                .OrderBy(i => i.ParentIndexNumber ?? 0)
 076                .ThenBy(i => i.IndexNumber ?? 0)
 077                .ThenBy(i => SortNameOrName(i))
 078                .ThenBy(i => i.Name?.Trim()))
 79            {
 080                writer.WriteStartElement("track");
 81
 082                if (track.ParentIndexNumber.HasValue && track.ParentIndexNumber.Value != 0)
 83                {
 084                    writer.WriteElementString("disc", track.ParentIndexNumber.Value.ToString(CultureInfo.InvariantCultur
 85                }
 86
 087                if (track.IndexNumber.HasValue && track.IndexNumber.Value != 0)
 88                {
 089                    writer.WriteElementString("position", track.IndexNumber.Value.ToString(CultureInfo.InvariantCulture)
 90                }
 91
 092                if (!string.IsNullOrEmpty(track.Name))
 93                {
 094                    writer.WriteElementString("title", track.Name);
 95                }
 96
 097                if (track.RunTimeTicks.HasValue)
 98                {
 099                    var time = TimeSpan.FromTicks(track.RunTimeTicks.Value).ToString(@"mm\:ss", CultureInfo.InvariantCul
 100
 0101                    writer.WriteElementString("duration", time);
 102                }
 103
 0104                writer.WriteEndElement();
 105            }
 0106        }
 107
 108        /// <inheritdoc />
 109        protected override IEnumerable<string> GetTagsUsed(BaseItem item)
 110        {
 111            foreach (var tag in base.GetTagsUsed(item))
 112            {
 113                yield return tag;
 114            }
 115
 116            yield return "track";
 117            yield return "artist";
 118            yield return "albumartist";
 119        }
 120    }
 121}