< Summary - Jellyfin

Information
Class: MediaBrowser.XbmcMetadata.Savers.MovieNfoSaver
Assembly: MediaBrowser.XbmcMetadata
File(s): /srv/git/jellyfin/MediaBrowser.XbmcMetadata/Savers/MovieNfoSaver.cs
Line coverage
22%
Covered lines: 5
Uncovered lines: 17
Coverable lines: 22
Total lines: 138
Line coverage: 22.7%
Branch coverage
16%
Covered branches: 4
Total branches: 24
Branch coverage: 16.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(...)0%620%
GetRootElementName(...)0%620%
IsEnabledFor(...)50%12860%
WriteCustomElements(...)0%156120%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using System.IO;
 3using System.Linq;
 4using System.Xml;
 5using Jellyfin.Extensions;
 6using MediaBrowser.Controller.Configuration;
 7using MediaBrowser.Controller.Entities;
 8using MediaBrowser.Controller.Entities.Movies;
 9using MediaBrowser.Controller.Entities.TV;
 10using MediaBrowser.Controller.Library;
 11using MediaBrowser.Controller.Providers;
 12using MediaBrowser.Model.Entities;
 13using MediaBrowser.Model.IO;
 14using Microsoft.Extensions.Logging;
 15
 16namespace MediaBrowser.XbmcMetadata.Savers
 17{
 18    /// <summary>
 19    /// Nfo saver for movies.
 20    /// </summary>
 21    public class MovieNfoSaver : BaseNfoSaver
 22    {
 23        /// <summary>
 24        /// Initializes a new instance of the <see cref="MovieNfoSaver"/> class.
 25        /// </summary>
 26        /// <param name="fileSystem">The file system.</param>
 27        /// <param name="configurationManager">the server configuration manager.</param>
 28        /// <param name="libraryManager">The library manager.</param>
 29        /// <param name="userManager">The user manager.</param>
 30        /// <param name="userDataManager">The user data manager.</param>
 31        /// <param name="logger">The logger.</param>
 32        public MovieNfoSaver(
 33            IFileSystem fileSystem,
 34            IServerConfigurationManager configurationManager,
 35            ILibraryManager libraryManager,
 36            IUserManager userManager,
 37            IUserDataManager userDataManager,
 38            ILogger<MovieNfoSaver> logger)
 2139            : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
 40        {
 2141        }
 42
 43        /// <inheritdoc />
 44        protected override string GetLocalSavePath(BaseItem item)
 045            => GetMovieSavePaths(new ItemInfo(item)).FirstOrDefault() ?? Path.ChangeExtension(item.Path, ".nfo");
 46
 47        internal static IEnumerable<string> GetMovieSavePaths(ItemInfo item)
 48        {
 49            var path = item.ContainingFolderPath;
 50            if (item.VideoType == VideoType.Dvd && !item.IsPlaceHolder)
 51            {
 52                yield return Path.Combine(path, "VIDEO_TS", "VIDEO_TS.nfo");
 53            }
 54
 55            // only allow movie object to read movie.nfo, not owned videos (which will be itemtype video, not movie)
 56            if (!item.IsInMixedFolder && item.ItemType == typeof(Movie))
 57            {
 58                yield return Path.Combine(path, "movie.nfo");
 59            }
 60
 61            if (!item.IsPlaceHolder && (item.VideoType == VideoType.Dvd || item.VideoType == VideoType.BluRay))
 62            {
 63                yield return Path.Combine(path, Path.GetFileName(path) + ".nfo");
 64            }
 65            else
 66            {
 67                yield return Path.ChangeExtension(item.Path, ".nfo");
 68            }
 69        }
 70
 71        /// <inheritdoc />
 72        protected override string GetRootElementName(BaseItem item)
 073            => item is MusicVideo ? "musicvideo" : "movie";
 74
 75        /// <inheritdoc />
 76        public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
 77        {
 13178            if (!item.SupportsLocalMetadata)
 79            {
 080                return false;
 81            }
 82
 83            // Check parent for null to avoid running this against things like video backdrops
 13184            if (item is Video video && item is not Episode && !video.ExtraType.HasValue)
 85            {
 086                return updateType >= MinimumUpdateType;
 87            }
 88
 13189            return false;
 90        }
 91
 92        /// <inheritdoc />
 93        protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
 94        {
 095            if (item.TryGetProviderId(MetadataProvider.Imdb, out var imdb))
 96            {
 097                writer.WriteElementString("id", imdb);
 98            }
 99
 0100            if (item is MusicVideo musicVideo)
 101            {
 0102                foreach (var artist in musicVideo.Artists.Trimmed().OrderBy(artist => artist))
 103                {
 0104                    writer.WriteElementString("artist", artist);
 105                }
 106
 0107                if (!string.IsNullOrEmpty(musicVideo.Album))
 108                {
 0109                    writer.WriteElementString("album", musicVideo.Album);
 110                }
 111            }
 112
 0113            if (item is Movie movie)
 114            {
 0115                if (!string.IsNullOrEmpty(movie.CollectionName))
 116                {
 0117                    writer.WriteStartElement("set");
 0118                    writer.WriteElementString("name", movie.CollectionName);
 0119                    writer.WriteEndElement();
 120                }
 121            }
 0122        }
 123
 124        /// <inheritdoc />
 125        protected override IEnumerable<string> GetTagsUsed(BaseItem item)
 126        {
 127            foreach (var tag in base.GetTagsUsed(item))
 128            {
 129                yield return tag;
 130            }
 131
 132            yield return "album";
 133            yield return "artist";
 134            yield return "set";
 135            yield return "id";
 136        }
 137    }
 138}