< Summary - Jellyfin

Information
Class: MediaBrowser.LocalMetadata.Savers.PlaylistXmlSaver
Assembly: MediaBrowser.LocalMetadata
File(s): /srv/git/jellyfin/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs
Line coverage
28%
Covered lines: 4
Uncovered lines: 10
Coverable lines: 14
Total lines: 83
Line coverage: 28.5%
Branch coverage
25%
Covered branches: 2
Total branches: 8
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%
IsEnabledFor(...)50%4.59466.66%
WriteCustomElementsAsync(...)0%620%
GetLocalSavePath(...)100%210%
GetSavePath(...)0%620%

File(s)

/srv/git/jellyfin/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs

#LineLine coverage
 1using System.IO;
 2using System.Threading.Tasks;
 3using System.Xml;
 4using Jellyfin.Data.Enums;
 5using MediaBrowser.Controller.Configuration;
 6using MediaBrowser.Controller.Entities;
 7using MediaBrowser.Controller.Library;
 8using MediaBrowser.Controller.Playlists;
 9using MediaBrowser.Model.IO;
 10using Microsoft.Extensions.Logging;
 11
 12namespace MediaBrowser.LocalMetadata.Savers
 13{
 14    /// <summary>
 15    /// Playlist xml saver.
 16    /// </summary>
 17    public class PlaylistXmlSaver : BaseXmlSaver
 18    {
 19        /// <summary>
 20        /// The default file name to use when creating a new playlist.
 21        /// </summary>
 22        public const string DefaultPlaylistFilename = "playlist.xml";
 23
 24        /// <summary>
 25        /// Initializes a new instance of the <see cref="PlaylistXmlSaver"/> class.
 26        /// </summary>
 27        /// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
 28        /// <param name="configurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</par
 29        /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
 30        /// <param name="logger">Instance of the <see cref="ILogger{PlaylistXmlSaver}"/> interface.</param>
 31        public PlaylistXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManage
 2232            : base(fileSystem, configurationManager, libraryManager, logger)
 33        {
 2234        }
 35
 36        /// <inheritdoc />
 37        public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
 38        {
 10439            if (!item.SupportsLocalMetadata)
 40            {
 041                return false;
 42            }
 43
 10444            return item is Playlist && updateType >= ItemUpdateType.MetadataImport;
 45        }
 46
 47        /// <inheritdoc />
 48        protected override Task WriteCustomElementsAsync(BaseItem item, XmlWriter writer)
 49        {
 050            var game = (Playlist)item;
 51
 052            if (game.PlaylistMediaType == MediaType.Unknown)
 53            {
 054                return Task.CompletedTask;
 55            }
 56
 057            return writer.WriteElementStringAsync(null, "PlaylistMediaType", null, game.PlaylistMediaType.ToString());
 58        }
 59
 60        /// <inheritdoc />
 61        protected override string GetLocalSavePath(BaseItem item)
 62        {
 063            return GetSavePath(item.Path);
 64        }
 65
 66        /// <summary>
 67        /// Get the save path.
 68        /// </summary>
 69        /// <param name="itemPath">The item path.</param>
 70        /// <returns>The save path.</returns>
 71        public static string GetSavePath(string itemPath)
 72        {
 073            var path = itemPath;
 74
 075            if (Playlist.IsPlaylistFile(path))
 76            {
 077                return Path.ChangeExtension(itemPath, ".xml");
 78            }
 79
 080            return Path.Combine(path, DefaultPlaylistFilename);
 81        }
 82    }
 83}